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') }