이 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 인증 라이브러리 사용:
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
목록의 각 항목에는 일부 동적 링크 관련 이벤트의 플랫폼별 개수(예: Android의 클릭 수)가 포함되어 있습니다. 이러한 통계에는 지난 36시간 동안 기록된 이벤트가 포함되지 않을 수도 있습니다.
이벤트 | 설명 | Firebase 콘솔 | REST API |
---|---|---|---|
딸깍 하는 소리 | 처리 방법 및 대상에 관계없이 동적 링크에 대한 클릭 수 | ||
리디렉션 | 앱을 설치하거나 업데이트하기 위해 App Store나 Play Store 또는 다른 대상으로 사용자를 리디렉션하려는 시도 횟수 | ||
앱 설치 | 실제 설치 수(Play 스토어에서만 지원) | ||
APP_FIRST_OPEN | 설치 후 처음으로 연 횟수 | ||
APP_RE_OPEN | 동적 링크로 인해 앱이 다시 열리는 횟수 |
이 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 인증 라이브러리 사용:
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
목록의 각 항목에는 일부 동적 링크 관련 이벤트의 플랫폼별 개수(예: Android의 클릭 수)가 포함되어 있습니다. 이러한 통계에는 지난 36시간 동안 기록된 이벤트가 포함되지 않을 수도 있습니다.
이벤트 | 설명 | Firebase 콘솔 | REST API |
---|---|---|---|
딸깍 하는 소리 | 처리 방법 및 대상에 관계없이 동적 링크에 대한 클릭 수 | ||
리디렉션 | 앱을 설치하거나 업데이트하기 위해 App Store나 Play Store 또는 다른 대상으로 사용자를 리디렉션하려는 시도 횟수 | ||
앱_설치 | 실제 설치 수(Play 스토어에서만 지원) | ||
APP_FIRST_OPEN | 설치 후 처음으로 연 횟수 | ||
APP_RE_OPEN | 동적 링크로 인해 앱이 다시 열리는 횟수 |