Skip to content

Instantly share code, notes, and snippets.

@jsn789
Last active April 9, 2018 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsn789/4072b78240060141290b815a701702c4 to your computer and use it in GitHub Desktop.
Save jsn789/4072b78240060141290b815a701702c4 to your computer and use it in GitHub Desktop.
GTM Custom JavaScript - Hit Timestamp used for a Custom Dimension
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment