Skip to content

Commit e27bf44

Browse files
authored
Added consent gating to the Advertising component to ensure no advertising cookies are written before user consent is resolved. (#1442)
* fix functional tests updated the skipped tests for helper.js in componentRegistered hook , for viewthru : return promise for click thru advertising call , for viewthru case fire and forget Add timestamp in payload of enrichment calls * click thru check -> either one of ef_id or s_kwcid param present * build trigger * build trigger * build trigger * build trigger * consent bug fix : advertising component * Remove sandbox file changes from branch * Remove unrelated files from branch - keep only consent changes * feat(Advertising): gate click cookie write on consent Move LAST_CLICK_COOKIE_KEY cookie write from clickThroughHandler into createAdConversionHandler.trackAdConversion(), after consent.awaitConsent() resolves. This ensures no ad-tracking cookies (skwcid/efid) are set without user consent. Changes: - clickThroughHandler: removed pre-consent LAST_CLICK_COOKIE_KEY write, pass skwcid/efid through to trackAdConversion() - createAdConversionHandler: accept cookieManager, write click cookie only after consent is granted - index.js: pass cookieManager to createAdConversionHandler (1-line change) * consent case for onbefore send event * consent case for onbefore send event * add changeset for advertising consent gate
1 parent 9cf47f9 commit e27bf44

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@adobe/alloy": patch
3+
---
4+
5+
Added consent gating to the Advertising component to ensure no advertising cookies are written before user consent is resolved.
6+

packages/core/src/components/Advertising/createComponent.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default ({
4242
sendAdConversionHandler();
4343
},
4444
onBeforeEvent: ({ event, advertising = {} }) => {
45+
const { state } = consent.current();
46+
if (state !== "in") {
47+
// Consent not yet granted — skip advertising ID resolution
48+
// but don't block the sendEvent call.
49+
return;
50+
}
4551
return handleOnBeforeSendEvent({
4652
cookieManager,
4753
logger,

packages/core/test/unit/specs/components/Advertising/createComponent.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe("Advertising::createComponent", () => {
7474

7575
consent = {
7676
awaitConsent: vi.fn().mockResolvedValue(),
77+
current: vi.fn().mockReturnValue({ state: "in", wasSet: true }),
7778
};
7879

7980
// Reset mocks
@@ -143,6 +144,26 @@ describe("Advertising::createComponent", () => {
143144
});
144145
});
145146

147+
it("should skip onBeforeSendEvent when consent is out", async () => {
148+
consent.current.mockReturnValue({ state: "out", wasSet: true });
149+
150+
const event = { mergeQuery: vi.fn() };
151+
152+
await component.lifecycle.onBeforeEvent({ event });
153+
154+
expect(handleOnBeforeSendEvent).not.toHaveBeenCalled();
155+
});
156+
157+
it("should skip onBeforeSendEvent when consent is pending", async () => {
158+
consent.current.mockReturnValue({ state: "pending", wasSet: false });
159+
160+
const event = { mergeQuery: vi.fn() };
161+
162+
await component.lifecycle.onBeforeEvent({ event });
163+
164+
expect(handleOnBeforeSendEvent).not.toHaveBeenCalled();
165+
});
166+
146167
it("should maintain shared state across calls", async () => {
147168
const event = { mergeQuery: vi.fn() };
148169

packages/core/test/unit/specs/components/Advertising/utils/helpers.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe("Advertising::helpers", () => {
4747
let mockLogger;
4848

4949
beforeEach(() => {
50+
// Reset modules to clear any cached state
51+
vi.resetModules();
5052
// Mock event object
5153
mockEvent = {
5254
mergeQuery: vi.fn(),

0 commit comments

Comments
 (0)