Step-by-step Walkthrough: How to Implement Google Tag Manager v5 for your Android Application

 

gtm_v5Google Tag Manager v5 is now all set with Firebase SDK for Apps, adding unique supplementary features to the Google Analytics arena.

Firebase was earlier a stand-alone company until Google purchased it in 2014. Google then tweaked Firebase as a whole new baggage for mobile app development, along with adding few obliging feature of Analytics to it. Firebase now includes tools for app development, like cloud messaging, database storage, hosting, etc. These tools can help us grow our app’s audience using push notifications and app indexing. Yes, Firebase Analytics sits right on top, pulling all the strings of the entire product.

In the previous blog, we had a walkthrough on how to implement tags with Google Tag Manager v4 in your Android application. Moving ahead, in this blog post, I will take you through the process of implementing Google Tag Manager v5.

Steps to set up GTM v5 in an Android Project
Setup Firebase
    1. Login to Firebase Console
    2. Create a Project and add your Application details as per the instructions.
    3. Download the google-services.json file and add it into your Android Application project as shown below.
      gtm

Image 1: Adding google-services.json file to your Android Application project

Add Google Tag Manager in Your Android Application
  1. Add Firebase SDK to your project in your Android Project. At the project level, add build.gradle file and include the google-services Plugin.

    gtm v5Image 2: Adding Firebase SDK  to your Android Application project

  2. At your app level, add the build.gradle file and include dependencies of both Firebase and Google Tag Manager

    androidImage 3: Adding Firebase SDK  to your Android Application project

  3. Create a Firebase Analytics Object and use it to track event by adding appropriate event name and its parameters.

    implement gtm v5Image 4: Creating Firebase Analytics Object in  your Android Application project

With these 3 steps, your Google Tag Manager v5 is now configured with your Android app. But we are missing out on something very important. The question you should be asking is:

Will setting up Firebase and GTM SDK be enough to track the event?  

Well, if we are using Google Tag Manager, it’s mandatory to configure a tag by setting the right triggering event to it. Hence, moving forward with GTM v5, with the features that it provides over the GTM v4 version, we can now control the event configuration with three different action types for a single event that is to be tracked.

Google Tag Manager Tag Configuration for Custom Events
  1. To start off with Google Tag Manager, first create a Container of Firebase type in Google Tag Manager Console :

    gtm console
    Image 5: Creating container

  2. We now begin with the configuration of an event in GTM. As opposed to the v4 tag configuration, v5 event tags are remarkably advanced in providing more actions. We have three actionable options in tag configuration :

    • Add  Event
    • Modify Event
    • Block Event
      Let us understand the strengths of these 3 actions by using it in our event configurations.

      1. Add Event
        Configure a Login event in Google Tag Manager v5 as shown below, for when the user logs into the app. For this use, let’s say the name of the event that fires if “new_login”

        android app
        Image 6: Tag Configuration – Add Event

        gmt v5
        Image 7: Trigger Configuration for the above tag

      2. Edit Event
        Post the successful tag configuration, we have an event for users logging in the app. But down the road, when the app is published on Playstore, we will be required to edit the name of the event that is being tracked from “new_login” to “Login”. Here’s how we can modify our existing Login event tag as shown below, without any efforts from app implementation.

        implement gtm v5
        Image 8: Tag Configuration – Modify Event

      3. Block Event
        Now, If user is signing up in the app for the first time, and it leads user to login automatically for the instance, then in this case we don’t require the Login event to be triggered in Firebase. The block event feature comes in handy for such an instance. Here is how you can use the feature of blocking the event on specific screen(i.e. Sign up screen) as shown below.

        android gtm
        Tag Configuration – Block Event

        google tag manager
        Trigger Configuration for the above tag

  3. Once the tags are configured, we will then need to publish the container, download it and add it to the Android Project. In assets -> container folder.

    google tag manager androidImage 9: Adding Container to Android Project

Please Note :

  • It is necessary to publish the container each time when new tags are configured in GTM
  • Adding the container file to the project is to be done only once when the container is published for the first time.
Concluding

We are now ready to run the application and verify the results as follows:

In the terminal, write following three commands:

gtm v5

View the logs for configured events by applying the filter of “D/FA” in Android Monitor,  or visit your Firebase Console for the same.

