- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
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
02-07-2018 08:02 AM - edited 02-08-2018 02:12 AM
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:
Then you would create a UDO variable called, local_time, which then you could map to any tag you wanted to pass through.
Adrian
Copyright All Rights Reserved © 2008-2023