Skip to content

Instantly share code, notes, and snippets.

@Hillsie
Last active March 15, 2020 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hillsie/54648b992c17db9b7c81f5430598154a to your computer and use it in GitHub Desktop.
Save Hillsie/54648b992c17db9b7c81f5430598154a to your computer and use it in GitHub Desktop.
Prevent Collection of Your Own Google Analytics Results
(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