When I add trigger in GTM on a React <a />
or <Link />
element it causes full page reload on click instead of re-rendering just part of application.
When I remove google tracking, everything works smoothly. Is there a way, how to configure GTM to not affect behaviour of application?
In the top-right corner click three dots and then go to More tools > Developer Tools. Then go to Application > Cookies > [Your domain]: And in the search field, enter _TAG_ASSISTANT. Once you find that cookie, click it and hit DELETE on your keyboard.
Multiple ways of tracking SPA + How to read this guide Built-in tracking of Google Analytics 4 (this is the quickest one) working with a History Change listener (within GTM) asking a developer to push pageview data to the Data Layer every time a visitor navigates from one page to another.
If strange things happens with Google Tag Manager link click tracking the first thing you should do is to go to your click trigger setup and see if the "wait for tags" and "check validation" checkboxes are enabled (as they are by default) and uncheck them.
They are not necessary in an SPA and (as evidenced) potentially harmful; "wait for tags" adds a delay so that other tags have time to fire before a the link directs a user away from the page (which does not happen within SPAs in any case), "check validation" tests if the link target is a valid URI (which within an SPA it probably isn't by GTMs standards - for example links starting with a hash are not valid etc.).
You can create separate function and use context router to change route ex:
myFunction(url) {
this.context.router.push({
pathname: url
});
}
<Link onClick={this.myFunction.bind(this,url)} ></Link>
attach this function to onClick of Link tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With