Skip to main content

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.

info

Aghanim currently sends purchase events to Google Analytics for Firebase only when a player successfully completes a payment on the game hub.

Requirements

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:hexhex or 1:NNNNNNNNNNNN:android:hexhex).

Web: Measurement ID

  1. Log in to your Google Analytics dashboard.
  2. Navigate to AdminData Streams → select your web data stream.
  3. In the Data stream details, find your Measurement ID and copy it.

iOS/Android: Firebase App ID

  1. Open the Firebase console and select your project.
  2. Go to Project settingsGeneralYour apps.
  3. 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.

  1. In the Google Analytics dashboard, navigate to AdminData Streams and select the data stream for the platform you're configuring (Web, iOS, or Android).
  2. In the Data stream details, scroll down to Measurement Protocol API secrets and click Create.
  3. Provide a nickname for the API secret (e.g., "Aghanim Integration - Web" or "Aghanim Integration - iOS") and click Create.
  4. Copy the generated API Secret value - this is a unique string that authenticates your server-to-server requests.
  5. 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

  1. Go to Aghanim Dashboard → Aghanim ConnectGoogle Analytics for Firebase and install the plugin.
  2. 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:

KeyTypeDescriptionRequired?
attributes.ga4firebase_app_instance_idstringThe 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_idstringYour 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 (the ga4_client_id attribute the game hub captures from the GA4 _ga cookie).
  • iOS/Android purchases — sends app_instance_id (the ga4firebase_app_instance_id attribute supplied by the game).

The event payload also includes:

  • user_id: ga4_user_id if set, otherwise player_id
  • timestamp_micros: purchase timestamp in microseconds (paid_at, or created_at if 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

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]