Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I followed the below guide to integrate Google tag manager and Firebase analytics to my application.

https://developers.google.com/tag-manager/android/v5/

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);
}
like image 817
Ajith Memana Avatar asked Mar 30 '17 18:03

Ajith Memana


People also ask

Can you use Google Tag Manager and Google Analytics together?

Google Tag Manager and Google Analytics are two completely separate tools, and can live independently of one another: You can use Google Analytics on your site by itself, just as much as you can use Google Tag Manager on your site by itself.

Do you need Google Analytics and Google Tag Manager?

Without Google Tag Manager, Google Analytics may be used. Without Google Analytics, Google Tag Manager may be used. To use both in conjunction, each must be configured independently. Both are implemented similarly on your website, utilizing javascript code snippets.

How do I integrate Google Analytics into an Android app?

Go to Analytics and select the Analytics account you registered the app with. If you're unsure, look for the Analytics tracking ID in the google-services. json file you added to your project earlier. Copy that ID to the Analytics account search in the report drop-down.


2 Answers

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!!!

like image 161
2 revs Avatar answered Sep 22 '22 07:09

2 revs


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. 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.

like image 29
Ajith Memana Avatar answered Sep 18 '22 07:09

Ajith Memana