From 0d5053c6d0f0f539d8ad460af70ce7cc86420fd0 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Fri, 4 Dec 2020 08:42:14 +1300 Subject: When forcing GET request method in JS tracker then disable send beacon (#16870) --- js/piwik.js | 18 +++++++++++++++--- js/piwik.min.js | 10 +++++----- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/piwik.js b/js/piwik.js index df8d6776d0..50bfcbda52 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -68,7 +68,7 @@ setCampaignNameKey, setCampaignKeywordKey, getConsentRequestsQueue, requireConsent, getRememberedConsent, hasRememberedConsent, isConsentRequired, setConsentGiven, rememberConsentGiven, forgetConsentGiven, unload, hasConsent, - discardHashTag, alwaysUseSendBeacon, disableAlwaysUseSendBeacon, + discardHashTag, alwaysUseSendBeacon, disableAlwaysUseSendBeacon, isUsingAlwaysUseSendBeacon, setCookieNamePrefix, setCookieDomain, setCookiePath, setSecureCookie, setVisitorIdCookie, getCookieDomain, hasCookies, setSessionCookie, setVisitorCookieTimeout, setSessionCookieTimeout, setReferralCookieTimeout, getCookie, getCookiePath, getSessionCookieTimeout, setConversionAttributionFirstReferrer, tracker, request, @@ -4827,6 +4827,9 @@ if (typeof window.Matomo !== 'object') { this.getContent = function () { return content; }; + this.isUsingAlwaysUseSendBeacon = function () { + return configAlwaysUseSendBeacon; + }; this.buildContentImpressionRequest = buildContentImpressionRequest; this.buildContentInteractionRequest = buildContentInteractionRequest; @@ -5504,12 +5507,21 @@ if (typeof window.Matomo !== 'object') { }; /** - * Set request method + * Set request method. If you specify GET then it will automatically disable sendBeacon. * * @param string method GET or POST; default is GET */ this.setRequestMethod = function (method) { - configRequestMethod = method || defaultRequestMethod; + if (method) { + configRequestMethod = String(method).toUpperCase(); + } else { + configRequestMethod = defaultRequestMethod; + } + + if (configRequestMethod === 'GET') { + // send beacon always sends a POST request so we have to disable it to make GET work + this.disableAlwaysUseSendBeacon(); + } }; /** diff --git a/js/piwik.min.js b/js/piwik.min.js index ab43fae552..f4bc58d03d 100644 --- a/js/piwik.min.js +++ b/js/piwik.min.js @@ -54,11 +54,11 @@ this.requests=[];if(di.length===1){bH(di[0],bL)}else{de(di,bL)}},canQueue:functi };this.setTrackerUrl=function(di){aE=di};this.getTrackerUrl=function(){return aE};this.getMatomoUrl=function(){return W(this.getTrackerUrl(),bJ)};this.getPiwikUrl=function(){return this.getMatomoUrl()};this.addTracker=function(dk,dj){if(!J(dk)||null===dk){dk=this.getTrackerUrl()}var di=new P(dk,dj);I.push(di);t.trigger("TrackerAdded",[this]);return di};this.getSiteId=function(){return b7};this.setSiteId=function(di){b4(di)};this.resetUserId=function(){bA=""};this.setUserId=function(di){if(Y(di)){bA=di}};this.setVisitorId=function(dj){var di=/[0-9A-Fa-f]{16}/g;if(w(dj)&&di.test(dj)){bP=dj}else{ak("Invalid visitorId set"+dj)}};this.getUserId=function(){return bA};this.setCustomData=function(di,dj){if(V(di)){ao=di}else{if(!ao){ao={}}ao[di]=dj}};this.getCustomData=function(){return ao};this.setCustomRequestProcessing=function(di){cc=di};this.appendToTrackingUrl=function(di){cZ=di};this.getRequest=function(di){return cr(di)};this.addPlugin=function(di,dj){b[di]=dj};this.setCustomDimension=function(di,dj){di=parseInt(di,10); if(di>0){if(!J(dj)){dj=""}if(!w(dj)){dj=String(dj)}bo[di]=dj}};this.getCustomDimension=function(di){di=parseInt(di,10);if(di>0&&Object.prototype.hasOwnProperty.call(bo,di)){return bo[di]}};this.deleteCustomDimension=function(di){di=parseInt(di,10);if(di>0){delete bo[di]}};this.setCustomVariable=function(dj,di,dm,dk){var dl;if(!J(dk)){dk="visit"}if(!J(di)){return}if(!J(dm)){dm=""}if(dj>0){di=!w(di)?String(di):di;dm=!w(dm)?String(dm):dm;dl=[di.slice(0,bv),dm.slice(0,bv)];if(dk==="visit"||dk===2){cF();aR[dj]=dl}else{if(dk==="page"||dk===3){bX[dj]=dl}else{if(dk==="event"){cm[dj]=dl}}}}};this.getCustomVariable=function(dj,dk){var di;if(!J(dk)){dk="visit"}if(dk==="page"||dk===3){di=bX[dj]}else{if(dk==="event"){di=cm[dj]}else{if(dk==="visit"||dk===2){cF();di=aR[dj]}}}if(!J(di)||(di&&di[0]==="")){return false}return di};this.deleteCustomVariable=function(di,dj){if(this.getCustomVariable(di,dj)){this.setCustomVariable(di,"","",dj)}};this.deleteCustomVariables=function(di){if(di==="page"||di===3){bX={} }else{if(di==="event"){cm={}}else{if(di==="visit"||di===2){aR={}}}}};this.storeCustomVariablesInCookie=function(){bR=true};this.setLinkTrackingTimer=function(di){bL=di};this.getLinkTrackingTimer=function(){return bL};this.setDownloadExtensions=function(di){if(w(di)){di=di.split("|")}c6=di};this.addDownloadExtensions=function(dj){var di;if(w(dj)){dj=dj.split("|")}for(di=0;di