Tag Manager + Firebase: Getting Started

Introduction

Developers can use the Google Tag Manager interface to implement and manage measurement tags and pixels in their mobile applications, without having to rebuild and resubmit application binaries to app marketplaces. Developers who are working with Firebase Analytics can easily add Google Tag Manager to help manage and make changes to the implementation, even after the app has shipped.

Developers can log important events, and decide later which tracking tags or pixels should be fired. Tag Manager currently supports tags for the following products:

  • Firebase Analytics
  • Google Analytics
  • DoubleClick
  • AdWords
  • adjust
  • AppsFlyer
  • Apsalar
  • Kochava
  • Tune
  • Custom Function Calls (for other products)

Prerequisites

Before getting started:

The following section walks you through the steps to configure and use Google Tag manager in your iOS application.

Getting Started

  1. Add Google Tag Manager to your project.
  2. Log events and variables.
  3. Fire tags.
  4. Preview, debug, and publish your container.

1. Add Google Tag Manager to your project

  1. Add the Google Tag Manager Cocoapod to your project:
    1. In a terminal, run the following command to install Cocoapods:
      $ sudo gem install cocoapods
      
    2. Change to your project directory.
    3. Run the following command to create a file named Podfile:
      $ pod init
      
    4. In Podfile, add the following:
      pod 'GoogleTagManager', '~> 5.0'
      
    5. Run the following command to download and install Google Tag Manager dependencies to your project:
      $ pod install
      
  2. Download your container:
    1. Sign in to your Google Tag Manager account
    2. Select your iOS container
    3. Click Versions in the top navigation bar
    4. Click Actions > Download on the selected container version
      The name of the downloaded file is the container ID with a .json extension.
  3. Add the downloaded container to your project:
    1. Copy the downloaded file into a folder called container in the XCode project root (usually PROJECT_ROOT/container/GTM-XXXXXX.json)
    2. Open Xcode
    3. From the File menu, choose Add files to...
    4. Select the container folder
    5. Click Options and make sure Create folder references is selected
    6. Click Finish

2. Log events and variables

Google Tag Manager uses Firebase Analytics' events, parameters, and user properties to trigger and build tags you've configured in the Google Tag Manager web interface. In this sense, your Firebase Analytics implementation acts as your data layer.

Read the Firebase Analytics Developer Documentation for instructions on logging events and setting user properties.

Configure variables in Tag Manager

To capture the value of Firebase event parameters and user properties for use in Google Tag Manager, you can configure variables in the Tag Manager interface.

For example, if you were logging the following custom event in your app:

FIRAnalytics.logEventWithName("share_image", parameters: [
    "image_name": name,
    "full_text": text
  ])

you could configure new Event Parameter variables in Google Tag Manager to capture the image_name and full_text parameter values:

  • Variable Name: Image Name
  • Variable Type: Event Parameter
  • Event Parameter Key Name: image_name

and:

  • Variable Name: Full Text
  • Variable Type: Event Parameter
  • Event Parameter Key Name: full_text

Similarly, if you were setting the following user property in your app:

FIRAnalytics.setUserPropertyString(food, forName: "favorite_food")

you could configure a new Firebase User Property variable in Google Tag Manager to capture the favorite_food value:

  • Variable Name: Favorite Food
  • Variable Type: Firebase User Property
  • Event Parameter Key Name: favorite_food

Modify and block Firebase Analytics events

Google Tag Manager enables you to modify and block events before they are logged in Firebase Analytics. Modifying events can help you—without app updates—add, remove, or change the values of event parameters or adjust event names. Events that are not blocked will be logged in Firebase Analytics.

Firebase Analytics also automatically logs some events and user properties; you don't need to add any code to enable them. These automatically collected events and properties can be used in Google Tag Manager, but cannot be blocked.

3. Fire tags

Firebase event name variables, Firebase event parameter variables, and other variables are used to set up triggers. Trigger conditions are evaluated whenever you log a Firebase event. By default, Firebase Analytics events automatically fire. It is possible to add a Firebase Analytics tag in Tag Manager to block events from being sent to Firebase Analytics.

4. Preview, debug, and publish your container

Before publishing a version of your container, you'll want to preview it to make sure it works as intended. Google Tag Manager enables you to preview versions of your container by generating links and QR codes in the Google Tag Manager web interface and using them to open your application.

Preview container

To preview a container, generate a preview URL in the Google Tag Manager web interface:

  1. Sign in to your Google Tag Manager account.
  2. Select a mobile container.
  3. Click Versions in the top navigation bar.
  4. Click Actions > Preview on the container version you'd like to preview.
  5. Enter your application's package name.
  6. Click Generate begin preview link.

    Preview URLs are available in the  preview window of the Tag
                Manager web interface

    Figure 1: Getting a preview URL from the Tag Manager web interface.

    Save this preview URL for later steps.

To enable container previews, you must define the Google Tag Manager preview URL scheme in your project's property list. Under URL types of your application's property list file, register the following URL identifier and URL scheme:

URL identifier: your.package.name
URL scheme: tagmanager.c.your.package.name
Register the tag manager preview URL scheme in your application's
            property list file.
Figure 2: Adding the Tag Manager preview URL scheme to your application's property list file.

Stop your application and open the preview URL on an emulator or physical device to preview the draft container in your application.

Debug container

When you run your app in a simulator or in preview mode, Tag Manager automatically turns logging to verbose.

Publish container

After previewing your container and verifying that it is working, you can publish it. After you have published your container, your tag configurations are available to mobile app users. When user devices are online, they typically will receive the new configurations within a day.

Next

Read Advanced configuration.