Material-Design-Lite tab tracking - google-analytics

I am attempting to use material design lite to code a landing page. I want to use tabs to separate content. Can I track the clicks on the tabs through Google tag manager? It seems as if all the events that fire when changing tabs are identical.

The original question specified that you wanted to use Google Tag Manager. To do this in Google Tag Manager you would just push an event onto the GTM dataLayer every time a tab is clicked. To differentiate between different tabs, you would push an extra key onto the dataLayer with the name of the tab.
An example might be:
dataLayer.push({'event' : 'tabSelected', 'tabName' : 'tabA'});
Then, in the Google Tag Manager interface, you would setup a Universal Analytics tag with track type "event" and you would pass the value of the tabName key to the label attribute of the GA event. The trigger of this tag would be a Custom Even trigger whose value is tabSelected.

Related

Tracking ID missing or not displaying in Google Analytics

When I open https://analytics.google.com/ and go to Admin section, I can't find "Tracking Id"
Notice that under the property items, <> Tracking Info is missing (see the attached image) We should have Tracking info section, which is missing.
How can I generate the Tracking Info or ID that starts with UA-
Google Analytics now defaults to creating a GA4 Property.
If you need to create a Universal Property, with a UA-XXXX-X format tracking id..
Start by creating a new property.
When you are creating that new Property, on the Property setup page, click on the blue link towards bottom of screen Show advanced options, that will then open up the section in the screenshot below so you can toggle on the option for a Universal property
It gives you the option of creating both property types or just a Universal Analytics property only.
Select to create just a universal property (you will be able to upgrade it to GA4 at a later date should you choose to).
If you have accidently created and do not want a GA4 Property, from the GA Admin page select the Property as you would any other property from the Property dropdown and then select it's Property Settings page and at the upper right, click the Send to Trash option to delete it.
In Universal Analytics just click on Tracking Info and then on Tracking code:
If you have display problems try refreshing the page or clearing your cookies and try again.
In Google Analytics 4 you have to click on Data Streams and then click on the data stream desired. You will find it under MEASUREMENT ID:

Execute Google Analytics Functions in addition to Google Tag Manager

When using the Google Tag Manager, is it possible to track some things the old way in addition to using the GTM?
For example, I use GTM in order to fire a page view.
However, I want to fire another page view, when a user clicks a button, also known as a virtual page view.
The button in question doesn't have an ID and I don't trust the othet agency, which handles these buttons to consistently keep the same IDs for these elements. So I would rather have them be responsible for these types of page views.
The code for the virtual page view would look something like that:
ga('send', {
hitType: 'pageview',
page: 'button2'
});
Since the tracker is already initialized by GTM, I would only have this code outside GTM.
Would this work if all other google analytics related things run over gtm and where should I put this code in this case? Somewhere after the GTM code on the page I'd imagine?
Google Tag Manager (GTM) by default uses a random name for each tracker, generated for each Universal Analytics tag. There is a possibility to use fixed name for trackers, which is highly discouraged. This means, that you might have difficulties to identify the proper tracker to use, when sending your additional pageview data.
There are however other methods to send virtual pageviews using GTM, where you can benefit from your existing Analytics settings, defined in Google Tag Manager. (Preferably by using Google Analyitcs Settings variable.)
As far as I understand, you have control over the code, to run some JavaScript on the relevant click event.
So instead of directly invoking the ga object, you can send the desired data to GTM, with a call like this:
dataLayer.push({
event : 'virtualPageView',
virtualPagePath : 'button2'
});
Obviously, there are a couple of things you need to set up in GTM, which will be able to act on this event, and send the pageview to Google Analytics.
Create a variable that points to virtualPagePath dataLayer variable, so the newly pushed value could be reused
Create a custom event trigger, that can be used with one or more tags. The event name should match your given event name, virtualPageView in my example.
You need an Universal Analytics tag, which will send the pageview. This tag should be fired by your new custom event trigger, and should have an extra setting compared to your regular pageview tag. Namely, page variable within the Fields to set block should point to the newly created dataLayer variable, that contains your virtual page path.
This way, Google Tag Manager will take care of creating the tracker for you, sending the hit to Google Analytics, and using the virtual page path variable provided by you, instead of the URL in the browser address bar.

Can I use same GTM tag to fire for multiple GA accounts?

