Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Google Tag Manager – How to collect immediately?

In my web page there is the following measurement

const data = {
    event: "FreeTrial-RegistrationLoginDone",
    eventContext: "additional info"     
};
window.dataLayer.push(data);

The issue is, I need to redirect from this page right after this measurement and there is a several second delay between pushing into window.dataLayer and automatic calling the API endpoint /collect. The web page cannot wait this long. Is there an option to prompt GTM to call /collect immediately?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, but normally this happens on success, right before the redirection to the thank you page. What we normally do here is ask the developers to move this push to the next page and make sure it doesn’t fire on reloads or direct hits to the thankyou page.

Also, GA4 introduces certain batching logic where it delays the calls to try to consolidate multiple events in one network request. This delaying logic, however, should use the onbeforeunload or a similar callback to make sure they still send the request even if the page is navigated from. I would suggest first debugging this screen transition and checking your Network tab to make sure that the collect request is indeed being lost on redirect.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading