At a glance: Instructions for setting up event sending reported via Firebase SDK to AppsFlyer in Google Tag Manager.
Google Tag Manager setup
This section discusses the necessary setup in Google Tag Manager (GTM) UI. All the steps described in this section are required in order for GTM to send events to AppsFlyer. Follow the steps in the order they are listed.
The following steps are for Google Tag Manager for mobile apps. If the UI that you see in your Google Tag Manager is different than the screenshots in the various steps, check the following:
- Your Google Tag Manager container is configured for mobile apps.
- The container is v5. For more information, click here.
Note
The steps described in this section relate to a purchase event but are relevant for any event that you wish to send.
1. Creating event parameter variables
Event parameter variables allow Google Tag Manager to obtain data from the event. When the event is sent, the AppsFlyer ID and Dev Key variables are passed along with it. Google Tag Manager then evaluates their value and this is how it obtains them. The data from the event has two functions:
- Provide Google Tag Manager with the AppsFlyer ID and Dev Key
- Provide Google Tag Manager with the event name and event parameters
Whenever Google Tag Manager sends an event to AppsFlyer, it must send it with the AppsFlyer ID and Dev Key. The Dev Key allows Google Tag Manager to communicate with AppsFlyer servers. The AppsFlyer ID lets AppsFlyer know what user to attribute the event to.
- In Google Tag Manager, click Variables and then New
- Name the variable as "AppsFlyer Dev Key" and click on Variable Configuration
- Choose Event Parameter
- Choose Custom Parameter
- In the Event Parameter field, enter "dev_key" and save
- Repeat the process for AppsFlyer ID as well - name the variable as "AppsFlyer Device ID" and enter "af_id" in the Event Parameter field
Example
Below is a screenshot from GTM UI. It shows the event parameter's final configuration:
Important!
For iOS, an additional Event Parameter should be configured. Follow the same flow as listed above. Create a variable and name it "Apple App ID". In the Event Parameter field, enter "apple_app_id" and save.
The next step is to create and set AppsFlyer ID and Dev Key variables inside the app. This step is discussed in the Sending Events Section.
Most in-app events require event value parameters. In this case, it is the af_revenue and af_price parameters but you can send any event parameters. Now that the event is configured in the app, revenue and price variables need to be created in Google Tag Manager. These variables are used later on in the Purchase event tag.
- In Google Tag Manager, create two Event Parameter variables for af_revenue and af_price
- For "af_revenue", name the variable "Revenue" and set the Event Parameter Key to "af_revenue"
- For "af_price", name the variable "Price" and set the Event Parameter Key to "af_price"
Example
Below is a screenshot from GTM UI. It shows the event parameter's final configuration:
Note
The example here shows how to create event parameter variables for Revenue and Price event parameters. You can create event parameter variables for any kind of event parameter, according to the event that is sent.
2. Creating a trigger for the purchase event
In order for Google Tag Manager to know if the event should be sent to AppsFlyer, a trigger for the event must be configured.
- In Google Tag Manager Click on Triggers and then New
- Name the trigger as "Purchase" and click on Trigger Configuration
- Choose Custom
- Choose Some Events
- In the conditions, set the trigger to fire when the Event Name equals "af_purchase"
- Click Save
Example
Below is a screenshot from GTM UI. It shows the trigger's final configuration:
3. Creating a tag for the purchase event
Now that the required variables and the event trigger are set, you can create the Purchase event tag.
- In Google Tag Manager click on Tags and then New
- Name the tag as "Purchase" and click on Tag Configuration
- Choose AppsFlyer
- In the Application ID field, set the built-in variable the App ID
Important!
For iOS, set the "apple_app_id" custom variable in the Application ID field.
- In the Dev Key field, choose the "AppsFlyer Dev Key" variable
- In the AppsFlyer Device ID field, choose the "AppsFlyer Device ID" variable
- In the Event Name field, set the built-in variable Event Name
- In the Event Currency field, set your currency code e.g. USD
- Click twice on Add Event Value
- Set the following:
Key: af_revenue, Value: choose the Event Parameter Variable "Revenue"
Key: af_price, Value: choose the Event Parameter Variable "Price" - In the Triggering section, set the Firing Trigger to the "Purchase" event trigger
- Click Save
Example
Below is a screenshot from GTM UI. It shows the Tag's final configuration:
4. Publishing the tag manager container
- Android - app/src/main/assets/containers
- iOS - root folder/container