I'm using the current Google Analytics tracking code, and on Firefox 59 I get this error in console:
unreachable code after return statement
On this javascript: https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code:formatted
Since this problem doesn't seem to be googleable, hence it seems others do not have this problem, my guess is that it's me who does something wrong. But what this could be?
I'm putting the snippet in <head>
, just like the docs say:
<!DOCTYPE html> <html> <head> <title>some title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-my-tracking-code'); </script> </head> <body> blah blah </body> </html>
The JavaScript warning "unreachable code after return statement" occurs when using an expression after a return statement, or when using a semicolon-less return statement but including an expression directly after.
Analytics. js is a JavaScript library that is used to measure users' interactions with your website. Whenever we refer to Google Analytics, we are actually referring to this library.
It is not your fault. If you prettify the code with Firefox's it can be found here:
Gc = function (a, b, c) { var d = a.split('.'); var e = function (a, b) { for (var c = 0; void 0 !== a && c < d.length; c++) { if (null === a) return !1; a = a[d[c]] } return void 0 !== a || 1 < c ? a : b.length ? e(Hc(b.pop()), b) : Ic(d) }; return e(Cc.eventModel, [ // <= True return value b, c ]); return Ic(d) // <= This can never be reached! },
To prettify the code:
{}
on the bottom left of that panel to prettify it. However the reference will be lost.Firefox is correctly pointing the bug, the function Ic(d)
will never be reached since the function returns earlier. Seems like a Google Tag Manager bug, however without inspecting the original code we cannot tell the severity.
My OCD will not let this be. Warnings are as bad as errors to my brain... lol
The answer provided by @Me - caused me to perform the following:
<script async src="https://www.googletagmanager.com/gtag/js?id={Google Analytics Id here}"></script>
tag and grab a copy of the JavaScript.The warning is gone, and so far everything seems to be working - no additional or new errors/warnings in the console and Analytics/Tracking data still seems to be coming through.
This is clearly not an ideal solution - I'll have to continue monitoring this until either a) Google fixes their code (which, incidentally, omits semi-colons all over - I doubt it'd come close to passing a Linter) or b) Google makes other changes to the code, causing mine to break or my Analytics to stop reporting.
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