Skip to content

Instantly share code, notes, and snippets.

@erinrwhite
Last active September 28, 2025 20:36
Show Gist options
  • Select an option

  • Save erinrwhite/c77eefc786fb2574160c21d30ef9e61a to your computer and use it in GitHub Desktop.

Select an option

Save erinrwhite/c77eefc786fb2574160c21d30ef9e61a to your computer and use it in GitHub Desktop.
SimpleAnalytics implementation with tracking gif - adding variables using local JS
<!-- SimpleAnalytics with some added info -->
<script type="text/javascript">
const analyticsURL = "https://queue.simpleanalyticscdn.com/noscript.gif";
const refURL = document.referrer;
const hostName = encodeURI(window.location.hostname);
const pathName = encodeURI(window.location.pathname);
const userTZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
const imageTag = document.createElement("img");
imageTag.setAttribute("alt","");
imageTag.setAttribute("referrerpolicy","no-referrer-when-downgrade");
imageTag.setAttribute("src",analyticsURL+"?hostname="+hostName+"&path="+pathName+"&referrer="+refURL+"&timezone="+userTZ);
document.body.appendChild(imageTag);
</script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade"/></noscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment