Skip to content

Instantly share code, notes, and snippets.

@Kugelschieber
Created March 18, 2022 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kugelschieber/ccee6a56777dbb565fee40cf67c58f27 to your computer and use it in GitHub Desktop.
Save Kugelschieber/ccee6a56777dbb565fee40cf67c58f27 to your computer and use it in GitHub Desktop.
(function() {
"use strict";
if(navigator.doNotTrack === "1" || localStorage.getItem("disable_pirsch")) {
return;
}
const script = document.querySelector("#pirschjs");
const endpoint = script.getAttribute("data-endpoint") || "https://api.pirsch.io/hit";
const identificationCode = script.getAttribute("data-code");
const dev = script.getAttribute("data-dev");
if(!dev && (/^localhost(.*)$|^127(\.[0-9]{1,3}){3}$/is.test(location.hostname) || location.protocol === "file:")) {
console.warn("You're running Pirsch on localhost. Hits will be ignored.");
return;
}
function hit() {
const url = endpoint+
"?nc="+new Date().getTime()+
"&code="+identificationCode+
"&url="+encodeURIComponent(location.href.substr(0, 1800))+
"&t="+encodeURIComponent(document.title)+
"&ref="+encodeURIComponent(document.referrer)+
"&w="+screen.width+
"&h="+screen.height;
const req = new XMLHttpRequest();
req.open("GET", url);
req.send();
}
if(history.pushState) {
const pushState = history["pushState"];
history.pushState = function() {
pushState.apply(this, arguments);
hit();
}
window.addEventListener("popstate", hit);
}
if(!document.body) {
window.addEventListener("DOMContentLoaded", hit);
} else {
hit();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment