Last active
March 15, 2020 22:23
-
-
Save Hillsie/54648b992c17db9b7c81f5430598154a to your computer and use it in GitHub Desktop.
Prevent Collection of Your Own Google Analytics Results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function analyticsIFFE(){ | |
const googleTagObj = { hostname :'yourDomainName', gtag: 'UA-XXXXXX-2'}; | |
if (document.location.hostname === googleTagObj.hostname){ | |
const documentHead = document.head; | |
const scriptTag = document.createElement("script"); | |
scriptTag.async = 1; | |
scriptTag.src = `https://www.googletagmanager.com/gtag/js?id=${googleTagObj.gtag}` | |
documentHead.appendChild(scriptTag); | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', `${googleTagObj.gtag}`); | |
} else { | |
console.log(`--- Running Locally ---- `); | |
console.log(`Host: ${document.location.hostname}; Tag ${googleTagObj.gtag}`); | |
};})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment