@@ -110,8 +110,8 @@ class TrackingConsent extends Vue {
110110 @Prop ({
111111 type: Object ,
112112 default : () => ({
113- domain: document . location . hostname ,
114- expirationDays: 365 * 20 ,
113+ domain: TrackingConsent . DEFAULT_COOKIE_DOMAIN ,
114+ expirationDays: TrackingConsent . DEFAULT_COOKIE_EXPIRATION_DAYS ,
115115 }),
116116 validator : ({ expirationDays }) => expirationDays >= 0 ,
117117 })
@@ -167,6 +167,8 @@ class TrackingConsent extends Vue {
167167 /**
168168 * trackEvent - allow you to track custom interaction on the website/webapp.
169169 *
170+ * This method won't do anything if the user denied to share usage data.
171+ *
170172 * Docs: https://matomo.org/docs/event-tracking/
171173 */
172174 public static trackEvent(
@@ -203,19 +205,18 @@ class TrackingConsent extends Vue {
203205 cookieName : string ,
204206 cookieValue : string ,
205207 options : {
206- expirationDays: number ,
207208 domain: string ,
209+ expirationDays: number ,
208210 },
209211 ) {
210212 const cookie = [cookieName + ' =' + cookieValue ];
211213
212214 if (options ) {
213- if (options .expirationDays ) {
214- cookie .push (' max-age=' + options .expirationDays * 24 * 60 * 60 );
215- }
216- if (options .domain ) {
217- cookie .push (' domain=' + options .domain );
218- }
215+ if (! options .domain ) options .domain = TrackingConsent .DEFAULT_COOKIE_DOMAIN ;
216+ if (! options .expirationDays ) options .expirationDays = TrackingConsent .DEFAULT_COOKIE_EXPIRATION_DAYS ;
217+
218+ cookie .push (' domain=' + options .domain );
219+ cookie .push (' max-age=' + options .expirationDays * 24 * 60 * 60 );
219220 }
220221
221222 cookie .push (' path=/' );
@@ -261,12 +262,12 @@ class TrackingConsent extends Vue {
261262
262263 /* Check old consent preferences if there's any */
263264 const localStoredConsent =
264- localStorage .getItem (TrackingConsent .localstorageKeys [0 ]) ||
265- localStorage .getItem (TrackingConsent .localstorageKeys [1 ]);
265+ localStorage .getItem (TrackingConsent .LOCALSTORAGE_KEYS [0 ]) ||
266+ localStorage .getItem (TrackingConsent .LOCALSTORAGE_KEYS [1 ]);
266267
267268 if (localStoredConsent ) {
268- localStorage .removeItem (TrackingConsent .localstorageKeys [0 ]);
269- localStorage .removeItem (TrackingConsent .localstorageKeys [1 ]);
269+ localStorage .removeItem (TrackingConsent .LOCALSTORAGE_KEYS [0 ]);
270+ localStorage .removeItem (TrackingConsent .LOCALSTORAGE_KEYS [1 ]);
270271
271272 this ._setConsent (JSON .parse (localStoredConsent ));
272273 }
@@ -388,14 +389,16 @@ namespace TrackingConsent { // tslint:disable-line:no-namespace
388389 DARK = ' dark' ,
389390 }
390391
391- export const localstorageKeys = [
392+ export const LOCALSTORAGE_KEYS = [
392393 ' tracking-consent' ,
393394 ' tracking-consensus' ,
394395 ];
395-
396396 export const COOKIE_STORAGE_KEY = ' tracking-consent' ;
397- export const DEFAULT_MATOMO_URL = ' //stats.nimiq-network.com/' ;
398397
398+ export const DEFAULT_COOKIE_DOMAIN = document .location .hostname ;
399+ export const DEFAULT_COOKIE_EXPIRATION_DAYS = 365 * 20 ;
400+
401+ export const DEFAULT_MATOMO_URL = ' //stats.nimiq-network.com/' ;
399402 export const DEFAULT_TRACKER_URL = DEFAULT_MATOMO_URL + ' matomo.php' ;
400403 export const DEFAULT_TRACKING_URL = DEFAULT_MATOMO_URL + ' matomo.js' ;
401404}
0 commit comments