Skip to content

Commit

Permalink
new analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgs committed Oct 22, 2024
1 parent 502aaa7 commit 8efff21
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
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;

Check failure on line 4 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

Identifier 'sc_project' is not in camel case

Check failure on line 4 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

'sc_project' is assigned a value but never used
const sc_invisible = params.analytics.statcounter.invisible;

Check failure on line 5 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

Identifier 'sc_invisible' is not in camel case

Check failure on line 5 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

'sc_invisible' is assigned a value but never used
const sc_security = params.analytics.statcounter.security;

Check failure on line 6 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

Identifier 'sc_security' is not in camel case

Check failure on line 6 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

'sc_security' is assigned a value but never used
const scJsHost = "https://www.statcounter.com/js/";

Check failure on line 7 in assets/scripts/features/analytics/statcounter.js

View workflow job for this annotation

GitHub Actions / lint

'scJsHost' is assigned a value but never used

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 8efff21

Please sign in to comment.