Android - Google tag Manager with Google Analytics and Firebase Analytics Android - Google tag Manager with Google Analytics and Firebase Analytics android android

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 fromKey-Value params send from app
  • Constants - Similar to variables. Values will be constant as definedon dashboard
  • Trigger - Trigger is used to fire a tag when a FA event is loggedfrom 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.https://firebase.google.com/docs/analytics/android/start/

Follow below link to learn how to use GTM with Firebase.https://developers.google.com/tag-manager/ios/v5/

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.