Skip to content

Commit

Permalink
adjusted tracking script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonolave committed Apr 15, 2024
1 parent 8d5c3cd commit 25ff71d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@
></script>

<script>
window.addEventListener('load', () => {
const updatePath = () => {
const path = location.hash ? location.hash.slice(1) : '/'; // Remove the '#' and use as path
window.goatcounter = {
window.addEventListener("load", () => {
const updateGoatCounterSettings = () => {
const path = location.hash ? location.hash.slice(1) : "/"; // Remove the '#' and use as path
const settings = {
path: path,
// You can add other GoatCounter settings here
// Optionally, add other properties like title or referrer if needed
title: document.title,
referrer: document.referrer,
};

const goatCounterScript = document.querySelector(
"script[data-goatcounter]"
);
goatCounterScript.setAttribute(
"data-goatcounter-settings",
JSON.stringify(settings)
);
};
// Update path on initial load
updatePath();
// Update path whenever the hash changes
window.addEventListener('hashchange', updatePath, false);

// Update settings on initial load
updateGoatCounterSettings();

// Update settings whenever the hash changes
window.addEventListener("hashchange", updateGoatCounterSettings, false);
});
</script>

Expand Down

0 comments on commit 25ff71d

Please sign in to comment.