Firebase and Google Analytics

Learn how to setup Firebase integration and get insights from Google Analytics

If you use such Google products as Google Analytics, Firebase, and BigQuery you may enrich your analytical data with events from Adapty using the integration described in this article. Events are sent through Google Analytics to Firebase and may be used in any of these services.

1. Set up Firebase

First of all, you have to enable integration between Firebase and Google Analytics. You can do it in your Firebase Console in the Integrations tab.

1850

Integrate Firebase and Google Analytics

2. Integrate with Adapty

Then Adapty needs your Firebase App ID and Google Analytics API Secret to send events and user properties. You can find these parameters in Firebase Console and Google Analytics Data Streams Tab respectively.

1834

Firebase App ID

1714

Retrieving Google Analytics Secret. Step 1

1781

Retrieving Google Analytics Secret. Step 2

1801

Retrieving Google Analytics Secret. Step 3

Then, your next step will be adjusting integration in Adapty Dashboard. You will need to provide Firebase App ID and Google Analytics API Secret to us.

1025

Setting up integration in Adapty Dashboard

3. Set up Adapty SDK

Then you have to set up Adapty SDK to associate your users with Firebase. For each user, you should send firebase_app_instance_id to Adapty. Here you can see an example of the code which can be used to integrate Firebase SDK and Adapty SDK.

import FirebaseCore
import FirebaseAnalytics

FirebaseApp.configure()
        
if let appInstanceId = Analytics.appInstanceID() {            
    let builder = AdaptyProfileParameters.Builder()
        .with(firebaseAppInstanceId: appInstanceId)
            
    Adapty.updateProfile(params: builder.build()) { error in
                // handle error
    }
}
//after Adapty.activate()

FirebaseAnalytics.getInstance(context).appInstanceId.addOnSuccessListener { appInstanceId ->
    Adapty.updateProfile(
        AdaptyProfileParameters.Builder()
            .withFirebaseAppInstanceId(appInstanceId)
            .build()
    ) {
        //handle error
    }
}
//after Adapty.activate()

FirebaseAnalytics.getInstance(context).getAppInstanceId().addOnSuccessListener(appInstanceId -> {
    AdaptyProfileParameters params = new AdaptyProfileParameters.Builder()
        .withFirebaseAppInstanceId(appInstanceId)
        .build();
    
    Adapty.updateProfile(params, error -> {
        if (error != null) {
            // handle the error
        }
    });
});

4. Sending events and user properties

And now it is time to decide which events you will receive in Firebase and Google Analytics.

984

Events names in Adapty Dashboard

You can see that some events have designated names, for example. "Purchase", while other ones are usual Adapty events. This discrepancy comes from Google Analytics event types. Currently, supported events are Refund and Purchase. Other events are custom events. So, please ensure that your event names are supported by Google Analytics.
Also, you can set up sending user properties in the Adapty dashboard.

1000

Enabling "Send user properties" in Adapty Dashboard

This means that your events will be enriched with subscription status and subscription_product_id. But you also have to enable this feature in Google Analytics.

1813

Create User Property in Google Analytics. Step 1

1911

Create User Property in Google Analytics. Step 2

Please check that your user properties names are subscription_status and subscription_product_id. Otherwise, we won`t be able to send you subscription status data.

And that`s all! Wait for new insights from Google.