I have a React SPA that handles all the url's titles on the frontend, so the historyChange event regsitered on GTM is getting all the visited urls with their titles right.
However, on first load of the SPA, let's say, reload with F5, you can see how it takes some time until our code on the frontend is able to set the correct title. It looks like by that time, the pageview or the historyChange event has already been registered.
Here you can see how we load our GTM script, which loads analytics.js automatically because we have it linked from the GTM dashboard.
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
<script type="text/javascript" async="" src="https://www.googletagmanager.com/gtm.js?id=GTM-WNJK84D"></script
Is there any way to wait for the title and avoid these incorrect data being registered?
Thanks a lot
In your GTM config, you need to get rid of the "All Pages" trigger for the GA tag (that loads analytics.js).
Then you'll want to replace that with a custom data layer event that your SPA will push to the datalayer e.g. datalayer.push({event:'my-app-load'}) then trigger your GA tag off of this new trigger.