Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid empty string values in serialized referrer cookie #22071

Draft
wants to merge 2 commits into
base: 5.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions js/piwik.js
Original file line number Diff line number Diff line change
Expand Up @@ -3694,10 +3694,10 @@ if (typeof window.Matomo !== 'object') {
}

return [
'',
'',
false,
false,
0,
''
false
];
}

Expand Down Expand Up @@ -3905,10 +3905,10 @@ if (typeof window.Matomo !== 'object') {
campaignKeywordDetected,
attributionValues = {};

campaignNameDetected = attributionCookie[0];
campaignKeywordDetected = attributionCookie[1];
campaignNameDetected = attributionCookie[0] || '';
campaignKeywordDetected = attributionCookie[1] || '';
referralTs = attributionCookie[2];
referralUrl = attributionCookie[3];
referralUrl = attributionCookie[3] || '';

if (!hasIgnoreReferrerParameter(currentUrl) && !cookieSessionValue) {
// cookie 'ses' was not found: we consider this the start of a 'session'
Expand Down Expand Up @@ -3965,10 +3965,10 @@ if (typeof window.Matomo !== 'object') {
|| campaignNameDetected.length) {
referralTs = nowTs;
attributionCookie = [
campaignNameDetected,
campaignKeywordDetected,
campaignNameDetected || false,
campaignKeywordDetected || false,
referralTs,
purify(referralUrl.slice(0, referralUrlMaxLength))
purify(referralUrl.slice(0, referralUrlMaxLength)) || false
];

setCookie(cookieReferrerName, windowAlias.JSON.stringify(attributionCookie), configReferralCookieTimeout, configCookiePath, configCookieDomain, configCookieIsSecure, configCookieSameSite);
Expand Down Expand Up @@ -5346,7 +5346,7 @@ if (typeof window.Matomo !== 'object') {
* @returns {string}
*/
this.getAttributionCampaignName = function () {
return loadReferrerAttributionCookie()[0];
return loadReferrerAttributionCookie()[0] || '';
};

/**
Expand All @@ -5356,7 +5356,7 @@ if (typeof window.Matomo !== 'object') {
* @returns {string}
*/
this.getAttributionCampaignKeyword = function () {
return loadReferrerAttributionCookie()[1];
return loadReferrerAttributionCookie()[1] || '';
};

/**
Expand All @@ -5374,7 +5374,7 @@ if (typeof window.Matomo !== 'object') {
* @returns {string} Raw URL, or empty string '' if no referrer currently set
*/
this.getAttributionReferrerUrl = function () {
return loadReferrerAttributionCookie()[3];
return loadReferrerAttributionCookie()[3] || '';
};

/**
Expand Down