Fri, May 10, 2019
The original article was written on May 10, 2019, and it focused on sending data to Google Analytics Universal. However, during the migration of the blog to a new CMS, I decided to update the content to reflect the current version — Google Analytics 4.
One of the most common questions I hear from businesses is how to calculate the time between a user’s first visit to the site and their final conversion or purchase. And while the Attribution Path report in Google Analytics 4 can help answer the first part of the question...
When it comes to calculating the time from the first visit to the actual purchase, things get trickier. However, all the necessary data is already stored in the user’s Client ID, which is generated by Google Analytics 4.
Let’s take a basic Client ID as an example:
GA1.2.1970745861.1555984860
The last number after the final dot is the timestamp of the first visit — but in UNIX format. To convert it into a human-readable date, you can use an online converter, such as this one.
If you need to perform this conversion at scale, here’s a small JavaScript snippet that will do the job:
function Unix_timestamp(t){
var dt = new Date(t*1000);
return dt;
}
This function will return the same value as the online converter:
Now all that’s left is to calculate the difference between two dates — the date of the first visit and the date of the sale — and your report is ready.
I hope this information was useful to you. Feel free to share your thoughts in the comments about other ways this first visit date can be used.
Also, don’t miss more tips from the #analyticsTips series:
If you enjoyed this content, subscribe to my LinkedIn page.
I also run a LinkedIn newsletter with fresh analytics updates every two weeks — here’s the link to join.
Web Analyst, Marketer