diff options
author | Stefan Giehl <stefan@matomo.org> | 2022-07-08 12:34:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 12:34:16 +0300 |
commit | 89a44abd03df0102f860306628bd0d75987c3626 (patch) | |
tree | ac02d4cd384ee467618e4188e5d5bdada23c6b36 /js/piwik.js | |
parent | 7885267b684c6b836b76b95a764fe792fafffbe1 (diff) |
Implement url parameter to ignore referrer (#19420)
* Implement url parameter to ignore referrer
* rebuilt js files
* apply some fixes
Diffstat (limited to 'js/piwik.js')
-rw-r--r-- | js/piwik.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/js/piwik.js b/js/piwik.js index 7a12a3adc1..29741749b3 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2522,6 +2522,10 @@ if (typeof window.Matomo !== 'object') { // for outlinks or referrers url = removeUrlParameter(url, configVisitorIdUrlParameter); + // remove ignore referrer parameter if present + url = removeUrlParameter(url, 'ignore_referrer'); + url = removeUrlParameter(url, 'ignore_referer'); + for (i = 0; i < configExcludedQueryParams.length; i++) { url = removeUrlParameter(url, configExcludedQueryParams[i]); } @@ -3757,6 +3761,16 @@ if (typeof window.Matomo !== 'object') { return request + timings; } + /** + * Returns if the given url contains a parameter to ignore the referrer + * e.g. ignore_referer or ignore_referrer + * @param url + * @returns {boolean} + */ + function hasIgnoreReferrerParameter(url) { + return getUrlParameter(url, 'ignore_referrer') === "1" || getUrlParameter(url, 'ignore_referer') === "1"; + } + function detectReferrerAttribution() { var i, now = new Date(), @@ -3780,7 +3794,7 @@ if (typeof window.Matomo !== 'object') { referralTs = attributionCookie[2]; referralUrl = attributionCookie[3]; - if (!cookieSessionValue) { + if (!hasIgnoreReferrerParameter(currentUrl) && !cookieSessionValue) { // cookie 'ses' was not found: we consider this the start of a 'session' // Detect the campaign information from the current URL @@ -3871,7 +3885,8 @@ if (typeof window.Matomo !== 'object') { now = new Date(), customVariablesCopy = customVariables, cookieCustomVariablesName = getCookieName('cvar'), - currentUrl = configCustomUrl || locationHrefAlias; + currentUrl = configCustomUrl || locationHrefAlias, + hasIgnoreReferrerParam = hasIgnoreReferrerParameter(currentUrl); if (configCookiesDisabled) { deleteCookies(); @@ -3898,7 +3913,7 @@ if (typeof window.Matomo !== 'object') { '&r=' + String(Math.random()).slice(2, 8) + // keep the string to a minimum '&h=' + now.getHours() + '&m=' + now.getMinutes() + '&s=' + now.getSeconds() + '&url=' + encodeWrapper(purify(currentUrl)) + - (configReferrerUrl.length && !isReferrerExcluded(configReferrerUrl) ? '&urlref=' + encodeWrapper(purify(configReferrerUrl)) : '') + + (configReferrerUrl.length && !isReferrerExcluded(configReferrerUrl) && !hasIgnoreReferrerParam ? '&urlref=' + encodeWrapper(purify(configReferrerUrl)) : '') + (isNumberOrHasLength(configUserId) ? '&uid=' + encodeWrapper(configUserId) : '') + '&_id=' + cookieVisitorIdValues.uuid + '&_idn=' + cookieVisitorIdValues.newVisitor + // currently unused |