react-ga icon indicating copy to clipboard operation
react-ga copied to clipboard

Detect when Google Analytics is blocked.

Open EliteMasterEric opened this issue 3 years ago • 2 comments

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'

EliteMasterEric avatar Jul 23 '20 21:07 EliteMasterEric

Great idea. Would have saved me a few hours of pain.

jrd656 avatar Sep 11 '20 09:09 jrd656

This would be great. Is this something that could happen?

This would have saved me an hour of confusion.

YesSeri avatar Oct 21 '20 12:10 YesSeri