From a638eba7c7b5796a3407f274d022ebd6bb1ca07f Mon Sep 17 00:00:00 2001 From: Jonas Leder Date: Tue, 13 Apr 2021 10:46:15 +0200 Subject: [PATCH] define custom element for matomo tracking --- js/customElements/header.js | 3 ++- js/customElements/matomo.js | 16 ++++++++++++++++ js/script.js | 3 ++- public/API/config.php | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 js/customElements/matomo.js diff --git a/js/customElements/header.js b/js/customElements/header.js index 0c3622d..338c031 100644 --- a/js/customElements/header.js +++ b/js/customElements/header.js @@ -10,6 +10,7 @@ class Header extends HTMLElement {

${pageTitle}

+
@@ -17,7 +18,7 @@ class Header extends HTMLElement {
- + `; } } diff --git a/js/customElements/matomo.js b/js/customElements/matomo.js new file mode 100644 index 0000000..c344fd8 --- /dev/null +++ b/js/customElements/matomo.js @@ -0,0 +1,16 @@ +class Matomo extends HTMLElement { + constructor() { + super(); + this.generateTrackImg(); + } + async generateTrackImg(){ + let trackURL = await (await fetch("/API/config.php?name=trackURL")).text() + this.innerHTML = ` + + + + `; + } +} + +customElements.define("jl-matomo", Matomo); \ No newline at end of file diff --git a/js/script.js b/js/script.js index 4ae0e95..2f9ab3e 100644 --- a/js/script.js +++ b/js/script.js @@ -15,4 +15,5 @@ require("./customElements/newComment"); require("./customElements/contactMailButton"); require("./customElements/header"); require("./customElements/mainMenu"); -require("./customElements/footer"); \ No newline at end of file +require("./customElements/footer"); +require("./customElements/matomo"); \ No newline at end of file diff --git a/public/API/config.php b/public/API/config.php index 97fe747..379bf62 100644 --- a/public/API/config.php +++ b/public/API/config.php @@ -8,7 +8,7 @@ switch ($configValue){ echo($sitekey); break; case "trackURL": - echo($trackurl); + echo($trackURL); break; default: echo("notFound");