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

Implement cookie expire time - forgetConsentGiven #19532

Merged
merged 6 commits into from Jul 21, 2022
Merged
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
25 changes: 17 additions & 8 deletions js/piwik.js
Expand Up @@ -7218,16 +7218,25 @@ if (typeof window.Matomo !== 'object') {
};

/**
* Calling this method will remove any previously given consent and during this page view no request
* will be sent anymore ({@link requireConsent()}) will be called automatically to ensure the removed
* consent will be enforced. You may call this method if the user removes consent manually, or if you
* want to re-ask for consent after a specific time period.
*/
this.forgetConsentGiven = function () {
var thirtyYears = 30 * 365 * 24 * 60 * 60 * 1000;
* Calling this method will remove any previously given consent and during this page view no request
* will be sent anymore ({@link requireConsent()}) will be called automatically to ensure the removed
* consent will be enforced. You may call this method if the user removes consent manually, or if you
* want to re-ask for consent after a specific time period. You can optionally define the lifetime of
* the CONSENT_REMOVED_COOKIE_NAME cookie in hours using a parameter.
*
* @param int hoursToExpire After how many hours the CONSENT_REMOVED_COOKIE_NAME cookie should expire.
* By default the consent is valid for 30 years unless cookies are deleted by the user or the browser
* prior to this
*/
this.forgetConsentGiven = function (hoursToExpire) {
futureweb marked this conversation as resolved.
Show resolved Hide resolved
if (hoursToExpire) {
hoursToExpire = hoursToExpire * 60 * 60 * 1000;
} else {
hoursToExpire = 30 * 365 * 24 * 60 * 60 * 1000;
}

deleteCookie(CONSENT_COOKIE_NAME, configCookiePath, configCookieDomain);
setCookie(CONSENT_REMOVED_COOKIE_NAME, new Date().getTime(), thirtyYears, configCookiePath, configCookieDomain, configCookieIsSecure, configCookieSameSite);
setCookie(CONSENT_REMOVED_COOKIE_NAME, new Date().getTime(), hoursToExpire, configCookiePath, configCookieDomain, configCookieIsSecure, configCookieSameSite);
this.forgetCookieConsentGiven();
this.requireConsent();
};
Expand Down
6 changes: 3 additions & 3 deletions js/piwik.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.