Aghanim-Google Analytics for Firebase Integration
This guide explains how to integrate Aghanim with Google Analytics for Firebase to track purchase events and user behavior. By connecting Aghanim with Google Analytics for Firebase, you can monitor player-generated purchase events from the game hub, ensuring comprehensive tracking of user transactions across your game environment.
Aghanim currently sends purchase events to Google Analytics for Firebase only when a player successfully completes a payment on the game hub.
Requirements
- Google Analytics for Firebase account
- Firebase project with Analytics enabled
- Administrative permissions to access Measurement Protocol settings
Step 1: Get your platform identifiers
Aghanim sends events to different identifiers depending on the platform:
- Web — uses a Measurement ID (format:
G-XXXXXXXXXX). - iOS/Android — uses a Firebase App ID (format:
1:NNNNNNNNNNNN:ios:hexhexor1:NNNNNNNNNNNN:android:hexhex).
Web: Measurement ID
- Log in to your Google Analytics dashboard.
- Navigate to Admin → Data Streams → select your web data stream.
- In the Data stream details, find your Measurement ID and copy it.
iOS/Android: Firebase App ID
- Open the Firebase console and select your project.
- Go to Project settings → General → Your apps.
- Find your iOS or Android app and copy the App ID.
For more details, see the Firebase config file/object reference.
Step 2: Create API Secrets
To enable server-to-server event tracking, you need to create API secrets for the Measurement Protocol. You can create separate API secrets for different platforms (Web, iOS, Android) or reuse the Web API Secret for iOS and Android.
- In the Google Analytics dashboard, navigate to Admin → Data Streams and select the data stream for the platform you're configuring (Web, iOS, or Android).
- In the Data stream details, scroll down to Measurement Protocol API secrets and click Create.
- Provide a nickname for the API secret (e.g., "Aghanim Integration - Web" or "Aghanim Integration - iOS") and click Create.
- Copy the generated API Secret value - this is a unique string that authenticates your server-to-server requests.
- If you want to use different API secrets for different platforms, repeat steps 2-4 for each platform.
For more details, see the Google Analytics Measurement Protocol documentation.
Step 3: Configure the plugin in Aghanim Dashboard
- Go to Aghanim Dashboard → Aghanim Connect → Google Analytics for Firebase and install the plugin.
- In the plugin settings, provide credentials for the platforms you support:
- Web: Measurement ID and API Secret
- iOS: Firebase App ID and API Secret (iOS-specific)
- Android: Firebase App ID and API Secret (Android-specific)
At least one platform must be fully configured. Each purchase is routed strictly by the order's platform — an iOS purchase uses the iOS credentials or is skipped if iOS isn't configured, and the same applies to Android and Web (no fallback between platforms). The only exception is the API Secret: if you don't set an iOS- or Android-specific API Secret, the Web API Secret is reused for that platform.
Step 4: Add Google Analytics for Firebase attributes to player.verify webhook response
To track purchases from iOS or Android, include the Firebase-specific attribute in the player.verify webhook response:
| Key | Type | Description | Required? |
|---|---|---|---|
attributes.ga4firebase_app_instance_id | string | The Firebase app_instance_id obtained from the device-side Firebase SDK (Analytics.appInstanceID() on iOS, FirebaseAnalytics.getAppInstanceId() on Android). Required for iOS/Android purchases; web purchases use the GA4 _ga cookie captured automatically by the game hub. | Yes (iOS/Android) |
attributes.ga4_user_id | string | Your cross-device user ID, sent to GA4 as user_id. Defaults to player_id when not set. Max 256 chars. | No |
Example webhook response:
{
"player_id": "r2d2-c3po",
"name": "R2-D2",
"attributes": {
"ga4firebase_app_instance_id": "1234567890abcdef1234567890abcdef",
"ga4_user_id": "u_8f3a1c2b"
}
}
Alternatively, you can set these attributes at any time via the update_player S2S endpoint — useful when the app obtains the Firebase instance ID after the player.verify exchange (e.g. on a later launch or after the user reinstalls the app):
{
"attributes": {
"ga4firebase_app_instance_id": "1234567890abcdef1234567890abcdef",
"ga4_user_id": "u_8f3a1c2b"
}
}
If ga4firebase_app_instance_id is missing on an iOS/Android purchase, that event is skipped (the rest of the order flow is unaffected).
How it works
When a player completes a purchase on the game hub, Aghanim automatically sends a purchase event to Google Analytics for Firebase. The user identifier depends on the platform:
- Web purchases — sends
client_id(thega4_client_idattribute the game hub captures from the GA4_gacookie). - iOS/Android purchases — sends
app_instance_id(thega4firebase_app_instance_idattribute supplied by the game).
The event payload also includes:
- user_id:
ga4_user_idif set, otherwiseplayer_id - timestamp_micros: purchase timestamp in microseconds (
paid_at, orcreated_atif the order isn't yet paid) - Event data:
- Event name:
purchase - Currency: order currency (e.g.
USD) - Value: purchase amount
- Transaction ID: unique order identifier
- Items: list of purchased items with their IDs and names
- Event name:
This integration ensures that all purchase events from your game hub are automatically tracked in Google Analytics for Firebase, providing comprehensive insights into player spending behavior and purchase patterns.
Need help?
Contact our integration team at [email protected]