Google Tag Manager

Its free resolution for tag management. It allows the developers to alter configuration values in their mobile applications exploitation the tag manager interface.

The Google Tag Manager is incredibly welcome, particularly by Marketers. within the past, everything was controlled by webmasters, together with web site chase, that was extremely technical because it needed handling log files.

Google Tag Manager for mobile app developer devices also make their development easy and dynamic.

In this post, we will cover how to get started with GTM for Android apps.

Before getting started

  1. Install the Firebase SDK.
  2. In the Firebase console, add your app to your Firebase project.
  3. Add Firebase Analytics to your app.
  4. Create a Google Tag Manager account.
  5. Configure a Google Tag Manager container.
  6. The following section walks you through the steps to configure and use Google Tag manager in your Android application.

Adding GTM into your Android Project

  1. Note down the Container ID which you have been created in your GTM account (It would be of the form of GTM-XXXXX)
  2. Add Google Play Services library to your project


  1. Add the following permissions in your AndroidManifest.xml



  1. Also Add the Install Referrer Receiver in AndroidManifest.xml to track Campaign Data.


       5. As I mentioned earlier, we’re going to use GTM for collecting Firebase events and sending them to our mobile Google        Analytics property in order to enable a new suite of reports that we otherwise would not get with Firebase First we need to make sure we have a GTM container to add to our app. Go to GTM site and create a new container for your app(s). Select the appropriate operating system and choose a Firebase container :

     6. Once you do this, you will immediately be provided with a link to instructions on installing the GTM SDK for your app:


Now, Create a Trigger with the following configuration in Google Tag Manager Container.

  1. Create a DataLayer Variable to fetch the value of screenName from the datalayer.


  1. Create a Tag to fire the Screen View from the app.


  1. Add Google Tag Manager’s Default Container to your Project. Within Google Tag Manager interface select VERSIONS -> ACTION -> DOWNLOAD this will download the container binary file.


  1. Within your Android project, create a raw folder in project-root / res path.
    Copy the downloaded binary file to the path project-root / res / raw with changing the filename to gtm_defaultcontainer_gtm_id.

Initializing Tag Manager Instance and using DataLayer

  1. Create a ContainerHolderSingleton Class.
  2. ContainerHolderSingleton class is used to have access to a single instance of TagManager Object at a time.

  1. Create a class ContainerLoadedCallback Class. ContainerLoadedCallback class is used to load the fresh GTM Container when it is available


  1. Initialize Tag Manager in First Screen of the App (i.e. Splash Screen or Main Screen) Load latest container by specifying  the CONTAINER_ID Use ResultCallback to return the ContainerHolder once it has finished loading or has timed out for fetching the latest container.


  1. After Initializing GTM well, it’s time to feature the pursuit code, that is enforced victimization the DataLayer Object. DataLayer provides a layer of persistence that you use to store data in key-value pairs form and then send it to Google Analytics.

  2. Create one method in general util class to push the openScreen event and start tracking the Screen views from your app. You can call this method in onCreate()/onStart Method of your app activities with the screenName that you want to send.


With the above steps performed we have successfully implemented the Google Tag Manager in Android.

To know that your implementation is working well, verify your data in Google Analytics Report.




Yatindra Sahu

Data Enthusiast

Related Posts


Helpful technical-coding skills for entrepreneurs

Where there is a will, there is a way. If there is a chance in a million that you can do something, anything, to keep what you want from ending, do it. Pry the door Read more…

Employee Onboarding App

How to hire with little or no money

If you are trying to hire employees with little or no money than it could be because, in a business, there are just so many things to do! There is marketing, sales, product, user experience, Read more…


Getting List ID for Trello API

Getting List ID for Trello API So the MangoBlogger onboarding task required me to add a card to my trello board using the Google App Script, But after some fiddling around with the Trello Read more…