feat: add goatcounter integration

To enable the goatcounter integration, the variable
VITE_QUEER_LEXIKON_PRIVATE must be set to "true". This check is
intentionally added for development environments so that all dev
environments from possible forks do not modify the statistics by
accident.
This commit is contained in:
nachtjasmin 2022-09-08 15:48:59 +02:00 committed by Jasmin
parent b0d3b0d205
commit b15bfc0a73
5 changed files with 42 additions and 1 deletions

2
.env Normal file
View file

@ -0,0 +1,2 @@
VITE_QUEER_LEXIKON_PRIVATE=false

View file

@ -5,6 +5,7 @@ import { initializeMap } from "./ts/map";
import "@fontsource/ubuntu/latin.css";
import { setupLegend } from "./ts/legend";
import { setupEmergencyButton } from "./ts/emergency-button";
import { addGoatCounter } from "./ts/goatcounter";
document.addEventListener("DOMContentLoaded", () => {
initializeMap();
@ -12,4 +13,8 @@ document.addEventListener("DOMContentLoaded", () => {
setupHamburger();
setupLegend();
setupEmergencyButton();
if (import.meta.env.VITE_QUEER_LEXIKON_PRIVATE === "true") {
addGoatCounter();
}
});

12
ts/env.d.ts vendored Normal file
View file

@ -0,0 +1,12 @@
interface ImportMeta {
readonly env: ImportMetaEnv;
}
interface ImportMetaEnv {
// This variable is set in our GitHub Actions for adding additional features
// that should be only available on karte.queer-lexikon.net and not
// for development purposes.
//
// Although it's actually a boolean, all environment variables are strings, so we
// type it as string here as well.
readonly VITE_QUEER_LEXIKON_PRIVATE?: string;
}

22
ts/goatcounter.ts Normal file
View file

@ -0,0 +1,22 @@
declare global {
interface Window {
goatcounter: {
path: (p: any) => string;
};
}
}
export const addGoatCounter = () => {
window.goatcounter = {
path: function (p: any) {
return location.host + p;
},
};
let goatcounter = document.createElement("script");
goatcounter.src = "//ziege.queer-lexikon.net/count.js";
goatcounter.async = true;
goatcounter.setAttribute("data-goatcounter", "https://ziege.queer-lexikon.net/count");
document.head.appendChild(goatcounter);
};

View file

@ -1,7 +1,7 @@
{
"exclude": ["/dist"],
"compilerOptions": {
"module": "ES2015",
"module": "ES2020",
"strict": true,
"lib": ["DOM", "ES2015"],
"target": "ES2015",