// Load the service account key JSON fileFileInputStreamserviceAccount=newFileInputStream("path/to/serviceAccountKey.json");// Authenticate a Google credential with the service accountGoogleCredentialgoogleCred=GoogleCredential.fromStream(serviceAccount);// Add the required scope to the Google credentialGoogleCredentialscoped=googleCred.createScoped(Arrays.asList("https://www.googleapis.com/auth/firebase"));// Use the Google credential to generate an access tokenscoped.refreshToken();Stringtoken=scoped.getAccessToken();// Include the access token in the Authorization header.
var{google}=require("googleapis");// Load the service account key JSON file.varserviceAccount=require("path/to/serviceAccountKey.json");// Specify the required scope.varscopes=["https://www.googleapis.com/auth/firebase"];// Authenticate a JWT client with the service account.varjwtClient=newgoogle.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);}elseif(tokens.access_token===null){console.log("Provided service account does not have permission to generate access tokens");}else{varaccessToken=tokens.access_token;// Include the access token in the Authorization header.}});
fromgoogle.oauth2importservice_accountfromgoogle.auth.transport.requestsimportAuthorizedSession# Specify the required scopescopes=["https://www.googleapis.com/auth/firebase"]# Authenticate a credential with the service accountcredentials=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
Get statistics for a single Dynamic Link
Use the linkStats endpoint to get event statistics for a single Dynamic Link.
HTTP request
A linkStats request has the following format:
GET https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=DURATION
Authorization: Bearer ACCESS_TOKEN
For example, to retrieve statistics from the last 7 days for the short link
https://example.page.link/wXYz:
GET https://firebasedynamiclinks.googleapis.com/v1/https%3A%2F%2Fexample.page.link%2FwXYz/linkStats?durationDays=7
Authorization: Bearer ya29.Abc123...
Parameters
SHORT_DYNAMIC_LINK
The
URL-encoded short Dynamic Link for which you want to get event data.
DURATION
The number of days for which to get event data. For example, if you
specify 30, the request retrieves data for the past 30 days.
Note that some events logged in the last 36 hours might not be included.
Each item in the linkEventStats list contains a platform-specific count of
some Dynamic Link related event (such as the number of clicks on Android). Note that
these statistics might not include events that have been logged within the last
36 hours.
Event
Description
Firebase console
REST API
CLICK
Count of any click on a Dynamic Link, irrespective to how it is handled and its destinations
REDIRECT
Count of attempts to redirect users, either to the App Store or Play Store to install or update the app, or to some other destination
APP_INSTALL
Count of actual installs (only supported by the Play Store)
APP_FIRST_OPEN
Count of first-opens after an install
APP_RE_OPEN
Number of times the Dynamic Link caused an app to be re-opened
[null,null,["Last updated 2025-08-15 UTC."],[],[],null,["You can use this REST API to get analytics data for each of your short Dynamic Links,\nwhether [created in the console or programmatically](/docs/dynamic-links/create-links).\n\nAPI Authorization\n\nWhen you make requests to the Dynamic Link Analytics APIs, you must include an OAuth\n2.0 access token that authorizes access to your Firebase project.\n\nYou can get access tokens using a Google API client library:\n\n1. [Add Firebase to your app](/docs/admin/setup#prerequisites) as described in the Admin SDK setup guide. That is, create a service account and generate a private key.\n2. Use a Google API client library to get an access token from your service account credentials: \n\n Java\n\n Using the\n [Google API Client Library for Java](https://developers.google.com/api-client-library/java/): \n\n ```java\n // Load the service account key JSON file\n FileInputStream serviceAccount = new FileInputStream(\"path/to/serviceAccountKey.json\");\n\n // Authenticate a Google credential with the service account\n GoogleCredential googleCred = GoogleCredential.fromStream(serviceAccount);\n\n // Add the required scope to the Google credential\n GoogleCredential scoped = googleCred.createScoped(\n Arrays.asList(\n \"https://www.googleapis.com/auth/firebase\"\n )\n );\n\n // Use the Google credential to generate an access token\n scoped.refreshToken();\n String token = scoped.getAccessToken();\n\n // Include the access token in the Authorization header.\n ```\n\n Node.js\n\n Using the\n [Google API Client Library for Node.js](https://github.com/google/google-api-nodejs-client/): \n\n ```javascript\n var { google } = require(\"googleapis\");\n\n // Load the service account key JSON file.\n var serviceAccount = require(\"path/to/serviceAccountKey.json\");\n\n // Specify the required scope.\n var scopes = [\n \"https://www.googleapis.com/auth/firebase\"\n ];\n\n // Authenticate a JWT client with the service account.\n var jwtClient = new google.auth.JWT(\n serviceAccount.client_email,\n null,\n serviceAccount.private_key,\n scopes\n );\n\n // Use the JWT client to generate an access token.\n jwtClient.authorize(function(error, tokens) {\n if (error) {\n console.log(\"Error making request to generate access token:\", error);\n } else if (tokens.access_token === null) {\n console.log(\"Provided service account does not have permission to generate access tokens\");\n } else {\n var accessToken = tokens.access_token;\n\n // Include the access token in the Authorization header.\n }\n });\n ```\n\n Python\n\n Using the [Google Auth](https://github.com/GoogleCloudPlatform/google-auth-library-python) library for Python: \n\n ```python\n from google.oauth2 import service_account\n from google.auth.transport.requests import AuthorizedSession\n\n # Specify the required scope\n scopes = [\n \"https://www.googleapis.com/auth/firebase\"\n ]\n\n # Authenticate a credential with the service account\n credentials = service_account.Credentials.from_service_account_file(\n \"path/to/serviceAccountKey.json\", scopes=scopes)\n\n # Use the credentials object to authenticate a Requests session.\n authed_session = AuthorizedSession(credentials)\n response = authed_session.get(\n \"https://firebasedynamiclinks.googleapis.com/v1/\u003cvar translate=\"no\"\u003eSHORT_DYNAMIC_LINK\u003c/var\u003e/linkStats?durationDays=\u003cvar translate=\"no\"\u003eDURATION\u003c/var\u003e\")\n\n # Or, use the token directly, as described below.\n request = google.auth.transport.requests.Request()\n credentials.refresh(request)\n access_token = credentials.token\n ```\n\n| **Warning:** Use extra caution when handling service account credentials in your code. Do not commit them to a public repository, deploy them in a client app, or expose them in any way that could compromise the security of your Firebase project.\n\nGet statistics for a single Dynamic Link\n\nUse the `linkStats` endpoint to get event statistics for a single Dynamic Link.\n\nHTTP request\n\nA `linkStats` request has the following format: \n\n```\nGET https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=DURATION\n\nAuthorization: Bearer ACCESS_TOKEN\n```\n\nFor example, to retrieve statistics from the last 7 days for the short link\n`https://example.page.link/wXYz`: \n\n```\nGET https://firebasedynamiclinks.googleapis.com/v1/https%3A%2F%2Fexample.page.link%2FwXYz/linkStats?durationDays=7\n\nAuthorization: Bearer ya29.Abc123...\n```\n\n| Parameters ||\n|----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| \u003cvar translate=\"no\"\u003eSHORT_DYNAMIC_LINK\u003c/var\u003e | The [URL-encoded](https://developer.mozilla.org/docs/Glossary/percent-encoding) short Dynamic Link for which you want to get event data. |\n| \u003cvar translate=\"no\"\u003eDURATION\u003c/var\u003e | The number of days for which to get event data. For example, if you specify `30`, the request retrieves data for the past 30 days. Note that some events logged in the last 36 hours might not be included. |\n| \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e | An unexpired access token. See [API Authorization](#api_authorization). |\n\nResponse body\n\nThe response to a request is a JSON object like the following: \n\n {\n \"linkEventStats\": [\n {\n \"platform\": \"ANDROID\",\n \"count\": \"123\",\n \"event\": \"CLICK\"\n },\n {\n \"platform\": \"IOS\",\n \"count\": \"123\",\n \"event\": \"CLICK\"\n },\n {\n \"platform\": \"DESKTOP\",\n \"count\": \"456\",\n \"event\": \"CLICK\"\n },\n {\n \"platform\": \"ANDROID\",\n \"count\": \"99\",\n \"event\": \"APP_INSTALL\"\n },\n {\n \"platform\": \"ANDROID\",\n \"count\": \"42\",\n \"event\": \"APP_FIRST_OPEN\"\n },\n\n ...\n\n ]\n }\n\nEach item in the `linkEventStats` list contains a platform-specific count of\nsome Dynamic Link related event (such as the number of clicks on Android). Note that\nthese statistics might not include events that have been logged within the last\n36 hours.\n\n| Event | Description | Firebase console | REST API |\n|----------------|---------------------------------------------------------------------------------------------------------------------------------------|------------------|----------|\n| CLICK | Count of any click on a Dynamic Link, irrespective to how it is handled and its destinations | | |\n| REDIRECT | Count of attempts to redirect users, either to the App Store or Play Store to install or update the app, or to some other destination | | |\n| APP_INSTALL | Count of actual installs (only supported by the Play Store) | | |\n| APP_FIRST_OPEN | Count of first-opens after an install | | |\n| APP_RE_OPEN | Number of times the Dynamic Link caused an app to be re-opened | | |"]]