Published October 1st, 2015 by Assaf Trafikant
Identifying User’s Local Time Using Google Tag Manager
I love the following report and the priceless knowledge behind it, and it was thanks to a question someone asked me that I realized I could also make it into an informative article. The technique has been around for a while now and can be executed in different ways, but it’s a whole lot simpler for those who use Google Tag Manager.
It all started with a question on one of my forums:
Is the time of visit, we see in Google Analytics is the user’s local time or the time to which the account is set?
“The account’s,” I answered. If a user from the UK and a user from Israel visit the website at the same time, the hour’s report will show both visits occurred at the same time of day, even though the local time for each user is different (2-3 hours gap, in this case, depending on daylight savings).
But wait, if they’re both registered under the same time, what time would that be?
Answer: It depends on the account settings! If your account is set to Jerusalem time, and both users visited the site at 9 AM Jerusalem time, that’s the time we’ll see for both, even though it was 6 AM for the English visitor.
Another example:
A user from Russia visits the website at 1 AM (Moscow Time) and converts; a user from London visits the website at 1 AM (his local time) and converts. Google will register them as the time set in your account. If your account is set to Jerusalem time, then the London conversion would be logged as a 4 AM conversion, and the Moscow one would be logged as a 12 AM conversion. The way Google displays it, there’s allegedly a 4-hour gap between the two conversions.
By the way, if you’re focused on a few markets, you might consider creating a dedicated view for each one of them, with the right time zone settings. My solution aimed for international websites.
My Solution
If you have a global website with visitors from around the world, then clearly the ‘hour’ dimension presented by Google Analytics is almost entirely meaningless. For every website like that, I implement the users’ local time in Google Analytics and get these results, for example:
The first column shows the time as Google Analytics sees it. That’s the built-in Hour dimension which is not too practical for international websites. The third column shows the local time (I’ll teach you how doing it in just a minute).
I took it a step further, and so the fourth column shows the local part of the day at which the visit occurred, according to the user’s local time:
As you can see in my Local Part of Day column, my peak sessions take place between 1 AM and 6 AM (visitors’ local time), and the column disregards their location. If I wanted to know what my site’s peak hours were, there’s my answer. If I wanted to know in what part of the day has the most conversions, that’s my answer. This column, Local Part of Day, doesn’t exist in Google Analytics, and I’m going to show you how you can create it.
Using local time normalizes all visitors on a single timeline, and allows you (among other things) to efficiently target campaigns in different countries.
How It’s Done
Create two custom dimensions. One for “Local Hour” and one for “Local Day Part“. Both should have ‘Session’ scope. Remember their index number.
In Google Tag Manager, create a new Custom JavaScript variable called “Fetch Local Hour”, with the following code:
function test(string) {
ourTime = new Date() ;
return ourTime.getHours() ;
}
Create another Custom JavaScript variable called “Local Day Part”, with the following code:
function (string){
var currentHour = (new Date()).getHours();
if (currentHour === 0){
return "Late Night (23-1)";}
if (currentHour < 6){
return "Over Night (1-6)";}
if (currentHour < 9){
return "Early Morning (6-9)";}
if (currentHour < 12){
return "Late Morning (9-12)";}
if (currentHour < 17){
return "Afternoon (12-17)";}
if (currentHour < 20){
return "Early Fringe (17-20)";}
if (currentHour < 23){
return "Late Fring (20-23)";}
if (currentHour ===23){
return "Late Night (23-1)";}
}
Now, go to your Google Analytics tag, and under “More Settings”, open the Custom Dimensions section, add two custom dimensions with the indexes 1,2:
Now, push the relevant variable to the right custom dimension index number:
Save the tag, debug and publish the container.
Now, when you create reports, you can use your new dimensions “local hour” and “local day part”. That’s it.