@Rapid Would you mind sharing a few more

@Rapid Would you mind sharing a few more details of your setup with TimeMe.js? Even just a screenshot of your zaraz.track() call from TimeMe callback and then a screenshot of your google analytics MC event configuration in cloudflare? I would super appreciate any tips on getting this working as I also see 0s or 1s user engagement time in google analytics like @Zino (Expatfile.tax) with Zaraz which is not very helpful.
7 Replies
Rapid
Rapid14mo ago
So, what we do is obviously installing the timeme package and we have a wrapper around zaraz.track. The way we do it is by using exactly their approach, we init timeme on every page and then use the onbeforeunload event to send zaraz.track.
window.onbeforeunload = function (event) {
const activeTime = TimeMe.getTimeOnCurrentPageInSeconds(); // Get the active time in seconds

if (activeTime >= <minumumtime_to_track>) {
const eventTime = Math.min(Math.floor(activeTime / 30) * 30, 120);
const eventName = `session_sustain_${eventTime}s`;

push({
event: eventName,
event_properties: {
event_category: <event_name>,
},
});
}
};
window.onbeforeunload = function (event) {
const activeTime = TimeMe.getTimeOnCurrentPageInSeconds(); // Get the active time in seconds

if (activeTime >= <minumumtime_to_track>) {
const eventTime = Math.min(Math.floor(activeTime / 30) * 30, 120);
const eventName = `session_sustain_${eventTime}s`;

push({
event: eventName,
event_properties: {
event_category: <event_name>,
},
});
}
};
(push is our wrapper around zaraz.track) Maybe @LiranM can elaborate abit in manners of how he see it in GA after that
Combwe
Combwe14mo ago
@BensTechLab We are triggering events to count specific time frames on page with the code @Rapid sent here, it's just an easy way for us to track active time on page
BensTechLab
BensTechLabOP14mo ago
So is this using your own custom event? Or reverse engineering GA4s native event? I guess I'm wondering about that session_sustain_{n} event and where that is documented.
BensTechLab
BensTechLabOP14mo ago
I am researching and found this article about GA4 native events: https://www.analyticsmania.com/post/user_engagement-event-in-google-analytics-4/
Julius Fedorovicius
Analytics Mania
Demystifying user_engagement Event in Google Analytics 4 - Analytic...
If you are at least a little familiar with event tracking in Google Analytics 4, you already know that one of the automatically tracked events is
BensTechLab
BensTechLabOP14mo ago
Another way to say it... I'd love to see your GA4 "Tool action" in the Zaraz config portal to see what event and parameters you send to GA4 as a result of TimeMe.js
Combwe
Combwe14mo ago
It's a custom event, we are using TimeMe to push events to zaraz.track() and trigger a GA4 custom event
BensTechLab
BensTechLabOP14mo ago
Ok thanks - I guess my preferred solution would mimic the GA4 events if I could get that to work. So I may try some experiments. I appreciate your information sharing! Thanks for the insight.

Did you find this page helpful?