Google Tag Manager Install on Android App Project
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
- Install the Firebase SDK.
- In the Firebase console, add your app to your Firebase project.
- Add Firebase Analytics to your app.
- Create a Google Tag Manager account.
- Configure a Google Tag Manager container.
- 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
- Note down the Container ID which you have been created in your GTM account (It would be of the form of GTM-XXXXX)
- Add Google Play Services library to your project
- Add the following permissions in your AndroidManifest.xml
- 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.
- Create a DataLayer Variable to fetch the value of screenName from the datalayer.
- Create a Tag to fire the Screen View from the app.
- 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.
- 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
- Create a ContainerHolderSingleton Class.
- ContainerHolderSingleton class is used to have access to a single instance of TagManager Object at a time.
- Create a class ContainerLoadedCallback Class. ContainerLoadedCallback class is used to load the fresh GTM Container when it is available
- Initialize Tag Manager in First Screen of the App (i.e. Splash Screen or Main Screen) Load the 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.
- 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.
- 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.