Extension for timestamp

Bronze Contributor
Bronze Contributor

Hi Comunity Members,

I am new in Tealium system but previously used GTM here i wanted to implement timezone JS which i will use with my existing GA (Google Analytics tag) to capture timestamp on every interaction on the website with their local timezone converted time as my org is having a presence in 33 countries.

Any idea how to start creating a custom extension of timestamp with JS script below:

function() {
// Get local time as ISO string with offset at the end
var now = new Date();
var tzo = -now.getTimezoneOffset();
var dif = tzo >= 0 ? '+' : '-';
var pad = function(num) {
var norm = Math.abs(Math.floor(num));
return (norm < 10 ? '0' : '') + norm;
};
return now.getFullYear()
+ '-' + pad(now.getMonth()+1)
+ '-' + pad(now.getDate())
+ 'T' + pad(now.getHours())
+ ':' + pad(now.getMinutes())
+ ':' + pad(now.getSeconds())
+ '.' + pad(now.getMilliseconds())
+ dif + pad(tzo / 60)
+ ':' + pad(tzo % 60);
}

Thanks in advance,

Nandan

 

 

3 REPLIES 3

Extension for timestamp

Tealium Employee

Hi @nandgupta

So I would change the code slightly to :

b.local_time = (function() {
  // Get local time as ISO string with offset at the end
  var now = new Date();
  var tzo = -now.getTimezoneOffset();
  var dif = tzo >= 0 ? '+' : '-';
  var pad = function(num) {
    var norm = Math.abs(Math.floor(num));
    return (norm < 10 ? '0' : '') + norm;
  };
  return now.getFullYear()
    + '-' + pad(now.getMonth()+1)
    + '-' + pad(now.getDate())
    + 'T' + pad(now.getHours())
    + ':' + pad(now.getMinutes())
    + ':' + pad(now.getSeconds())
    + '.' + pad(now.getMilliseconds())
    + dif + pad(tzo / 60)
    + ':' + pad(tzo % 60);
}());

 

This then can go into a JS Extension, with before load rules set:

localtime2018-02-07_1557.png

Then you would create a UDO variable called, local_time, which then you could map to any tag you wanted to pass through.

localtime2018-02-07_1558.png

Adrian

Ask me anything Tealium related or TypeScript/JavaScript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.

Extension for timestamp

Bronze Contributor
Bronze Contributor

Hi @adrian_browning,

 

Super useful much appreciated.

 

Thanks,

 

Extension for timestamp

Gold Contributor
Gold Contributor
Hello @adrian_browning,

Excellent detailed elucidation along with screenshot to understand precisely.
Public