Reply
Highlighted
Visitor
Posts: 2
Registered: ‎10-12-2017

Extension for timestamp

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

 

 

Reply
0 Kudos
Tealium Employee
Posts: 382
Registered: ‎09-01-2015

Re: Extension for timestamp

[ Edited ]

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 Javascript, or NodeJS. But not cooking, can't do that.
Please remember to mark solutions as accepted for future searchers.
Visitor
Posts: 2
Registered: ‎10-12-2017

Re: Extension for timestamp

Hi @adrian_browning,

 

Super useful much appreciated.

 

Thanks,

 

Super Contributor
Posts: 161
Registered: ‎11-15-2015

Re: Extension for timestamp

Hello @adrian_browning,

Excellent detailed elucidation along with screenshot to understand precisely.