Created
March 18, 2022 11:40
-
-
Save Kugelschieber/ccee6a56777dbb565fee40cf67c58f27 to your computer and use it in GitHub Desktop.
This file contains 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() { | |
"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