Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion assets/cookie-notice/frontconsent-cookie-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@
function purgeTrackingCookies() {
var patterns = Array.isArray(frcnCookieNotice.purgeCookies) ? frcnCookieNotice.purgeCookies : [];

if (!patterns.length || !document.cookie) {
if (!patterns.length) {
return;
}

purgeTrackingStorage(patterns);

if (!document.cookie) {
return;
}

Expand All @@ -94,6 +100,41 @@
});
}

/**
* Same purge for localStorage/sessionStorage: some tags keep their
* identifiers there instead of (or as well as) in cookies — e.g. the
* OpenAI ChatGPT Ads pixel's `oaiq_cs:<pixel id>` session entry.
* Storage access can throw (blocked site data, private windows), so each
* store is handled on its own and failures are ignored.
*
* @param {string[]} patterns Purge patterns (see purgeTrackingCookies()).
*/
function purgeTrackingStorage(patterns) {
['localStorage', 'sessionStorage'].forEach(function (storeName) {
try {
var store = window[storeName];

if (!store) {
return;
}

var keys = [];

for (var i = 0; i < store.length; i++) {
keys.push(store.key(i));
}

keys.forEach(function (key) {
if (key && matchesPurgePattern(key, patterns)) {
store.removeItem(key);
}
});
} catch (e) {
// Storage unavailable: nothing to purge.
}
});
}

function defineActivateGatedHelper() {
window.frcnCookieNoticeActivateGated = window.frcnCookieNoticeActivateGated || function (allowedCategories) {
if (allowedCategories && !allowedCategories.analytics) {
Expand Down
2 changes: 1 addition & 1 deletion assets/cookie-notice/frontconsent-cookie-notice.min.js

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

3 changes: 3 additions & 0 deletions includes/Frontend/CookieNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public static function get_purge_cookie_patterns() {
'_clsk',
// Brevo.
'sib_cuid',
// OpenAI ChatGPT Ads pixel (cookie, plus its sessionStorage entry).
'__obref',
'oaiq_*',
// WooCommerce order attribution (sourcebuster).
'sbjs_*',
);
Expand Down
Loading
Loading