Skip to content

Commit

Permalink
Merge pull request #2 from davidgs/analytics-fix
Browse files Browse the repository at this point in the history
Analytics fix
  • Loading branch information
davidgs authored Oct 22, 2024
2 parents aa9b49b + 8efff21 commit 4401ced
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/scripts/core/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './device'
export * from './insertScript'
export * from './theme-scheme'
11 changes: 11 additions & 0 deletions assets/scripts/core/theme-scheme.js
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions assets/scripts/features/analytics/index.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
8 changes: 8 additions & 0 deletions assets/scripts/features/analytics/posthog.js
Original file line number Diff line number Diff line change
@@ -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',
})
24 changes: 24 additions & 0 deletions assets/scripts/features/analytics/statcounter.js
Original file line number Diff line number Diff line change
@@ -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);


4 changes: 4 additions & 0 deletions assets/scripts/features/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (process.env.FEATURE_ANALYTICS === '1') {
import('./analytics')
}

if (process.env.FEATURE_VIDEOPLAYER === '1') {
import('./videoplayer')
}
Expand Down

0 comments on commit 4401ced

Please sign in to comment.