Outstanding Paragon of Google Tag Manager Part 1

Google Tag Manager
It’s already been a couple of years since the new Google Tag Manager (GTM) was introduced. And everyday, I am finding and learning new things that do not cease to amaze me. Though Custom HTML tags solve almost anything for us, but we tend to feel secure when it is done via GTM itself.

This topic is pretty vast and just one blog post wouldn’t do justice to it. Which is why I’ll be coming up with a series of 3 blogs that shall cover the major topics falling under Universal Analytics (UA) implementation. We are missing out on many awesome features that GTM provides to ease out the implementation of UA. There are many features (like JavaScript Error Tracking, Fields to Set, Lookup Table variable, Auto Event variable, History change triggers and variables, Environment feature) that we at Tatvic use for GTM implementations and solutions. Let us explore these features one by one.

  • Fields to set parameters

Most of us have used this feature which falls under the Universal Analytics tag configuration. This feature leverages us to use all configurable fields name which are listed under this link. We can set almost every field listed in that list with just “&fieldName” and give it a value. For example, You want to modify the document title to some custom value. You can simply use “&dt” equals to “titlevalue”. Do make sure that you have assignment value available when you are using “&fieldName” as GTM will enforce it to pass it with hit. If you do not have value assigned then it will be passed as null/undefined. I have been using it for the following:

      • To set virtual pageviews
      • To set up userId
      • For setting up cookieDomain as auto or
      • For setting up the campaign parameters which are listed for Universal Analytics implementation for different projects.

In my experience of working with GTM, I have found some unexplored parameters which can be useful.

      • hitCallback
        This field executes operation after the tag fires successfully regardless of whether it is sent successfully or has failed. We can also achieve via tag scheduling as well. But tag scheduling does not wait for the first tag to complete the execution. So if your solution is interdependent that you can use hitCallBack.

          • Fetch ClientId from “_ga” cookie after pageview tag fires. This cookie will be set with the first pageview itself

        For example, you can create custom javascript variable which will store client id in the cookie variable called “tvc_clientid” with below code. You can use it in any tag you want.
        Custom HTML Tags

        Image: hitcallback image

        function() {
           //before this, create 1st party javascript variable named 'tvc_clientid'
           if (!{{tvc_clientid}}) {
              try {
                if (window.ga || window._ga){
                    var tvc_trackers = ga.getAll();
                    var tvc_i, tvc_len;
                    for (tvc_i = 0, tvc_len = tvc_trackers.length; tvc_i < tvc_len; tvc_i += 1) {
                      if (tvc_trackers[tvc_i].get('trackingId') === {{your_UA_id}}) {
                        tvc_visitorID = tvc_trackers[tvc_i].get('clientId');
                    var tvc_d = new Date();
                    var expires = "expires="+tvc_d.toGMTString();
                    document.cookie = "tvc_clientid="+tvc_visitorID+"; "+expires+"; path=/;";
              }catch(e) {  
        Code: Create custom javascript variable from this code. And assign it to hitcallback in pageview tag
          • Fetch ClientId from “_ga” cookie after pageview tag fires. This cookie will be set with the first pageview itself
          • Restrict transaction tag (Enhanced Ecommerce) to fire multiple times: Simo’s solution
          • Use Case: push dataLayer/execute client side script when user performs specific action on website using custom javascript variable

        Javascript error tracking
        Image: fields to set, sessionControl, cookieName

      • sessionControl
        A lot of the times we want to start and stop sessions for data cleanliness likein some cases where website is accessed by single machines but users are different every time. A classic example would be food ordering systems in coffee shops. sessionControl variable takes only 2 values “start” and “end”. As per the values, Google Analytics will start new session or stop the ongoing session respectively. It is very likely that we can use this for gathering data for different analysis.

        • Website accessed through Single machine, used by multiple users
        • New session of every transaction/specific action performed by user
      • cookieName
        Default name of analytics cookie is “_ga” but in many cases (when multiple UA codes are implemented ) we want to separate our implementation of tag manager with others. That’s when we can change the cookie name of UA. When you use this field, you can modify the cookie name and which ever tag contains that field set, data will be sent to Google Analytics by referring to the newer cookieName.
  • Tag scheduling

Now, if i want to fire my tag first, in multiple tags firing in a race, I will use Tag firing priority whereas if I want to apply sequencing of tags, I will use Tag Sequencing. But can I restrict my tag to fire in the morning time only or can I fire these tags during a specific time. Well, yes of course I can. Let’s find out how.
Tag scheduling is one of the lesser known features and when we started using it, we realised the efficiency and the use cases have only increased since then.
 Universal Analytics Implementation

Image: tag scheduling

So far we have only covered a couple of features in this blog, GTM has many other unexplored features and it is not possible to accommodate all of them into one single blog. So we would be coming with a series of blogs regarding these features’ explanation and usages. In the upcoming blogs, we will cover auto event variable, tracker name and global function name configurations, history change triggers and variables.

In the meantime, if you have any questions, please feel free to comment. We would love to answer your queries.

, , , , , ,
Previous Post
Importance of Heat Maps Part 2: Know the Fascinating Insights Tatvic Got from Heat Map Integration
Next Post
Track Progressive Web Apps with Google Analytics and Google Tag Manager

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