Important!
This integration works with iOS and Android apps that already have the Google Analytics for Firebase SDK implemented. For the integration to succeed, the AppsFlyer SDK has to collect the app_instance_id value from the Firebase SDK. See instructions on how to retrieve the app instance ID from the Firebase SDK.
How does it work?
-
When a new install occurs, AppsFlyer sends the touchpoint details— media source, campaign name, and campaign ID—to GA4. It also sends the Firebase SDK's
app_instance_idto ensure the touchpoint is recorded in GA4 for that user. - When an in-app event occurs, GA4 will attribute the event to the last touchpoint.
Set up Google Analytics (GA4) integration
Follow the instructions below to configure the integration with Google Analytics (GA4).
1. Select Google Analytics (GA4) in the Partner Marketplace
Prerequisite: Before setting up the integration, make sure you contact the partner and open an account with them.
To activate or edit the integration:
- To activate: In AppsFlyer, from the side menu, select Collaborate > Partner Marketplace. To edit: In AppsFlyer, from the side menu, select Collaborate > Active Integrations.
- Search for Google Analytics (GA4) and select it.
- Click Set up integration. You’re directed to the integration setup page.
The Google Analytics configuration only includes the Integration tab.
For a detailed description of the Partner Configuration Window Header, click here.
2. Set GA4 Integration in AppsFlyer
Configure the following settings:
-
In the Integration tab, select the app for the integration and turn Activate partner on.
Note: The toggle must be on (activated) for as long as you work with the partner.
For more details about partner activation, click here.
- In Firebase App ID, enter the identifier of the Firebase app. To learn how to locate the Firebase App ID, see the Firebase documentation.
- In API Secret, enter the API Secret used to authenticate postbacks to Google Analytics. An API Secret is generated through the Google Analytics user interface. To view, edit, or create a secret, follow the instructions in the Google documentation. When instructed to select a web data stream, choose an Android or iOS data stream instead.
- Turn on Customer User ID to send the customer user ID (CUID) instead of the advertising ID (IDFA).
-
Under the Default postbacks section, for users from, select All media sources including organic.
Note
The install postback includes only the touchpoint details (media source, campaign name, and campaign ID).
3. Set default postbacks
AppsFlyer can send automatic postbacks to Amplitude following user installs, including both installs and re-engagements (including re-attributions). Re-engagements occur when a user who already has the app installed opens it after clicking a campaign link. Learn more about default postbacks.
4. Set in-app event postbacks
In the Integration tab, map AppsFlyer in-app events to Google Analytics (GA4) events, sent via postbacks.
Note
- Postbacks for mobile in-app events sent via S2S aren't supported.
- GA4 does not deduplicate events sent from both the Firebase SDK and AppsFlyer. We recommend configuring in-app event postbacks only for events that are not already sent to GA4 via the Firebase SDK.
- Turn on In-app event postbacks.
-
Click Add event to add an SDK event to the list. The following table describes the fields to complete:
Parameter name Description AppsFlyer event The name of the event, as received from the AppsFlyer SDK integrated into your app.
Tip: Don't see the event you are looking for?
- Make sure to activate the event on a device with a non-organic installation, and recheck.
- Type it in AppsFlyer event, then click Create custom.
Read more about custom event mapping.
mapped to partner event The unique name or ID of each event, as defined on the partner's side. Possible mapping configurations are:
- Text field: Get the corresponding event ID from the partner.
- Drop-down box: Select the most suitable pre-defined AppsFlyer event.
- As is: Send the events as they are, without name mapping.
for users from Select the sending option for the event:
- All media sources including organic: Send postbacks for events attributed to any partner, as well as organic events.
including - No data (default): Send only the event itself without any event values.
- Values and revenue: Send all the event parameters, including the revenue value (if exists in the event).
- Values without revenue: Send all the parameters excluding the revenue value.
- [Optional] Click the Add condition icon (
) to set conditions for an event.
- Click Save integration.
- Send the event postback mapping
5. Send your developer the postback event mapping
After you have set up the in-app event mapping, send your developer a table where each mapped event corresponds to a row with the following columns:
- AF event: Name of the AppsFlyer event.
-
Mapped to Google event: Name of the event in Google Analytics.
Important!
Don’t use any of the Google reserved events as names for custom Google Analytics events.
-
AF event parameters (MANDATORY): Predefined AppsFlyer event parameters that must be included in the event postback sent to Google Analytics.
Important!
It is mandatory to include all predefined AF event parameters within the event definition exactly as they are listed in the table; failure to do so will result in Google Analytics rejecting the postback.
The event mapping table
The following table includes all the Google Analytics events and their predefined AppsFlyer parameters. Send your developer a table containing just the events that you mapped.
Reserved Google event names
The following event names are reserved and cannot be used as custom event names:
ad_activeviewad_clickad_exposuread_queryad_rewardadunit_exposureapp_clear_dataapp_exceptionapp_installapp_removeapp_store_refundapp_updateapp_upgradedynamic_link_app_opendynamic_link_app_updatedynamic_link_first_openerrorfirebase_campaignfirebase_in_app_message_actionfirebase_in_app_message_dismissfirebase_in_app_message_impressionfirst_openfirst_visitin_app_purchasenotification_dismissnotification_foregroundnotification_opennotification_receivenotification_sendos_updatesession_startuser_engagement
6. Retrieve app instance ID in AppsFlyer SDK
The app_instance_id uniquely identifies a Firebase app installation, and the ga_session_id uniquely identifies a Firebase app session. Retrieve these values from the Firebase SDK, then send them to GA4 using the setAdditionalData API.
Let your developer implement the code to:
- Collect the
app_instance_idand thega_session_idfields from Firebase. - Call
setAdditionalData, before the first launch, to include the app instance ID andga_session_id, in installs, sessions, and in-app events.
Important!
setAdditionalData (Android / Unity / React Native) and customData (iOS) accept a mapping of key-value pairs. Sends both app_instance_id and ga_session_id together in the same mapping, so both values are included. If you send them in separate setAdditionalData calls, the later one will overwrite the earlier one.
Kotlin
FirebaseAnalytics.getInstance(this).appInstanceId.addOnCompleteListener { task ->
if (task.isSuccessful) {
AppsFlyerLib.getInstance().setAdditionalData("app_instance_id", task.result)
}
}
Java
FirebaseAnalytics.getInstance(this).getAppInstanceId().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
AppsFlyerLib.getInstance().setAdditionalData("app_instance_id", task.getResult());
}
});
API reference: setAdditionalData
iOS native
let appInstanceId = Analytics.appInstanceID()
AppsFlyerLib.shared().customData = ["app_instance_id": appInstanceId]
Objective C
(void) fetchAnalyticsInstanceId {
NSString *instanceID = [FIRAnalytics appInstanceID];
[[AppsFlyerLib shared] setAdditionalData:@{@"app_instance_id": instanceID}];
}
API reference: customData
using Firebase.Analytics;
public class AnalyticsManager : MonoBehaviour
{
private async void Start()
{
AppsFlyer.initSDK(devKey, appID, this);
string appInstanceId = await FirebaseAnalytics.GetAnalyticsInstanceIdAsync();
Dictionary <string, string> customData = new Dictionary<string, string>();
customData.Add("app_instance_id", appInstanceId);
AppsFlyer.setAdditionalData(appInstanceId);
AppsFlyer.startSDK();
}
}
API reference: setAdditionalData
API reference: setAdditionalData
7. Retrieve GA4 session ID in the AppsFlyer SDK
The ga_session_id uniquely identifies a session of a Firebase app. This value must be retrieved from the Firebase SDK and sent to GA4 using the setAdditionalData API.
Let your developer implement the code to:
- Collect the
ga_session_idfield from Firebase. - Call
setAdditionalDatabefore the first launch to include the session ID (andapp_instance_id, if used). - Use the key
ga_session_idwhen calling the API.
Important!
setAdditionalData (Android / Unity / React Native) and customData (iOS) accept a mapping of key-value pairs. If your app sends both app_instance_id and ga_session_id (see step 5), send them together in the same mapping so both values are included. If you send them in separate setAdditionalData calls, the later one will overwrite the earlier one.
Kotlin
FirebaseAnalytics.getInstance(this).sessionId.addOnCompleteListener { task ->
if (task.isSuccessful) {
AppsFlyerLib.getInstance().setAdditionalData("ga_session_id", task.result)
}
}
Java
FirebaseAnalytics.getInstance(this).getSessionId().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
AppsFlyerLib.getInstance().setAdditionalData("ga_session_id", task.getResult());
}
});
API reference: setAdditionalData
Swift
if #available(iOS 14.0, *) {
Analytics.sessionID { sessionID, error in
if let sessionID = sessionID {
AppsFlyerLib.shared().customData = ["ga_session_id": sessionID]
}
}
}
Objective-C
- (void)fetchAnalyticsSessionId {
if (@available(iOS 14.0, *)) {
[FIRAnalytics sessionIDWithCompletion:^(NSString * _Nullable sessionID, NSError * _Nullable error) {
if (sessionID) {
[[AppsFlyerLib shared] setAdditionalData:@{@"ga_session_id": sessionID}];
}
}];
}
}
API reference: customData
using Firebase.Analytics;
using System.Threading.Tasks;
using AppsFlyerSDK;
using UnityEngine;
using System.Collections.Generic;
public class AnalyticsManager : MonoBehaviour
{
private async void Start()
{
AppsFlyer.initSDK("yourDevKey", "yourAppID", this);
// Get session ID
string sessionId = await FirebaseAnalytics.GetSessionIdAsync();
Dictionary<string, string> customData = new Dictionary<string, string>();
customData.Add("ga_session_id", sessionId);
AppsFlyer.setAdditionalData(customData);
AppsFlyer.startSDK();
}
}
API reference: setAdditionalData
8. Validate the GA4 integration
Make sure the events in the postbacks you send to GA4 are registered and read by Google Analytics. There are two methods advertisers can use to view their data:
- Using GA4 Explorations, you can explore the raw event data with all associated parameters. Prerequisite: Big Query export must be set up in your property)
-
The Events report enables advertisers to view their postback events. The report can be found under one or more report collections.
For example, the Events reports can be found in the Life cycle or the Games reporting collections under Engagement > Events.
For more information on the Events report see the Google documentation. -
The Traffic acquisition report helps you understand where your website and app visitors are coming from.
Under the Life cycle collection go to Acquisition > Traffic Acquisition).
For more information on the Traffic acquisition report, see the Google documentation.