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 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'js/piwik.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(); + } }; /** -- cgit v1.2.3