From 502aaa7148d87c794fdbd9264836e90d8cac9afd Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Mon, 21 Oct 2024 09:35:54 -0400 Subject: [PATCH 1/2] remove in-line script from header --- assets/scripts/core/index.js | 1 + assets/scripts/core/theme-scheme.js | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 assets/scripts/core/theme-scheme.js diff --git a/assets/scripts/core/index.js b/assets/scripts/core/index.js index 31f9d0390..939d5df22 100644 --- a/assets/scripts/core/index.js +++ b/assets/scripts/core/index.js @@ -1,2 +1,3 @@ export * from './device' export * from './insertScript' +export * from './theme-scheme' diff --git a/assets/scripts/core/theme-scheme.js b/assets/scripts/core/theme-scheme.js new file mode 100644 index 000000000..8e50b9666 --- /dev/null +++ b/assets/scripts/core/theme-scheme.js @@ -0,0 +1,11 @@ +let theme = localStorage.getItem('theme-scheme') || localStorage.getItem('darkmode:color-scheme') || 'light' +const b = 'bollocks!'; +console.log(b); +if (theme === 'system') { + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + theme = 'dark' + } else { + theme = 'light' + } +} +document.documentElement.setAttribute('data-theme', theme) From 8efff21c6e7a5f9854d270bae0be90cac1a563d4 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Tue, 22 Oct 2024 14:38:05 -0400 Subject: [PATCH 2/2] new analytics --- assets/scripts/features/analytics/index.js | 15 ++++++++++++ assets/scripts/features/analytics/posthog.js | 8 +++++++ .../scripts/features/analytics/statcounter.js | 24 +++++++++++++++++++ assets/scripts/features/index.js | 4 ++++ 4 files changed, 51 insertions(+) create mode 100644 assets/scripts/features/analytics/index.js create mode 100644 assets/scripts/features/analytics/posthog.js create mode 100644 assets/scripts/features/analytics/statcounter.js diff --git a/assets/scripts/features/analytics/index.js b/assets/scripts/features/analytics/index.js new file mode 100644 index 000000000..de1d2526c --- /dev/null +++ b/assets/scripts/features/analytics/index.js @@ -0,0 +1,15 @@ +import * as params from '@params'; + +console.log("params: ", params); + +if (params.analytics) { + console.log('Analytics: Analytics enabled'); + if (params.analytics.statcounter) { + console.log('Analytics: Statcounter enabled'); + import('./statcounter'); + } + if (params.analytics.posthog) { + console.log('Analytics: Posthog enabled'); + import('./posthog'); + } +} diff --git a/assets/scripts/features/analytics/posthog.js b/assets/scripts/features/analytics/posthog.js new file mode 100644 index 000000000..8280c5192 --- /dev/null +++ b/assets/scripts/features/analytics/posthog.js @@ -0,0 +1,8 @@ +import posthog from 'posthog-js' +import * as params from '@params' + +console.log('Posthog: Posthog enabled', params.analytics.posthog.id); +posthog.init(params.analytics.posthog.id, { + api_host: 'https://us.i.posthog.com', + person_profiles: 'identified_only', +}) diff --git a/assets/scripts/features/analytics/statcounter.js b/assets/scripts/features/analytics/statcounter.js new file mode 100644 index 000000000..fe40528e0 --- /dev/null +++ b/assets/scripts/features/analytics/statcounter.js @@ -0,0 +1,24 @@ +import * as params from '@params'; + + console.log('StatCounter: Statcounter enabled'); + const sc_project = params.analytics.statcounter.project; + const sc_invisible = params.analytics.statcounter.invisible; + const sc_security = params.analytics.statcounter.security; + const scJsHost = "https://www.statcounter.com/js/"; + + const ns = document.createElement('noscript'); + ns.setAttribute('class', 'statcounter'); + const a = document.createElement('a'); + a.setAttribute('title', 'web counter'); + a.setAttribute('href', 'https://statcounter.com/'); + a.setAttribute('target', '_blank'); + const img = document.createElement('img'); + img.setAttribute('class', 'statcounter'); + img.setAttribute('src', 'https://c.statcounter.com/' + params.analytics.statcounter.project + '/0/' + params.analytics.statcounter.security + '/' + params.analytics.statcounter.invisible + '/'); + img.setAttribute('alt', 'web counter'); + img.setAttribute('referrerPolicy', 'no-referrer-when-downgrade'); + ns.appendChild(a); + a.appendChild(img); +document.body.appendChild(ns); + + diff --git a/assets/scripts/features/index.js b/assets/scripts/features/index.js index 8065251a2..091d3cfb0 100644 --- a/assets/scripts/features/index.js +++ b/assets/scripts/features/index.js @@ -1,3 +1,7 @@ +if (process.env.FEATURE_ANALYTICS === '1') { + import('./analytics') +} + if (process.env.FEATURE_VIDEOPLAYER === '1') { import('./videoplayer') }