Time-based load rules are useful when you want to load a tag in a specific timezone. By default, the timezone is determined from the local time set in the visitor's browser, and not the server or visitor’s time/time zone. If you want to create a load rule based on UTC you must retrieve the browser’s local time and convert it to the UTC format using a new set of data layer variables.

This article assumes that you are familiar with load rules and how to set up time-based load rules.

Converting Local Time to UTC

  1. Add the following UTC date and time variables to your data layer tab using the Bulk Import tool.
    datetime_year_utc, "UDO Variable",, "Will output a number. ex: 2015"
    datetime_month_utc, "UDO Variable",, "Will output a number. ex: 5"
    datetime_day_utc, "UDO Variable",, "Will output a number. ex: 7"
    datetime_day_string_utc, "UDO Variable", "Will output a string. ex: Fri"
    datetime_hour_utc, "UDO Variable",, "Will output a number in military time. ex: 23"
    datetime_minute_utc, "UDO Variable",, "Will output a number. ex: 57"
    datetime_second_utc, "UDO Variable",, "Will output a number. ex: 7"
    datetime_epoch_utc, "UDO Variable",, "Will output a Unix timestamp. ex: 1431057424923"
    datetime_string_utc, "UDO Variable",, "Will output a string. ex: 2015-05-08 03:57:04 UTC"
  2. Add a new JavaScript Code Extension and scope it to Preloader.
  3. Copy and paste the following code into the editor. This code will capture the date and time from the visitor’s browser, convert it to UTC format, and store in your new data layer variables.
    (function(d,y,m,da,dn,h,mi,s,ep,padL,days){
      padL=function(str,len,char){
        return (new Array((len||1)+1).join(char||0)+(str||'')).slice(-(len||2))
      }
      window.utag_data=window.utag_data||{}
      days="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_");
      d=new Date();
      y=d.getUTCFullYear();
      m=d.getUTCMonth()+1;
      da=d.getUTCDate();
      dn=days[d.getUTCDay()];
      h=d.getUTCHours();
      mi=d.getUTCMinutes();
      s=d.getUTCSeconds();
      ep=d.getTime();
      utag_data.datetime_year_utc=y;
      utag_data.datetime_month_utc=m;
      utag_data.datetime_day_utc=da;
      utag_data.datetime_day_string_utc=dn;
      utag_data.datetime_hour_utc=h;
      utag_data.datetime_minute_utc=mi;
      utag_data.datetime_second_utc=s;
      utag_data.datetime_epoch_utc=ep;
      utag_data.datetime_string_utc=y+"-"+padL(m)+"-"+padL(da)+" "+padL(h)+":"+padL(mi)+":"+padL(s)+" UTC";
    })();
    

That's it! You can now use these new variables to create load rules based on UTC time.

Additional Resources:

 

Version history
Revision #:
11 of 11
Last update:
‎11-22-2019 09:27 AM
Updated by: