この REST API を使用すると、コンソールで作成されたかプログラムで作成されたかに関係なく、短いダイナミック リンクごとに分析データを取得できます。
API認可
Dynamic Link Analytics API にリクエストを行う場合は、Firebase プロジェクトへのアクセスを承認する OAuth 2.0 アクセス トークンを含める必要があります。
Google API クライアント ライブラリを使用してアクセス トークンを取得できます。
- Admin SDK セットアップ ガイドの説明に従って、 Firebase をアプリに追加します。つまり、サービス アカウントを作成し、秘密キーを生成します。
- Google API クライアント ライブラリを使用して、サービス アカウントの資格情報からアクセス トークンを取得します。
ジャワ
Java 用 Google API クライアント ライブラリの使用:
// 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 用の Google API クライアント ライブラリの使用:
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 用のGoogle Authライブラリを使用する:
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
単一のダイナミック リンクの統計を取得する
linkStats
エンドポイントを使用して、単一のダイナミック リンクのイベント統計を取得します。
HTTPリクエスト
linkStats
リクエストの形式は次のとおりです。
GET https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=DURATION Authorization: Bearer ACCESS_TOKEN
たとえば、短いリンクhttps://example.page.link/wXYz
の過去 7 日間の統計を取得するには、次のようにします。
GET https://firebasedynamiclinks.googleapis.com/v1/https%3A%2F%2Fexample.page.link%2FwXYz/linkStats?durationDays=7 Authorization: Bearer ya29.Abc123...
パラメーター | |
---|---|
SHORT_DYNAMIC_LINK | イベント データを取得するURL エンコードされた短いダイナミック リンク。 |
DURATION | イベントデータを取得する日数。たとえば、 30 を指定すると、リクエストは過去 30 日間のデータを取得します。過去 36 時間に記録された一部のイベントは含まれない場合があることに注意してください。 |
ACCESS_TOKEN | 有効期限が切れていないアクセス トークン。 「 API 認可 」を参照してください。 |
レスポンスボディ
リクエストに対するレスポンスは、次のような JSON オブジェクトです。
{
"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
リストの各項目には、Dynamic Link 関連イベント (Android のクリック数など) のプラットフォーム固有のカウントが含まれています。これらの統計には、過去 36 時間以内に記録されたイベントが含まれない場合があることに注意してください。
イベント | 説明 | Firebaseコンソール | REST API |
---|---|---|---|
クリック | ダイナミック リンクの処理方法や宛先に関係なく、ダイナミック リンク上のクリック数 | ||
リダイレクト | ユーザーを App Store または Play Store にリダイレクトしてアプリをインストールまたは更新するか、その他の宛先にリダイレクトしようとした回数 | ||
APP_INSTALL | 実際のインストール数 (Play ストアでのみサポート) | ||
APP_FIRST_OPEN | インストール後に最初に開いた回数 | ||
APP_RE_OPEN | ダイナミック リンクによりアプリが再度開かれた回数 |