@@ -76,6 +76,7 @@ class TrackingConsent extends Vue {
76
76
validator : (options ) => ' setSiteId' in options ,
77
77
default : () => ({
78
78
setTrackerUrl: TrackingConsent .DEFAULT_TRACKER_URL ,
79
+ trackPageView: null ,
79
80
}),
80
81
})
81
82
public options: {
@@ -208,6 +209,24 @@ class TrackingConsent extends Vue {
208
209
});
209
210
}
210
211
212
+ /**
213
+ * trackPageView - allow you to track a new page view. Usefull for single-page apps that use history manipulation
214
+ *
215
+ * @param {number} generationTimeMs - Time that took the new route to load. Usefull if lazy-loading routes
216
+ */
217
+ public static trackPageView(
218
+ options ? : {
219
+ generationTimeMs? : number ,
220
+ customUrl? : string ,
221
+ }
222
+ ) {
223
+ if (options .customUrl ) TrackingConsent ._paq .push ([' setCustomUrl' , options .customUrl ]);
224
+
225
+ TrackingConsent ._paq .push ([' deleteCustomVariables' , ' page' ]);
226
+ TrackingConsent ._paq .push ([' setGenerationTimeMs' , options .generationTimeMs || 0 ]);
227
+ TrackingConsent ._paq .push ([' trackPageView' ]);
228
+ }
229
+
211
230
private static _setCookie(
212
231
cookieName : string ,
213
232
cookieValue : string ,
@@ -372,9 +391,10 @@ class TrackingConsent extends Vue {
372
391
}
373
392
374
393
/* set setTrackerUrl to default value if not set */
375
- if (! this .options .setTrackerUrl ) {
376
- this .options .setTrackerUrl = TrackingConsent .DEFAULT_TRACKER_URL ;
377
- }
394
+ if (! this .options .setTrackerUrl ) this .options .setTrackerUrl = TrackingConsent .DEFAULT_TRACKER_URL ;
395
+
396
+ /* set trackPageView if not set, to track the first page view */
397
+ if (! this .options .trackPageView ) this .options .trackPageView = null ;
378
398
379
399
/* Cycle through options and set them */
380
400
Object .keys (this .options ).forEach ((k ) => {
0 commit comments