Disable google analytics without reloading

Viewed 178

When a user requests to disable tracking, we should disable google analytics. However, according to their docs:

"This window property must be set before any calls to gtag() are made, and it must be set on each page for which you want to disable Analytics. If the property is not set or set to false, then Analytics will work as usual."

Meaning that once you've started tracking, it seems like you have to reload the page for it to be properly disabled (using the cookie/localstorage you just set when the user asked to disable tracking).

Is it possible to disable tracking without forcing a page reload?

1 Answers

You can send hit to Google Analytics in accordance with the presence or absence of the policy acceptance cookie, using JavaScript.

Related