Skip to content

Commit 2a07d26

Browse files
committed
Motomo Analytics (#42)
1 parent 0dc4111 commit 2a07d26

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ node_modules
99

1010
/*.js
1111

12+
static/*.js
13+
1214
# Ignore files for PNPM, NPM and YARN
1315
pnpm-lock.yaml
1416
package-lock.json

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
pnpm-lock.yaml
33
package-lock.json
44
yarn.lock
5+
6+
static/*.js

src/app.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99
<link rel="manifest" href="%sveltekit.assets%/manifest.webmanifest" />
1010
<meta name="viewport" content="width=device-width, initial-scale=1" />
1111
%sveltekit.head%
12+
13+
<!-- Klaro - make sure the config gets loaded before Klaro -->
14+
<script defer type="text/javascript" src="klaro-config.js"></script>
15+
<script defer type="text/javascript" src="klaro.js"></script>
16+
<!-- Matomo -->
17+
<script>
18+
var _paq = (window._paq = window._paq || []);
19+
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
20+
_paq.push(['requireCookieConsent']);
21+
_paq.push(['requireConsent']);
22+
_paq.push(['trackPageView']);
23+
_paq.push(['enableLinkTracking']);
24+
(function () {
25+
var u = 'https://dsnp.matomo.cloud/';
26+
_paq.push(['setTrackerUrl', u + 'matomo.php']);
27+
_paq.push(['setSiteId', '2']);
28+
var d = document,
29+
g = d.createElement('script'),
30+
s = d.getElementsByTagName('script')[0];
31+
g.async = true;
32+
g.src = 'https://cdn.matomo.cloud/dsnp.matomo.cloud/matomo.js';
33+
s.parentNode.insertBefore(g, s);
34+
})();
35+
</script>
36+
<!-- End Matomo Code -->
1237
</head>
1338

1439
<body data-sveltekit-preload-data="hover">

static/klaro-config.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// By default, Klaro will load the config from a global "klaroConfig" variable.
2+
// You can change this by specifying the "data-config" attribute on your
3+
// script take, e.g. like this:
4+
// <script src="klaro.js" data-config="myConfigVariableName" />
5+
// You can also disable auto-loading of the consent notice by adding
6+
// data-no-auto-load=true to the script tag.
7+
var klaroConfig = {
8+
// You can customize the ID of the DIV element that Klaro will create
9+
// when starting up. If undefined, Klaro will use 'klaro'.
10+
elementID: 'klaro',
11+
12+
// How Klaro should store the user's preferences. It can be either 'cookies'
13+
// or 'localStorage'. If undefined, Klaro will use cookies.
14+
klaroStorage: 'localStorage',
15+
16+
// You can customize the name of the cookie that Klaro uses for storing
17+
// user consent decisions. If undefined, Klaro will use 'klaro'.
18+
cookieName: 'frequencyCookieConsent',
19+
20+
// You can also set a custom expiration time for the Klaro cookie.
21+
// By default, it will expire after 120 days.
22+
cookieExpiresAfterDays: 120,
23+
24+
// You can customize the name of the cookie that Klaro will use to
25+
// store user consent. If undefined, Klaro will use 'klaro'.
26+
27+
// Put a link to your privacy policy here (relative or absolute).
28+
privacyPolicy: 'https://www.frequency.xyz/privacy.html',
29+
30+
// Defines the default state for applications (true=enabled by default).
31+
default: true,
32+
33+
// If "mustConsent" is set to true, Klaro will directly display the consent
34+
// manager modal and not allow the user to close it before having actively
35+
// consented or declines the use of third-party apps.
36+
mustConsent: false,
37+
hideDeclineAll: false,
38+
hideLearnMore: false,
39+
acceptAll: true,
40+
41+
// You can define the UI language directly here. If undefined, Klaro will
42+
// use the value given in the global "lang" variable. If that does
43+
// not exist, it will use the value given in the "lang" attribute of your
44+
// HTML tag. If that also doesn't exist, it will use 'en'.
45+
//lang: 'en',
46+
47+
// You can overwrite existing translations and add translations for your
48+
// app descriptions and purposes. See `src/translations.yml` for a full
49+
// list of translations that can be overwritten:
50+
// https://github.com/DPKit/klaro/blob/master/src/translations.yml
51+
52+
// Example config that shows how to overwrite translations:
53+
// https://github.com/DPKit/klaro/blob/master/src/configs/i18n.js
54+
translations: {
55+
// If you erase the "consentModal" translations, Klaro will use the
56+
// defaults as defined in translations.yml
57+
en: {
58+
consentNotice: {
59+
description: 'By browsing this website, you are allowing cookies from third-party services.',
60+
learnMore: 'Learn more',
61+
},
62+
acceptAll: 'Accept All',
63+
acceptSelected: 'Accept Selected',
64+
privacyPolicy: {
65+
name: '',
66+
text: '',
67+
},
68+
69+
matomo: {
70+
description: 'Privacy focused site analytics with no cross site tracking',
71+
},
72+
purposes: {
73+
analytics: 'analytics and improvement of our site',
74+
},
75+
},
76+
},
77+
78+
// This is a list of third-party apps that Klaro will manage for you.
79+
apps: [
80+
{
81+
// Each app should have a unique (and short) name.
82+
name: 'matomo',
83+
84+
// If "default" is set to true, the app will be enabled by default
85+
// Overwrites global "default" setting.
86+
// We recommend leaving this to "false" for apps that collect
87+
// personal information.
88+
default: true,
89+
90+
// The title of you app as listed in the consent modal.
91+
title: 'Matomo Analytics',
92+
93+
// The purpose(s) of this app. Will be listed on the consent notice.
94+
// Do not forget to add translations for all purposes you list here.
95+
purposes: ['analytics'],
96+
97+
// A list of regex expressions or strings giving the names of
98+
// cookies set by this app. If the user withdraws consent for a
99+
// given app, Klaro will then automatically delete all matching
100+
// cookies.
101+
cookies: [
102+
// you can also explicitly provide a path and a domain for
103+
// a given cookie. This is necessary if you have apps that
104+
// set cookies for a path that is not "/" or a domain that
105+
// is not the current domain. If you do not set these values
106+
// properly, the cookie can't be deleted by Klaro
107+
// (there is no way to access the path or domain of a cookie in JS)
108+
[/^_pk_.*$/, '/', '.frequency.xyz'], //for the production version
109+
['^_pk_.*$/', '/', 'localhost'], //for the local version
110+
'piwik_ignore',
111+
],
112+
callback: function (consent, _service) {
113+
console.log('here we are');
114+
if (_paq !== 'undefined') {
115+
if (consent == true) {
116+
_paq.push(['setConsentGiven']);
117+
_paq.push(['setCookieConsentGiven']);
118+
} else {
119+
_paq.push(['forgetConsentGiven']);
120+
_paq.push(['forgetCookieConsentGiven']);
121+
}
122+
}
123+
},
124+
125+
// If "required" is set to true, Klaro will not allow this app to
126+
// be disabled by the user.
127+
required: false,
128+
129+
// If "optOut" is set to true, Klaro will load this app even before
130+
// the user gave explicit consent.
131+
// We recommend always leaving this "false".
132+
optOut: false,
133+
134+
// If "onlyOnce" is set to true, the app will only be executed
135+
// once regardless how often the user toggles it on and off.
136+
onlyOnce: true,
137+
},
138+
139+
// The apps will appear in the modal in the same order as defined here.
140+
],
141+
};

static/klaro.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)