Thursday, 29 April 2021

TypeError: Illegal Invocation

We're running a Create React App (CRA) web app, to which we've added Google Analytics v4. We initiate analytics using the ga-4-react npm package. Manual initialization in index.js

const ga4react = new GA4React(process.env.REACT_APP_GOOGLE_ANALYTICS_ID);

ga4react.initialize().then((ga4) => {
    ga4.pageview(window.location.path);
}, (err) => {
    Sentry.captureException(err);
});

We're receiving hundreds of errors from the gtag/js file to our Sentry error monitoring platform. This error doesn't really say much to us and we've spent two days trying to find out if anyone's run into a problem like this, but so far we've come up empty. It also doesn't seem to affect user experience, but it's rather annoying for us to monitor.

The error is reported as so to Sentry.

TypeError zq(gtag/js)
Illegal invocation

gtag/js in zq at line 477:453
{snip} ))}}},zq=function(a,b,c){var d=a+"?"+b;c?$c.sendBeacon&&$c.sendBeacon(d,c):pd(d)};var Eq=window,Fq=document,Gq=function(a){var b=Eq._gaUserP {snip}

We also receive as many errors from ga-4-react (the catch-block in the code snippet above). We also tried using the analytics snippet with react-helmet, but had the same result.

This error seems to be generated by a number of browsers (Chrome, Opera, Safari, mobile browsers) on many platforms (Android, Windows 10, OS X) so we can't really pinpoint any specific route, platform, browser that's common with these users.

I also tried to replicate this with AdBlock, blocking trackers, using Do Not Track, but nothing.



from TypeError: Illegal Invocation

No comments:

Post a Comment