Firebase Dinamik Bağlantılar Analizi API'si

İster konsolda ister programlı olarak oluşturulmuş olsun , kısa Dinamik Bağlantılarınızın her biri için analiz verileri almak üzere bu REST API'yi kullanabilirsiniz.

API Yetkilendirmesi

Dynamic Link Analytics API'lerine istekte bulunduğunuzda Firebase projenize erişim yetkisi veren bir OAuth 2.0 erişim jetonu eklemeniz gerekir.

Bir Google API istemci kitaplığını kullanarak erişim belirteçlerine ulaşabilirsiniz:

  1. Firebase'i Admin SDK kurulum kılavuzunda açıklandığı şekilde uygulamanıza ekleyin . Yani bir hizmet hesabı oluşturun ve özel bir anahtar oluşturun.
  2. Hizmet hesabı kimlik bilgilerinizden erişim jetonu almak için bir Google API istemci kitaplığı kullanın:

    Java

    Java için Google API İstemci Kitaplığını Kullanma:

    // Load the service account key JSON file
    FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
    
    // Authenticate a Google credential with the service account
    GoogleCredential googleCred = GoogleCredential.fromStream(serviceAccount);
    
    // Add the required scope to the Google credential
    GoogleCredential scoped = googleCred.createScoped(
        Arrays.asList(
          "https://www.googleapis.com/auth/firebase"
        )
    );
    
    // Use the Google credential to generate an access token
    scoped.refreshToken();
    String token = scoped.getAccessToken();
    
    // Include the access token in the Authorization header.
    

    Node.js

    Node.js için Google API İstemci Kitaplığını Kullanma:

    var { google } = require("googleapis");
    
    // Load the service account key JSON file.
    var serviceAccount = require("path/to/serviceAccountKey.json");
    
    // Specify the required scope.
    var scopes = [
      "https://www.googleapis.com/auth/firebase"
    ];
    
    // Authenticate a JWT client with the service account.
    var jwtClient = new google.auth.JWT(
      serviceAccount.client_email,
      null,
      serviceAccount.private_key,
      scopes
    );
    
    // Use the JWT client to generate an access token.
    jwtClient.authorize(function(error, tokens) {
      if (error) {
        console.log("Error making request to generate access token:", error);
      } else if (tokens.access_token === null) {
        console.log("Provided service account does not have permission to generate access tokens");
      } else {
        var accessToken = tokens.access_token;
    
        // Include the access token in the Authorization header.
      }
    });
    

    Python

    Python için Google Auth kitaplığını kullanma:

    from google.oauth2 import service_account
    from google.auth.transport.requests import AuthorizedSession
    
    # Specify the required scope
    scopes = [
      "https://www.googleapis.com/auth/firebase"
    ]
    
    # Authenticate a credential with the service account
    credentials = service_account.Credentials.from_service_account_file(
        "path/to/serviceAccountKey.json", scopes=scopes)
    
    # Use the credentials object to authenticate a Requests session.
    authed_session = AuthorizedSession(credentials)
    response = authed_session.get(
        "https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=DURATION")
    
    # Or, use the token directly, as described below.
    request = google.auth.transport.requests.Request()
    credentials.refresh(request)
    access_token = credentials.token
    

Tek bir Dinamik Bağlantıya ilişkin istatistikleri alın

Tek bir Dinamik Bağlantıya ilişkin etkinlik istatistiklerini almak için linkStats uç noktasını kullanın.

HTTP isteği

Bir linkStats isteği aşağıdaki formata sahiptir:

GET https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=DURATION

Authorization: Bearer ACCESS_TOKEN

Örneğin, https://example.page.link/wXYz kısa bağlantısına ilişkin son 7 güne ait istatistikleri almak için:

GET https://firebasedynamiclinks.googleapis.com/v1/https%3A%2F%2Fexample.page.link%2FwXYz/linkStats?durationDays=7

Authorization: Bearer ya29.Abc123...
Parametreler
SHORT_DYNAMIC_LINK Etkinlik verilerini almak istediğiniz URL kodlu kısa Dinamik Bağlantı.
DURATION Etkinlik verilerinin alınacağı gün sayısı. Örneğin, 30 belirtirseniz istek, son 30 güne ait verileri alır. Son 36 saatte kaydedilen bazı etkinliklerin dahil edilmeyebileceğini unutmayın.
ACCESS_TOKEN Süresi dolmamış bir erişim belirteci. Bkz. API Yetkilendirmesi .

Yanıt gövdesi

Bir isteğe verilen yanıt aşağıdakine benzer bir JSON nesnesidir:

{
  "linkEventStats": [
    {
      "platform": "ANDROID",
      "count": "123",
      "event": "CLICK"
    },
    {
      "platform": "IOS",
      "count": "123",
      "event": "CLICK"
    },
    {
      "platform": "DESKTOP",
      "count": "456",
      "event": "CLICK"
    },
    {
      "platform": "ANDROID",
      "count": "99",
      "event": "APP_INSTALL"
    },
    {
      "platform": "ANDROID",
      "count": "42",
      "event": "APP_FIRST_OPEN"
    },

    ...

  ]
}

linkEventStats listesindeki her öğe, Dinamik Bağlantı ile ilgili bazı olayların (Android'deki tıklama sayısı gibi) platforma özel sayısını içerir. Bu istatistiklerin son 36 saat içinde günlüğe kaydedilen etkinlikleri içermeyebileceğini unutmayın.

Etkinlik Tanım Firebase konsolu REST API'si
TIKLAMAK Nasıl işlendiğine ve hedeflerine bakılmaksızın Dinamik Bağlantıya yapılan tıklamaların sayısı
YÖNLENDİR Uygulamayı yüklemek veya güncellemek için kullanıcıları App Store'a veya Play Store'a ya da başka bir hedefe yönlendirme girişimlerinin sayısı
APP_INSTALL Gerçek yüklemelerin sayısı (yalnızca Play Store tarafından desteklenir)
APP_FIRST_OPEN Kurulumdan sonra ilk açılmaların sayısı
APP_RE_OPEN Dinamik Bağlantının bir uygulamanın yeniden açılmasına neden olma sayısı