Firebase and 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.
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 the Firebase Console and Google Analytics Data Streams Tab respectively.
Next, access the App's Stream details page within the Data Streams section of Admin settings in Google Analytics.
Under Additional settings, go to the Measurement Protocol API secrets page and create a new API Secret if it doesn't exist. Copy the value.
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.
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.
- iOS (Swift)
- Android (Kotlin)
- Java
- Flutter (Dart)
- Unity (C#)
- React Native (TS)
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) {}
// We suppose FirebaseAnalytics Unity Plugin is already installed
Firebase.Analytics
.FirebaseAnalytics
.GetAnalyticsInstanceIdAsync()
.ContinueWithOnMainThread((task) => {
if (!task.IsCompletedSuccessfully)
{
// handle error
return;
}
var firebaseId = task.Result
var builder = new Adapty.ProfileParameters.Builder();
builder.SetFirebaseAppInstanceId(firebaseId);
Adapty.UpdateProfile(builder.Build(), (error) => {
// handle error
});
});
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`
}
Sending events and user properties
And now it is time to decide which events you will receive in Firebase and Google Analytics.
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.
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 use User properties in your analytics, begin by assigning them to a custom dimension through the Firebase Console's Custom Definitions by selecting the User scope, naming, and describing them.
Please check that your user property 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.