Skip to content
Tips & tricks

How to send the visitor's local time to GA4 with GTM

Find out how to send your users' local time to Google Analytics with a simple JavaScript variable in Google Tag Manager.

Alexis Neve 2 min read

Why GA4 does not show your users' real time

By default, GA4 records all data according to your property's time zone. While this logic works for a single market, it skews the analysis of an international site: a conversions peak recorded at 2am can match 8pm for your visitors on the other side of the world. The buying behaviors of each country then pile up on a single chart, which makes it impossible to identify at what time of day your visitors really convert.

The principle: capture the time at the browser level

The method consists in reading the time from the user's browser. A variable in GTM extracts it, then passes it to GA4 as a custom parameter (to keep both times).

Tutorial: set up the local time in Google Tag Manager

Step 1: Create the custom JavaScript variable

In GTM, go to Variables > User-Defined Variables > New, choose the Custom JavaScript type, name it JS - Visitor local hour then paste the following script:

function() {
  return ('0' + new Date().getHours()).slice(-2);
}

The getHours() function extracts the hour of the device (0 to 23).

Step 2: Link the parameter to the Google tag

In your Google tag (or your GA4 event tags), open the Configuration settings section. Add the visitor_local_hour parameter with the value {{JS - Visitor local hour}}. Every event sent will now carry the visitor's local time.

Step 3: Register the custom dimension

To use this data in your reports, register the parameter in GA4:

  1. Go to Admin > Data display > Custom definitions.
  2. Click Create custom dimension.
  3. Name it "Visitor local hour", set the scope to Event and select the visitor_local_hour parameter.

Step 4: Check in DebugView

Turn on GTM's Preview mode and open DebugView in GA4. Trigger an event on your site, then check that the visitor_local_hour parameter returns the right value.

How to use the local time in your Google Analytics reports

In the Explore menu (Free form format), put the Visitor local hour dimension in rows, your key events (conversions) in values and the country in columns. This cross view lets you identify the real peak hours by market, to optimize for example the timing of your email campaigns, your follow-ups and the availability of your customer support.

Tools

  • Google Tag Manager: Custom JavaScript variable, Preview mode.
  • Google Analytics 4: custom dimension, explorations, DebugView.

This variable is part of the tracking expertise, together with GTM setup, the data layer and GA4 custom dimensions.

Ready to take action?

Tell me about your site and your Ads platforms: you get a clear answer within 48 hours.

Get a quote