Android – Google tag Manager with Google Analytics and Firebase Analytics

I am working with a shopping app and would like to track so events occuring on my mobile application. My objective is to track the events using Firebase Analytics and Google Tag manager and push the same events to Google analytics.

My event > Firebase > Google tag manager > Google analytics

  • When will MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST be applied?
  • Display push notification in alert box when the app is running in the foreground
  • Android Signature Capture
  • In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?
  • How to remove or delete Android app from Admob?
  • How can I launch mobile network settings screen from my code
  • I followed the below guide to integrate Google tag manager and Firebase analytics to my application.

    I was able to log my events on Firebase console and view in debug console. I have added dependency for Tag manager in my gradle so that the events are Send to tag manager also.

    Now i would like to know, how can i push those events from Google tag manager to Google analytics? Can someone provide me insights into configuring tags and triggers on Tag manger and Google analytics

    My Android code for logging events is as below

     public void logEventClicked(View view){
        Toast.makeText(this, "Logging event", Toast.LENGTH_SHORT).show();
        Bundle bundle = new Bundle();
        bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "150");
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_TO_CART, bundle);

    Related posts:

    How to get information about android battery usage by application
    how to resume an interrupted download - part 2
    Android DownloadManager API - opening file after download?
    Use GPS and Network Provider at the same time in Android
    Intermittent 401 Unauthorized from Google GCM
    Android: is there an easy way to find all the Strings in my project?
  • aapt.exe has stopped working in eclipse 4.3 kepler SDK 22.3 API level 19
  • Multiple PlaceAutoCompleteFragment opens when clicked on it very quickly
  • Rendering Problems Exception
  • How can i get the application's icon from the package name?
  • How to get the graphical layout Window back in Eclipse for Android Application Design?
  • How to play an android notification sound
  • 2 Solutions collect form web for “Android – Google tag Manager with Google Analytics and Firebase Analytics”

    Well, I got all this information from AndroidStuff Blog written by @DavidMedenjak in any case this link got expired I am posting some extract and Images from his blog….

    how can i push those events from Google tag manager to Google analytics? Can someone provide me insights into configuring tags and triggers on Tag manger and Google analytics

    • In your Tag Manager Console open your container and click to add a new tag, either by selecting the option on the dashboard or the tag menu entry. The product to use is Google Analytics and after selecting it you will be prompted for your Tracking ID. Select the button to the right and choose to create a new variable. It is a good idea to have your Tracking ID as a constant value.

    enter image description here

    • Since having screen views without the actual name of the screen does not make too much sense, we will have to include the name as well. Select More Settings – Fields to Set and add a new field. screenName is the value to use with Google Analytics, I’ll explain the variable used next. I chose to name my tag Screen Tracking. Your setup should look something like this:

    enter image description here

    {{Item Name}} is another variable like the Tracking ID Constant created before. It makes use of the data layer where Firebase pushes its events. In my case I decided to use Firebase like this to track my home screen:

        Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "home");
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle);

    This will send a view_item event with a parameter item_name containing the screen name to Firebase. If you want to track different events and parameters you have to use those event and parameter names respectively. So to track my screens with the code shown above I’m going to use the keys view_item and item_name.

    • I create a new variable in Tag Manager, name it Item Name and select that it should have the value of item_name. With this I can access the parameter value and send the correct screen name to Google Analytics.

    enter image description here

    configure my tag manager account to Push firebase events to Google analytics.

    • Now, all that’s left to finish our tracking is to set up a trigger. Triggers define when your tag fires. For the purpose of tracking your Firebase Events to Google Analytics as well you should choose a trigger that fires every time a specific event occurs.

    Here I use Event Name which is a predefined variable to fire this tag every time a new view_item event gets pushed to the data layer.

    enter image description here

    • With this trigger the setup is complete. Every time a view_item event occurs, Tag Manager will fire this tag. It will take the value out of item_name and send it as a screen view to Google Analytics.

    enter image description here

    That’s it! What you want to do now is publish your container, download it and add it to your project. If you did get something wrong, don’t worry. You can just edit and publish a new version—Tag Manager will update itself within 24 hours.

    Note: Google Analytics tracking can still be configured afterwards without changing any of your code.

    Hope this helps!!!

    Ok. I was quite confused for the first time. I will answer to my question in a more simple way. Please refer to images from the first answer for a better idea.

    Objective: Push events from mobile app to both Firebase and Google Analytics (GA)

    In my question i have asked, how to copy the events from FA to GA using tagmanager.

    My event > Firebase > Google tag manager > Google analytics

    I am changing this as follows. Because this is how it works. Only thing is GTM and FA are connected internally so that you only need to logEvent using FA and it will be captured by GTM, just by adding the dependency in Gradle(V5+).

    My event > Firebase

    My event > Google tag manager > Google analytics

    I will explain few basic terms in GTM to get started.

    • Event Parameter – Variables that will be used to extract data from
      Key-Value params send from app
    • Constants – Similar to variables. Values will be constant as defined
      on dashboard
    • Trigger – Trigger is used to fire a tag when a FA event is logged
      from app
    • Tags – Tag carries data and is pushed from GTM to GA so that an event is logged on GA

    The logic is simple. We need to create a Trigger which will push a Tag to GA. To carry the data from GTM we use an Event parameter variable.

    Follow the below link to learn how to log a FA event.

    Follow below link to learn how to use GTM with Firebase.

    Say, i want to log an event as below.

    bundle.putString(“button_click”, “Login button”);
    mFirebaseAnalytics.logEvent(“user_interactions”, bundle);

    Essentially we are sending 3 data items from app.

    • Event parameter – button_click
    • Event parameter value – Login button
    • Event name – user_interactions

    Now, to capture the above data and push to GA we create variables/Tags/Triggers as follows.

    Button click variable – Create a new Variable of type Firebase > Event parameter. Set value to Custom parameter. Value as “button_click”

    Button click trigger – Create a new trigger and set the trigger to fire on Event = “user_interactions”

    Button click tag – Create a tag with Universal analytics(GA) as tag type. Because we are going to push this to GA. Inside the Tag configuration, choose Track type as Event, and now you can set Category/Label/Action/Value etc here. Remember that Category and Action are mandatory. Click the icon next to Action field and choose the button_click event parameter variable. This will pass the value matching key = button_click. Set this tag to fire on above trigger. Check the “Enable overriding settings” option and set you Google analytics key here.

    Now save your configurations and publish the container. Download and copy the container to app and run your app.

    When you log an event in app, typically event will log in your GA console in Realtime tab within one or two minutes. If you have configured it correctly, when the app is running, it will show number of active users as greater that 0. Note that you don’t need to enable debug mode. But it’s always good to ensure that events are logged on Firebase console.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.