]> _ Git - fluidbook-html5.git/commitdiff
wip #6934 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 10:33:00 +0000 (12:33 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 10:33:00 +0000 (12:33 +0200)
js/libs/fluidbook/fluidbook.stats.js

index 422805b95f22136b788ec9277b188db9b2112e32..5df7c3dd06cca208fcb68713f759b2e6beeddbf8 100644 (file)
@@ -1,6 +1,7 @@
 function FluidbookStats() {
     this.hasMatomoTagManager = this.setupMatomoTagManager();
     this.pixel_pv_id;
+    this.user_id = window.MATOMO_USER_ID !== undefined ? window.MATOMO_USER_ID : window.sessionStorage.getItem('secureUsername');
     this.matomo_stack = [];
     this.setupMatomo();
 }
@@ -25,6 +26,7 @@ FluidbookStats.prototype = {
             if (SETTINGS.statsMatomoServer === undefined || SETTINGS.statsMatomoServer === null) {
                 SETTINGS.statsMatomoServer = '3';
             }
+            let pixel = this.hasMatomoTagManager || SETTINGS.matomoTracking === 'pixel' || SETTINGS.matomoTracking === 'proxy' ? this.getPixelUUID() : false;
             this.matomoServers.push({
                 server: 'stats' + SETTINGS.statsMatomoServer + '.fluidbook.com',
                 siteId: SETTINGS.statsMatomo,
@@ -32,7 +34,8 @@ FluidbookStats.prototype = {
                 referer: '',
                 fullURL: false,
                 mtm: false,
-                pixel: this.hasMatomoTagManager ? this.getPixelUUID() : false,
+                pixel: pixel,
+                pixelProxy: SETTINGS.matomoTracking === 'proxy',
             });
         }
         if (SETTINGS.matomoServer && SETTINGS.matomoSiteId && !this.hasMatomoTagManager) {
@@ -43,14 +46,17 @@ FluidbookStats.prototype = {
                 referer: '',
                 fullURL: true,
                 mtm: false,
+                pixel: SETTINGS.matomoTracking === 'pixel' || SETTINGS.matomoTracking === 'proxy' ? this.getPixelUUID() : false,
+                pixelProxy: SETTINGS.matomoTracking === 'proxy',
             });
         }
 
-        if (this.matomoServers.length > 0 && !this.hasMatomoTagManager) {
+
+        if (this.matomoServers.length > 0 && !this.hasMatomoTagManager && SETTINGS.matomoTracking !== 'pixel' || SETTINGS.matomoTracking !== 'proxy') {
             let u = 'https://' + this.matomoServers[0].server + '/';
             window._paq = window._paq || [];
-            if (window.MATOMO_USER_ID !== undefined) {
-                window._paq.push(['setUserId', window.MATOMO_USER_ID]);
+            if (this.user_id !== null) {
+                window._paq.push(['setUserId', this.user_id]);
             }
             window._paq.push(["setDoNotTrack", true]);
             window._paq.push(['enableHeartBeatTimer']);
@@ -161,13 +167,11 @@ FluidbookStats.prototype = {
     matomoSetCartItems: function (items) {
         for (var i in items) {
             let item = items[i];
-            this.matomoPush(['addEcommerceItem',
-                item.reference, // (Required) productSKU
+            this.matomoPush(['addEcommerceItem', item.reference, // (Required) productSKU
                 item.name, // (Optional) productName
                 item.categories, // (Optional) productCategory
                 item.price, // (Recommended) price
-                item.quantity
-            ]);
+                item.quantity]);
         }
     },
 
@@ -198,7 +202,7 @@ FluidbookStats.prototype = {
             }
             url += '&res=' + screen.width + 'x' + screen.height;
             if (data[0] === 'trackPageView') {
-                url += '&action_name=' + data[1];
+                url += '&action_name=' + encodeURIComponent(data[1]);
                 this.pixel_pv_id = this.generatePixelPVID();
             } else if (data[0] === 'trackSiteSearch') {
                 url += '&search=' + encodeURIComponent(data[1]);
@@ -210,7 +214,15 @@ FluidbookStats.prototype = {
                     url += '&e_' + order[i - 1] + '=' + encodeURIComponent(data[i]);
                 }
             }
+            if (this.user_id !== null) {
+                url += '&uid=' + encodeURIComponent(this.user_id);
+            }
             url += '&pv_id=' + this.pixel_pv_id;
+
+            if (server.pixelProxy) {
+                url = 'https://toolbox.fluidbook.com/s/prxtm?d=' + btoa(url);
+            }
+
             let i = new Image();
             i.src = url;
             return;