How to Set Up Google Tag Manager for Firebase

how-to-set-up-google-tag-manager-1Google Tag Manager allows you to deploy and manage tags for a variety of purposes across websites and apps. Now, you can add Google Tag Manager to Firebase, which improves the experience of building and developing Android and iOS apps.

Setting Up Firebase

The first step is to create a Firebase account and add your app to a new project in the Firebase console. You will need the Package Name if you have an Android app and the Bundle ID if you have an iOS app. If you have both an Android and iOS version of your app, you can either set up two accounts or add them to the same account. In either case, the data are not combined.

Once this stage is complete, you will receive a config file. This comes with instructions on where to place the file in your app and how to install it along with the installation dependencies for the app. Head to “Analytics” in the navigation on the left side to find the reports where your analytics data will appear.

Finally, install Firebase SDK. You will notice that you can enable additional services. Choose all those that are relevant to your app.

Setting Up Google Tag Manager

With Firebase ready, it is time to turn your attention to Google Tag Manager. To begin, add Google Tag Manager Cocoapod to your project. In a terminal, run the command:

$ sudo gem install cocoapods

Then, in your project directory, run the command:

$ pod init

This will create a file called “Podfile,” in which you should add:

pod ‘GoogleTagManager’, ‘~> 6.0’

Finally, run the command:

$ 4 pod install

This will download and install the Google Tag Manager dependencies to your project.

You also need to have a Google Tag Manager container to add to your app. Create a new container, giving it the name you want and selecting the appropriate operating system. Under “Select SDK Version,” choose the Firebase option. You will receive instructions for installing the Google Tag Manager SDK for your app.

Sending Screenviews

There is no need to configure tags in Google Tag Manager to see events logged to Firebase — these will automatically appear in your Firebase Analytics reports. You will need to capture variables and set up Google Analytics tags if you want to send data to Google Analytics, though.

To pull in the screen name from the Firebase event being logged in your app, you need to create an event parameter. After this, create a trigger called “screenview” that listens for Firebase events. Finally, create a Google Analytics tag, setting the tracking ID to a new Google Analytics app property. As soon as everything is set up, screenview hits will appear in the mobile app Google Analytics property.how-to-set-up-google-tag-manager-2

Event Tracking

With the same event parameter you created for screenview hits, you can set up Google Analytics event tracking. You need to create a second event parameter to pull the search term for the event action, plus create a trigger called “search” that listens for Firebase events. Lastly, set up a new Google Analytics tag with your tracking ID to the Google Analytics mobile app property.

Modifying Events

Google Tag Manager also allows you to modify and block events before they are logged in Firebase Analytics. This is necessary if you want to add, remove, or change the values of event parameters or adjust event names. Bear in mind, you are only able to block events and user properties that are not automatically collected.

Publish Your Container

The final stage is to preview your container before publishing it. This will check that everything is working correctly.

Sign in to your Google Tag Manager account and choose the mobile container you want to preview. Click “Versions” in the top navigation bar and choose “Actions” and then “Preview” on the container version. Enter the Package Name or Bundle ID of your app and click “Generate begin preview link.”

To enable previews, you need to define the Google Tag Manager preview URL scheme in the property list of your project. Register the URL identifier: your.package.name and the URL scheme: tagmanager.c.your.package.name under “URL types” in the property list file of the application.

Once you have completed all the above steps, including checking that your container is working, you can publish your container. This will usually mean that tag configurations are available for mobile app users within one day, provided that devices are online.

If you like my articles,