Skip to content

Commit 05cefe2

Browse files
committed
TrackingConsent: Requested Changes
PR #56 Requested changes by Sisou #56 (review) - `options.setSiteId` doesn’t have a default value anymore, and is now required - Renamed `DEFAULT_TRACKING_URL` to `DEFAULT_TRACKING_SCRIPT_URL` - Moved the default `geoIpServer` value to a constant named `DEFAULT_GEOIP_SERVER_URL` - Added possibility to set the cookie's attributes `secure` and `sameSite` - Added a comment explaining the two `localStorage` keys - Changed default lifetime of the cookie from 20 years to 10 years since 20 years would not work on 32bits systems. (the cookie would just disappear instantly)
1 parent ff10c36 commit 05cefe2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/components/TrackingConsent.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ class TrackingConsent extends Vue {
7878
/** API reference: https://developer.matomo.org/guides/tracking-javascript#configuration-of-the-tracker-object */
7979
@Prop({
8080
type: Object,
81+
required: true,
82+
validator: (options) => 'setSiteId' in options,
8183
default: () => ({
82-
setSiteId: 1,
8384
setTrackerUrl: TrackingConsent.DEFAULT_TRACKER_URL,
8485
}),
8586
})
@@ -91,7 +92,7 @@ class TrackingConsent extends Vue {
9192
9293
@Prop({
9394
type: String,
94-
default: () => TrackingConsent.DEFAULT_TRACKING_URL,
95+
default: () => TrackingConsent.DEFAULT_TRACKING_SCRIPT_URL,
9596
})
9697
public trackingScriptUrl: string;
9798
@@ -118,11 +119,13 @@ class TrackingConsent extends Vue {
118119
public cookieOptions: {
119120
domain: string,
120121
expirationDays: number,
122+
secure?: boolean,
123+
sameSite?: 'lax'|'strict'|'none',
121124
};
122125
123126
@Prop({
124127
type: String,
125-
default: 'https://geoip.nimiq-network.com:8443/v1/locate',
128+
default: TrackingConsent.DEFAULT_GEOIP_SERVER_URL,
126129
})
127130
public geoIpServer: string;
128131
@@ -207,6 +210,8 @@ class TrackingConsent extends Vue {
207210
options: {
208211
domain: string,
209212
expirationDays: number,
213+
secure?: boolean,
214+
sameSite?: 'lax'|'strict'|'none',
210215
},
211216
) {
212217
const cookie = [cookieName + '=' + cookieValue];
@@ -217,6 +222,8 @@ class TrackingConsent extends Vue {
217222
218223
cookie.push('domain=' + options.domain);
219224
cookie.push('max-age=' + options.expirationDays * 24 * 60 * 60);
225+
if (options.secure) cookie.push('Secure');
226+
if (options.sameSite) cookie.push('SameSite=' + options.sameSite);
220227
}
221228
222229
cookie.push('path=/');
@@ -389,18 +396,25 @@ namespace TrackingConsent { // tslint:disable-line:no-namespace
389396
DARK = 'dark',
390397
}
391398
399+
/**
400+
* Old matomo tracking implementations were using localStorage instead of cookies to store consent.
401+
* But unfortunately, some implementations were using the first key, and some the second one.
402+
* So we're checking both keys for existing consent for the sake of backward compatibility.
403+
*/
392404
export const LOCALSTORAGE_KEYS = [
393405
'tracking-consent',
394406
'tracking-consensus',
395407
];
396408
export const COOKIE_STORAGE_KEY = 'tracking-consent';
397409
398410
export const DEFAULT_COOKIE_DOMAIN = document.location.hostname;
399-
export const DEFAULT_COOKIE_EXPIRATION_DAYS = 365 * 20;
411+
export const DEFAULT_COOKIE_EXPIRATION_DAYS = 365 * 10;
400412
401413
export const DEFAULT_MATOMO_URL = '//stats.nimiq-network.com/';
402414
export const DEFAULT_TRACKER_URL = DEFAULT_MATOMO_URL + 'matomo.php';
403-
export const DEFAULT_TRACKING_URL = DEFAULT_MATOMO_URL + 'matomo.js';
415+
export const DEFAULT_TRACKING_SCRIPT_URL = DEFAULT_MATOMO_URL + 'matomo.js';
416+
417+
export const DEFAULT_GEOIP_SERVER_URL = 'https://geoip.nimiq-network.com:8443/v1/locate';
404418
}
405419
406420
export default TrackingConsent;

0 commit comments

Comments
 (0)