Wednesday, November 20, 2013

Why Hour of Visit is an important metric? How to track it using Google Tag Manger in Google Universal Analytics?

Last week I have written an introductory post on Google Tag Manager explaining how to implement Google Universal Analytics using Google Tag Manager. You might have observed how easy it is to implement the Google UA base code with GTM. It's just a simple plug and play operation. But that's not our whole aim, isn't it? We need to understand what kind of Key Performance Indicators (KPIs) are we looking for considering the website on which we need to implement the tool and there by come up with perfect Metrics which can be translated into our needed KPIs. This is the whole purpose having a Web Analytics tool at place, to understand the most needed KPIs and how they are being affected by different things.

So, let us consider one such KPI in our present post and simultaneously let's see how to implement them using Google Tag Manager and what all configuration needed to be done on Google UA.

Most of the web is filled up with Content based websites. For example, my blog comes under such category. I just write some posts related to Web Analytics. So, what am I interested in? What patterns am I looking for? How much can I change my marketing pattern or writing pattern?

Since my site is hosted on blogger, I am fortunate to have some basic statistics provided by Blogger's in-built Stats dashboard. There I have a small graph which shows number of page views my site is getting each minute cleanly. I generally write posts during mid night Indian time, once I am done with the post, I post the link in couple of places so that I can get some traffic to the blog. But last week I broke that pattern and I wrote a post on Tealium in the morning Indian time and tell me about bad timing, on Saturday. Since I have written the post already I couldn't resist myself from posting the link to different places where I generally post the link. I have spent almost 4 to 5 hours in writing the post and a day preparation for what should be written and with my timing I have received almost no visitors to the post on Saturday and Sunday. I was very disappointed with that result and went to bed on Monday night (Indian Time). And then the magic started, I started receiving number of visits from US and Europe (Most of the visitors to my blog are from US, Europe and India) from Yahoo forums and people started retweeting the post and Tealium has published my article on their blog by the morning I woke up on Tuesday. Good number of visitors have come to my site and some of them liked the post on Facebook, some of them tweeted and some of them shared it on Google plus and LinkedIn making it more reachable via Social media.

So what is the moral of the story? Even if you write great content, if you don't understand people's pattern and how to market your content it will go waste. If I had written the post during a week day and posted it on couple of forums the post would have gotten a very different exposure. So the timing is a very important thing in content based websites. So what exactly is Hour of Visit and what is it's importance? Nothing fancy. Its pretty straightforward. It's the hour in which a user has come to your site. It's important to track this because you will get an understanding about your visitors, when they are visiting your site on what day so that you can write your posts on the day and hour which will give you exciting results.

How to track Hour of Visit using JavaScript?
It's pretty easy to track the hour of visit using JavaScript but there is a small thing we need to observe here. You would be interested to know the hour of visit with respect to your timezone but not the visitor's isn't it? So how to track the hour of visit for the timezone you want? Thanks to Nilesh for his blog post on getting the time in particular timezone using JavaScript. Here is the code for that

 var dte = new Date();
 dte.setTime(dte.getTime() +(dte.getTimezoneOffset()+330)*60*1000);
 return dte.getHours();

If you want to understand the code clearly, I would recommend you to go through the above blog post or google the various functions used.

Where do you paste this code in GTM?
Now that you have the code with you, open your container in Google Tag Manager and create a new macro with type "Custom JavaScript" and name it as you like and paste the above code into the code box.

What variables need to be used in Google Universal Analytics?
That's fine, you have created a macro which returns your required hour of visit but where will you pass this data into in Google Universal Analytics? In UA we have something called Custom Dimensions which you can use to track different variables. Explanation of Google Universal Analytics' Custom Dimensions will take an entire post which I will cover later. For now, we can define a new custom dimension in UA as shown in the below picture. Depending upon your requirement you can select the scope of the custom dimension. I am going to assign the scope as Session for the Hour of visit. The reason behind this is, I want to know the first hour of visit when the user has come to the site which will be accomplished if I select the scope as Session.

You can also create a new custom report keeping the above defined Hour of Visit as the primary dimension with other dimensions under drill downs as shown in the picture below.

How to implement using Google Tag Manager?
Everything is fine so far but still we haven't connected the macro we have created to the Custom dimension we have created on UA. This is where GTM makes our life very easy. You remember the Base Tag implementation we have done for UA using GTM previously? Open that tag and go to the advanced settings, you should see Custom Dimensions which you can expand and enter the index of the custom dimension and in the place of value you can select the macro you have created previously. Take a look at the picture below to get more clarity.

Now save the tag and create a new version and publish it in GTM. Once it is published you should see the custom dimension with the value populating inside it as below.

If you had faced any such situations where you felt something or some metric you feel gives you a pattern of users and you have implemented it for your blog, please do feel free to comment below :)

No comments :

Post a Comment