Skip to content

Commit

Permalink
Merge pull request #12 from Carifio24/no-dev-ga
Browse files Browse the repository at this point in the history
Don't use Google Analytics on a local network
  • Loading branch information
Carifio24 authored Sep 6, 2024
2 parents a62e304 + e96344d commit f35c406
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@
<html lang="en">

<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C2ELSYY9VC"></script>
<!-- Google Analytics -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Logic derived from https://stackoverflow.com/a/61839170
const local = (function (hostname=window.location.hostname) {
return (
(['localhost', '127.0.0.1', '', '::1'].includes(hostname))
|| (hostname.startsWith('192.168.'))
|| (hostname.startsWith('10.'))
)
})();
if (!local) {
const script = document.createElement("script");
script.async = true;
script.src = "https://www.googletagmanager.com/gtag/js?id=G-C2ELSYY9VC";
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-C2ELSYY9VC');
gtag('config', 'G-C2ELSYY9VC');
}
</script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down

0 comments on commit f35c406

Please sign in to comment.