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.

How to set up Firebase integration

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.

Set up Firebase

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.

Integrate with Adapty

Firebase App ID

Next, access the App's Stream details page within the Data Streams section of Admin settings in Google Analytics.

Retrieving Google Analytics Secret. Step 1

Retrieving Google Analytics Secret. Step 1

Under Additional settings go to Measurement Protocol API secrets page and create a new API Secret if it doesn't exist. Copy the value.

Retrieving Google Analytics Secret. Step 2

Retrieving Google Analytics Secret. Step 2

Retrieving Google Analytics Secret. Step 3

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 for your iOS and Android platforms.

Setting up integration in Adapty Dashboard

Setting up integration in Adapty Dashboard

SDK configuration

Then you have to set up Adapty SDK to associate your users with Firebase. For each user, you should send thefirebase_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
        }
    });
});
import 'package:firebase_analytics/firebase_analytics.dart';

final builder = AdaptyProfileParametersBuilder()
        ..setFirebaseAppInstanceId(
          await FirebaseAnalytics.instance.appInstanceId,
        );
        
try {
    await adapty.updateProfile(builder.build());
} on AdaptyError catch (adaptyError) {
    // handle error
} catch (e) {}
import analytics from '@react-native-firebase/analytics';
import { adapty } from 'react-native-adapty';

try {
  const appInstanceId = await analytics().getAppInstanceId();

  await adapty.updateProfile({
    firebaseAppInstanceId: appInstanceId,
  });
} catch (error) {
  // handle `AdaptyError`
}
Firebase.Installations
                .FirebaseInstallations
                .DefaultInstance
                .GetIdAsync()
                .ContinueWith((task) => {
                    if (!task.IsCompletedSuccessfully) {
                        // handle error
                        return;
                    }

                    String firebaseId = task.Result;

                    var builder = new Adapty.ProfileParameters.Builder();
                    builder.SetFirebaseAppInstanceId(firebaseId);

                    Adapty.UpdateProfile(builder.Build(), (error) => {
                        // handle error
                    });
            });

Sending events and user properties

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

Sending events and user properties

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.

Enabling "Send user properties" in Adapty Dashboard

Enabling "Send user properties" in Adapty Dashboard

This means that your events will be enriched with subscription_state and subscription_product_id by Adapty. But you also have to enable this feature in Google Analytics. So to utilize User properties in your analytics, begin by assigning them to a custom dimension through Firebase Console's Custom Definitions by selecting User scope, naming, and describing them.

Create User Property in Google Analytics. Step 1

Create User Property in Google Analytics. Step 1

Create User Property in Google Analytics. Step 2

Create User Property in Google Analytics. Step 2

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

📘

There is a time delay between when events are sent from Adapty and when they appear on the Google Analytics Dashboard. It's suggested to monitor the Realtime Dashboard on your Google Analytics account to see the latest events in real-time.

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