From 5d89d6ba81558c5e2ad2f5b6e4832b1deecf753f Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 30 Jan 2025 15:57:25 +1100 Subject: [PATCH 1/3] Add rule for Shopify Customer Privacy CMP --- lib/eval-snippets.ts | 1 + rules/autoconsent/shopify.json | 31 +++++++++++++++++++++++++++++++ tests/shopify.spec.ts | 7 +++++++ 3 files changed, 39 insertions(+) create mode 100644 rules/autoconsent/shopify.json create mode 100644 tests/shopify.spec.ts diff --git a/lib/eval-snippets.ts b/lib/eval-snippets.ts index aaacab0f..1588a888 100644 --- a/lib/eval-snippets.ts +++ b/lib/eval-snippets.ts @@ -173,6 +173,7 @@ export const snippets = { (document.cookie.match(/.YAAAAAAAAAAA/) || document.cookie.match(/.aAAAAAAAAAAA/) || document.cookie.match(/.YAAACFgAAAAA/)), EVAL_REDDIT_0: () => document.cookie.includes('eu_cookie={%22opted%22:true%2C%22nonessential%22:false}'), EVAL_ROBLOX_TEST: () => document.cookie.includes('RBXcb'), + EVAL_SHOPIFY_TEST: () => window.Shopify.customerPrivacy.currentVisitorConsent().analytics === 'no', EVAL_SKYSCANNER_TEST: () => document.cookie.match(/gdpr=[^;]*adverts:::false/) && !document.cookie.match(/gdpr=[^;]*init:::true/), EVAL_SIRDATA_UNBLOCK_SCROLL: () => { document.documentElement.classList.forEach((cls) => { diff --git a/rules/autoconsent/shopify.json b/rules/autoconsent/shopify.json new file mode 100644 index 00000000..64f8d6c7 --- /dev/null +++ b/rules/autoconsent/shopify.json @@ -0,0 +1,31 @@ +{ + "name": "shopify", + "vendorUrl": "https://shopify.dev/docs/api/customer-privacy", + "cosmetic": false, + "prehideSelectors": ["#shopify-pc__banner"], + "detectCmp": [ + { + "exists": "#shopify-pc__banner" + } + ], + "detectPopup": [ + { + "visible": "#shopify-pc__banner" + } + ], + "optIn": [ + { + "waitForThenClick": "#shopify-pc__banner__btn-accept" + } + ], + "optOut": [ + { + "waitForThenClick": "#shopify-pc__banner__btn-decline" + } + ], + "test": [ + { + "eval": "EVAL_SHOPIFY" + } + ] +} diff --git a/tests/shopify.spec.ts b/tests/shopify.spec.ts new file mode 100644 index 00000000..e91736bd --- /dev/null +++ b/tests/shopify.spec.ts @@ -0,0 +1,7 @@ +import generateCMPTests from '../playwright/runner'; + +generateCMPTests('shopify', [ + 'https://store.leviton.com/collections/smart-load-center', + 'https://snaprevise.co.uk/', + 'https://hannun.com/', +]); From 31f9f77d9de169ff4a4eeef540bacfb2014adf23 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 31 Jan 2025 10:53:20 +1100 Subject: [PATCH 2/3] EVAL_SHOPIFY -> EVAL_SHOPIFY_TEST --- rules/autoconsent/shopify.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/autoconsent/shopify.json b/rules/autoconsent/shopify.json index 64f8d6c7..a939f562 100644 --- a/rules/autoconsent/shopify.json +++ b/rules/autoconsent/shopify.json @@ -25,7 +25,7 @@ ], "test": [ { - "eval": "EVAL_SHOPIFY" + "eval": "EVAL_SHOPIFY_TEST" } ] } From 53a2516724ab7c3872cb1da6b2a3a6151fdca34c Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 31 Jan 2025 11:48:47 +1100 Subject: [PATCH 3/3] Fix tests --- lib/eval-snippets.ts | 12 +++++++++++- tests/shopify.spec.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/eval-snippets.ts b/lib/eval-snippets.ts index 1588a888..164739af 100644 --- a/lib/eval-snippets.ts +++ b/lib/eval-snippets.ts @@ -173,7 +173,17 @@ export const snippets = { (document.cookie.match(/.YAAAAAAAAAAA/) || document.cookie.match(/.aAAAAAAAAAAA/) || document.cookie.match(/.YAAACFgAAAAA/)), EVAL_REDDIT_0: () => document.cookie.includes('eu_cookie={%22opted%22:true%2C%22nonessential%22:false}'), EVAL_ROBLOX_TEST: () => document.cookie.includes('RBXcb'), - EVAL_SHOPIFY_TEST: () => window.Shopify.customerPrivacy.currentVisitorConsent().analytics === 'no', + EVAL_SHOPIFY_TEST: () => + document.cookie.includes('gdpr_cookie_consent=0') || + (document.cookie.includes('_tracking_consent=') && + JSON.parse( + decodeURIComponent( + document.cookie + .split(';') + .find((s) => s.trim().startsWith('_tracking_consent')) + .split('=')[1], + ), + ).purposes.a === false), EVAL_SKYSCANNER_TEST: () => document.cookie.match(/gdpr=[^;]*adverts:::false/) && !document.cookie.match(/gdpr=[^;]*init:::true/), EVAL_SIRDATA_UNBLOCK_SCROLL: () => { document.documentElement.classList.forEach((cls) => { diff --git a/tests/shopify.spec.ts b/tests/shopify.spec.ts index e91736bd..1ed57134 100644 --- a/tests/shopify.spec.ts +++ b/tests/shopify.spec.ts @@ -3,5 +3,5 @@ import generateCMPTests from '../playwright/runner'; generateCMPTests('shopify', [ 'https://store.leviton.com/collections/smart-load-center', 'https://snaprevise.co.uk/', - 'https://hannun.com/', + 'https://www.blacklimba.com/', ]);