@@ -76,6 +76,7 @@ class TrackingConsent extends Vue {
7676 validator : (options ) => ' setSiteId' in options ,
7777 default : () => ({
7878 setTrackerUrl: TrackingConsent .DEFAULT_TRACKER_URL ,
79+ trackPageView: null ,
7980 }),
8081 })
8182 public options: {
@@ -208,6 +209,24 @@ class TrackingConsent extends Vue {
208209 });
209210 }
210211
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+
211230 private static _setCookie(
212231 cookieName : string ,
213232 cookieValue : string ,
@@ -372,9 +391,10 @@ class TrackingConsent extends Vue {
372391 }
373392
374393 /* 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 ;
378398
379399 /* Cycle through options and set them */
380400 Object .keys (this .options ).forEach ((k ) => {
0 commit comments