Using Firebase and Google Tag Manager with AppsFlyer—Google Tag Manager setup

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:

  1. Your Google Tag Manager container is configured for mobile apps.
  2. 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:

  1. Provide Google Tag Manager with the AppsFlyer ID and Dev Key
  2. Provide Google Tag Manager with the event name and event parameters
AppsFlyer Device ID and Dev Key Revenue and Price

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.

  1. In Google Tag Manager, click Variables and then New
  2. Name the variable as "AppsFlyer Dev Key" and click on Variable Configuration
  3. Choose Event Parameter
  4. Choose Custom Parameter
  5. In the Event Parameter field, enter "dev_key" and save
  6. 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:

event_parameter_variable_dev_key.png

 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.

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.

  1. In Google Tag Manager Click on Triggers and then New
  2. Name the trigger as "Purchase" and click on Trigger Configuration
  3. Choose Custom
  4. Choose Some Events
  5. In the conditions, set the trigger to fire when the Event Name equals "af_purchase"
  6. Click Save

 Example

Below is a screenshot from GTM UI. It shows the trigger's final configuration:

trigger_purchase_event.png

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.

  1. In Google Tag Manager click on Tags and then New
  2. Name the tag as "Purchase" and click on Tag Configuration
  3. Choose AppsFlyer
  4. 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.

  5. In the Dev Key field, choose the "AppsFlyer Dev Key" variable
  6. In the AppsFlyer Device ID field, choose the "AppsFlyer Device ID" variable
  7. In the Event Name field, set the built-in variable Event Name
  8. In the Event Currency field, set your currency code e.g. USD
  9. Click twice on Add Event Value
  10. Set the following:
    Key: af_revenue, Value: choose the Event Parameter Variable "Revenue"
    Key: af_price, Value: choose the Event Parameter Variable "Price"
  11. In the Triggering section, set the Firing Trigger to the "Purchase" event trigger
  12. Click Save

 Example

Below is a screenshot from GTM UI. It shows the Tag's final configuration:

purchase_tag.png

4. Publishing the tag manager container

After each change in Google Tag Manager (adding tags etc.) you must download the container and add it to your app root folder:
  • Android - app/src/main/assets/containers
  • iOS - root folder/container
Build and install the application on a test device and check the debug log to see that the event is triggered and sent.