I am working on one project which needs to fire same GTM tag to for two different GA account is this possible? or should I have duplicate all the same tags for two GA accounts?
There is no standard way to fire multiple properties in one tag. However I can think of two possible workarounds.
(Updated: The same questions came up on the GTM forum and naturally Simo Ahava had a solution).
One would be to create the tracker object manually in a custom html tag (the actual pageviews happen still via Ga tag templates). This would allow you to use Google Analytics plugins and there are plugins (e.g. here or here) that send hits to multiple properties.
The other workaround is to use a feature called tag sequencing. This has the advantage that you do it with "pure" GTM instead of GA plugins. I will first show the steps and explain what happens later.
The Setup
First you need to set up your tracking id as a variable of the datalayer type. As default value you set your first tracking id:
Next you create a custom html tag that will later set the second tracker id. This also sets a custom event necessary to fire the second tracker. Note that there are no triggers attached to this tag, and that it is set to "fire only once per page" (the last thing is very important! You can set this in Advanced Settings -> Tag firing options).
Then you create a trigger that uses the custom event from the previous step:
Now comes the magic with the GA tag. You use the variable for the tracking id that you have created earlier. Then you go to "Advanced Settings", expand the "Tag Sequencing" options and check the mark before "fire a tag after fires". You select the custom html tag from above (named set2ndId in my example). Then you attach a pageview trigger and the custom event trigger (called 2ndTracker in my example).
The sequence
GTM is loaded and evaluates the tracker id from the default value of the datalayer variable
The pageview trigger fires the GA tag
The tag sequencing setting fires the custom html tag that sets the datalayer variables for event and tracking ind
Since we have an event the datalayer is re-evaluated, and the new value with the second tracker id from the custom html tag is set
The custom event trigger fires the GA tag with the second tracker id
Since the custom html tag was set to "fire once per page" it is not fired again (else you would end up in a loop)
A word of caution: This is somewhat clever, even if I say so myself, but at the moment it is a bit "proof of concept". I use it without problems for pageview tracking, but I'm still working the kinks out for event tracking etc, so you have to decide for yourself if this is useful for you.
But at least it answers your question: yes, it is possible to send to multiple properties without duplicating the GA tags, but it takes some additional setup so you have to decide if this actually saves you work.
yes it is fine to fire multiple GA properties in single GTM.
Maybe this tutorial will help you:
http://www.kristaseiden.com/step-by-step-adding-a-second-ga-property-via-google-tag-manager/
I hope this helps.

Google tag manager custom event tracking

I am a developer in codiva.io a java ide for students. I am using codemirror editor.
I want to track on edits (specifically a pause or timeout after last edit).
I had previously used Google analytics, and for events, we will do ga.send(). Now I'm using Google tag manager, for clicks and other events it seems we can configure using tag manager ui itself.
With tag manager, I'm not able to find how implement tracking for this.
Codemirror generates an on change event. On each edit, clear any previous timer and setup a timeout trigger to run after 200ms. (The compilation will be dive at this point, and I want to make sure to track the number of times this event happened)
If I understand you correctly:
Use you change event to have a custom event pushed to the dataLayer:
dataLayer.push({event:'compile'});
Then create a trigger of the type "custom event", set event name to "compile" and use that to fire a Google Analytics event tracking tag (if you use the GA tag template you can select the hit type via a dropdown).
The "push" method of the dataLayer ist not the native array method but a special implementation by the GTM code; GTM uses this to monitor changes to the dataLayer, and the "event" keyword tells GTM to update its internal datastructure so new values become available to tags and triggers.
With the same push you can also pass data to be used as eventCategory etc:
dataLayer.push({
event:'compile',
eventCategory:'myCategory',
eventAction:'myAction',
....
});
You then create new variables of the "dataLayer" type and enter the name of the key you want to access. You can then use the variable in your Ga tag, either by selecting it from the autosuggest list (if you click the icon right to the eventCategory etc. fields) or by typing out the variable name with curly brackets, i.e {{myVariableName}}.
Also keep in mind that the "event" keyword in the dataLayer does not relate to Google Analytics events, except in the sense that it can be used to trigger event tracking (as well as any other tag). "Event" is just a keyword in GTM to indicate that data is updated and tags can now access the new data.

How to trigger an event tag when a user leaves a page?

In Google Tag Manager, I'm tracking the pageScrollDepth variable.
I want to trigger a Google Analytics event Tag that pushes (as custom metrics) the recent value of pageScrollDepth just before the user leaves the page.
How can I create the leavingPage trigger?
http://www.blastam.com/blog/index.php/2014/04/scroll-depth-tracking-analysis-google-analytics
^ The code in this blog post is the one that your are looking for where it takes the last scroll depth before the user leaves to another page. You will find a link to bitbucket to download the code
Paste the code in a Custom HTML tag and then create a JS variable to call the "callbackData.scrollPercent" for the Event Label

Resources