react-ga
react-ga copied to clipboard
Detect when Google Analytics is blocked.
Software addons such as AdBlock Plus, uBlock Origin, Ghostery, Brave browser, and more will all prevent Google Analytics from loading by blocking the web request. Extenuating circumstances such as server issues can also prevent connection to Google Analytics.
In this scenario, there should be a convenient function that reliably determines if the Google Analytics script has loaded and the server is accessible.
Something like the following:
// If not using AdBlocker:
ReactGA.initialize('UA-000000-01');
ReactGA.hasLoaded(); // Returns 'true'
// If using an AdBlocker, or if the Google Analytics server is otherwise unaccessible:
ReactGA.initialize('UA-000000-02');
ReactGA.hasLoaded(); // Returns 'false'
Great idea. Would have saved me a few hours of pain.
This would be great. Is this something that could happen?
This would have saved me an hour of confusion.