So, that’s it. This is how you can integrate Google Tag Manager version 5 in your Android app. Happy Tagging!

If you are stuck anywhere or need guidance while implementing the GTM v5 for your Android app, please feel free to leave us a comment in the section below and our Android experts will be glad to help you out.

, , ,
Previous Post
Update from Google Analytics: You Can Now Stream Your Google Analytics 360 Data to BigQuery Export
Next Post
Insights from Push Notifications Tracking With Google Analytics: Take a Peek into How Your Users are Interacting with Your Brand

26 Comments. Leave new

  • Hello Vedangi!

    Thank you for the clear guide of GTM implementation. I’m newbie at app analytics and this information is quite useful for me 🙂

    We’ve already use GA, Firebase, AppsFlyer. Now we’d like to implement GTM to our app.
    Could you please help me to understand two things:

    1. Should trackers’ codes be implemented to GTM or they need to be implemented in app’s code? Should we remove all implemented code before from the app and use only GTM tags?
    Like on websites, we can implement GA (or other trackers) code in the website code or in GTM. In both cases trackers will work. Is this the same for mobile apps?

    2. Sould we change events and enhanced ecommerce tracking implemented before GTM was added to the app or the ‘old code’ will still work?

    Reply
    • Thanks for writing Nadine. Below is the explanation for your query :
      1. Yes, it is kind of similar as web. But we suggest to keep single tracker which would be created through GTM. No need to initialise another tracker from app side.

      2. Old code will work same. But to keep GTM as a mediator to send your data, some syntactical changes would be required. Code would be very much reduced than your current code. In case of app , we send keys (which you can consider as an event) with some dynamic parameters ( i.e screen name,e-commerce data) and from GTM side, we can control what data should be passed to GA. So we would suggest you to replace your tracking with newer syntax (Bundle) of GTM V5, where you will only push events, and dynamic parameters (event category,action,etc. will be manageable through GTM only) .
      – It also supports Enhance e-commerce now. So no need to worry about enhance e-commerce tracking. One thing I would highlight here is, currently GTM V5 does not support product level custom dimensions. If you are using this feature at high extent, then go with GTM V4(Legacy GTM).

      Reply
      • Vedangi, thank you for your reply. I’ve had some time to find out, that some trackers have requirements to install their SDK in app code (AppsFlyer, adjust). Do you want to suggest move all trackers from app side to GTM anyway? Why?

        Reply
  • Hi Vedangi Pathak,
    Add event is working fine but block event not working.

    Bundle params = new Bundle();
    params.putString(“loginTime”, “time_stamp”);
    params.putString(“login”, “true”);
    params.putString(“ScreenName”, “SignUp”);
    mFirebaseAnalytics.logEvent(“Logged_in”, params);
    these are the data i’m passing.

    in GTM i created tag for block event
    ScreenName equals SignUp. But now its showing in Analyticas

    Reply
  • Fantastic blog! Thanks for sharing very interesting post, I appreciate to blogger for amazing post.

    Reply
  • You defined your article so well and I am much comfortable to read this because of the given example easy. We now know that how we implement google tag manager V5 android application.

    Reply
  • Avatar
    Kalpesh Wadekar
    March 16, 2018 1:13 pm

    I followed the following docs for creating Tags and triggers in GTM:
    https://developers.google.com/tag-manager/android/v5/enhanced-ecommerce#purchases

    I am able to track “events” and “screen views” in GA using GTM + Firebase but not the “ecommerce purchase”.
    I can see logs in firebase debug view for “ecommerce purchase” event, but it is not getting recorded in Google Analytics.

    Reply
    • Hi Kalpesh,

      Thanks for reaching out. If you are seeing logs for Firebase Analytics, It will be available. Because to send data to Firebase Aanlytics, GTM configuration is not required.

      I would request you to check your google analytics tag for ecommerce purchase and verify below things:
      Tag Type: Universal Analytics
      Track Type: Screen View/Event (your preference)
      Fields to Set: (Field Name) screenName (value, e.g.) Thank You Screen
      Enable Enhanced Ecommerce Features: True
      Read data from: Firebase Event
      Trigger, e.g.: (Custom > Some Events) Event Name equals ecommerce_purchase

      Reply
  • Avatar
    Ankush Mahajan
    August 22, 2018 10:57 am

    How to check in real time for a Mobile App, that event I have created in GTM is fire or not?

    Reply
    • Hi Ankush

      You can check the realtime data in the stream view report of Firebase Analytics and If you are sending data to Google Analytics from GTM, then you can verify the same in real-time reports.

      In the Streamview Report of Firebase Analytics, you can filter your data by selecting your device from the available live user’s data.

      Reply
  • Hi, Vedangi!

    I’m migrating GTM from v3 to v5. My app use GTM to get dynamic value from GTM container.

    But I cannot found the document which is talking about getting value from container and The container in library is removed with firebase library.

    Please give me some advise if you have any idea about my issue. Thanks!

    Reply
    • Hi Jack,

      If you are using GTM v5, then you must be integrating firebase with your application. Firebase has introduced one feature called “”Remote Config””. Remote config helps you to dynamically fetch updated value published from Firebase Console. Checkout out the link for reference.
      for reference.

      Reply
  • I want To know where to place the GTM snippet in the android app. Or is it just to place Container alone which will lead the app to connect GTM and then firebase

    Reply
    • Hey Jerry!
      You just have to add the container file in the respective place mentioned in the blog. Firebase SDK is designed in a way that if it finds a GTM container in containers folder, It will initialize the GTM itself.

      Reply
      • Thanks for the feedback.
        But, what about i use GTM directly in Android App, rather than going through firebase, Place the Google Service play- Tagmanager snippet(singleton) and create Datalayer as we create for Website. And In Google Analytics I create a separate View rather than a property with Application filter.

        Reply
        • Hi Jerry

          The approach mentioned by you is already known as GTM v4 approach, in which we implement Datalayer in Android and send hits to GA, which are visible in Mobile View (without having to create another property for mobile app tracking).
          But Google will be declaring the final sunset date of v4 Approach on 30th June 2020. Hence this approach is not advisable. Rather, one should opt for v5 approach.

          Reference link for the same.

          Let me know if any concerns here

          Reply
  • Avatar
    Pushkar Srivastava
    December 18, 2018 12:10 pm

    Hi Vedangi,
    Thanks for yout tutorial but please let me know where we can see analytics of these events which are fired by firebseAnalytics and don’t we have to enable the enhanced ecommerce for that?

    Reply
    • Hi Pushkar,
      We’re glad you liked our tutorial.
      For your query, the data for these events will be available in firebase console it self. Switch to Analytics -> Events report in there. Firebase Ecommerce events can be tracked without any settings in firebase console.

      Reply
  • Hi Vedangi, Very helpfull post but I want to know one thing is any code we need to do related to Tag manager in our project because I can see that in your previous blog (Google Tag Manager v4) you are using so many class like TagManager , ContainerLoaderCallback,ContainerHolderSingelton etc. Now I want to ask we also need to do that same for Google Tag Manager V5?

    Thanks in advance.

    Reply
    • Tatvic Analytics
      Tatvic Analytics
      March 19, 2019 12:10 pm

      Hey Rohit, Thanks For writing in. We need not add those classes here. The SDK itself handles the callback. It only requires the GTM id, which it finds from the filename you have added in app/src/main/assets/containers.

      Reply
      • Avatar
        Rohit Sharma
        April 3, 2019 4:48 pm

        HI Vedangi, thanks for the response,
        I also want to know one thing I have to implement GTM with firebase as well as appsflyer and google analytics, So here should I create GTM tag three times one for Appsflyer and one for google analytics and one for firebase?

        Reply
  • Avatar
    Rohit Sharma
    April 3, 2019 4:49 pm

    HI Vedangi, thanks for the response,
    I also want to know one thing I have to implement GTM with firebase as well as appsflyer and google analytics, So here should I create GTM tag three times one for Appsflyer and one for google analytics and one for firebase?

    Reply
    • Hi Rohit,

      You have to create 2 tags, one for Appsflyer and one for GA. For Firebase, TAG is not mandatory. Same data which you send from the app will be available in Firebase Analytics. Firebase tag comes into the picture when you want to modify/delete/add something with the data being sent.

      Reply
  • Hi There,
    Is it possible if we want to integrate chatbot via GTM Android (In web it’s so simple) or adding SDK directly to the App is the only solution here.

    Reply

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu