Skip to content
Advertisement

Google Analytics Event Datetime

I have the javascript code below to trigger an event each time a visitor is clicking on a specific element on the page.

JavaScript

The problem is with the datetime (dimension3), because it’s in PHP I only get the time of when the page was loaded and not the time of the click.

Any idea how I could get the time of the click?

Thank you

Advertisement

Answer

PHP is processed before the page is created, so of course it is static. If you want a dynamic time, use JavaScript. But as JS is executed by the client, it will also use the client’s timezone, so you will have to recalculate it to the timezone you are expecting.

Create a method that returns the date string you need

JavaScript

That should solve it from a technical point of view. But WHY are you doing this? Google Analytics automatically logs the event time for you, you don’t need to add it as a dimension.

On a side note: Be careful with logging IP addresses. In many countries, including the EU, this is illegal.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement