Hi, I need to send a timezone-specific hit with every event that I am passing to Google Analytics. Specifically, the function is: // 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;
};
utag.data['ga_hit_timestamp'] = 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 is too complicated to set with JS code within the 'Set data values' extension, and since this needs to trigger on e.g. page loads, clicks, and potentially others, using a single jQuery onHandler extension will not cover all cases. I though about using a JS code extension to set the above to a globally scoped function, and pass that function within 'Set data values' extension. Would this be possible? Something like the image below? Otherwise, what would be the best practice way of achieving this? Within Google Tag Manager (we are migrating to Tealium), this function can be used anywhere the token {{timestamp}} is declared, since the variable is set with custom HTML (the function) as soon as it is declared. I am trying to replicate this functionality.
... View more