diff --git a/static/js/analytics.js b/static/js/analytics.js new file mode 100644 index 00000000..75ab2f06 --- /dev/null +++ b/static/js/analytics.js @@ -0,0 +1,26 @@ +(function () { + // only enable on prod + if (!window.location.host.endsWith('simplelogin.io')) { + console.log("Analytics should only be enabled in prod"); + return; + } + + if (store.get('analytics-ignore') === 't') { + console.log("Analytics is disabled"); + return; + } + + console.log("init Analytics"); + + // Add Plausible script + // + var plausibleScript = document.createElement('script'); + plausibleScript.defer = 1; + plausibleScript.async = 1; + plausibleScript.dataset.domain = "app.simplelogin.io"; + plausibleScript.src = 'https://plausible.simplelogin.io/js/index.js'; + + var ins = document.getElementsByTagName('script')[0]; + ins.parentNode.insertBefore(plausibleScript, ins) + +})(); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index aa713c50..d871619c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -198,39 +198,10 @@ - {% block script %} {% endblock %} - - var plausibleScript = document.createElement('script'); - plausibleScript.defer = 1; - plausibleScript.async = 1; - plausibleScript.dataset.domain = "app.simplelogin.io"; - plausibleScript.src = 'https://plausible.simplelogin.io/js/index.js'; - - var ins = document.getElementsByTagName('script')[0]; - ins.parentNode.insertBefore(plausibleScript, ins) - - })(); - - + \ No newline at end of file