Harry
Harry

Reputation: 61

Is there a timestamp feature in GTM event data?

I'm creating an event data via GTM, and typically if it's sent to GA the timezone will follow the GA timezone but if I sent it to a different endpoint how do I capture the timestamp for the GTM event? Would I have to populate it in the dataLayer?

Upvotes: 0

Views: 1983

Answers (1)

Hernan
Hernan

Reputation: 371

You may create a custom variable using javascript. That custom variable will return the current timestamp (beware that you may need to deal with browsers timezones, if that is important to you).

Go to Variables and add a new using the type Custom JavaScript: enter image description here

Then the code could be along this lines (grabbed from here), depending on the format you want to return:

function() {
 try {
  var timestamp = new Date();
  var time = timestamp.toString().split(' ');
  return time[3]+ " " +time[1]+ " " +time[2]+ " "+time[4];
 } catch(e) {
  return "unknown";
 }
}

After that, a variable with the name given (in this case I used 'Timestamp') will become available as {{Timestamp}} You then can plug it in the event or whatever tag you are creating. You may even use it as {{Timestamp}} inside a Javascript tag. The variable will return a timestamp in the format: 2020 May 30 11:41:44

Upvotes: 2

Related Questions