From 08c1cc0b8ada09d152eed39e4bba6e04615ac94a Mon Sep 17 00:00:00 2001 From: Tachfine Date: Mon, 9 Sep 2024 18:44:36 +0200 Subject: [PATCH] Trigger iframe based sync pixel (#12144) --- modules/criteoBidAdapter.js | 6 ++++- test/spec/modules/criteoBidAdapter_spec.js | 30 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index 053980d04ab..bfb703b8a8e 100644 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -1,4 +1,4 @@ -import {deepAccess, deepSetValue, isArray, logError, logWarn, parseUrl} from '../src/utils.js'; +import {deepAccess, deepSetValue, isArray, logError, logWarn, parseUrl, triggerPixel} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -283,6 +283,10 @@ export const spec = { if (response.bundle) { saveOnAllStorages(BUNDLE_COOKIE_NAME, response.bundle, GUID_RETENTION_TIME_HOUR); } + + if (response.callbacks) { + response.callbacks.forEach(triggerPixel); + } } }, true); diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index 00f05a2dc4d..123117027ea 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -123,7 +123,8 @@ describe('The Criteo bidding adapter', function () { getCookieStub, setCookieStub, getDataFromLocalStorageStub, - removeDataFromLocalStorageStub; + removeDataFromLocalStorageStub, + triggerPixelStub; beforeEach(function () { getConfigStub = sinon.stub(config, 'getConfig'); @@ -146,6 +147,8 @@ describe('The Criteo bidding adapter', function () { setCookieStub = sinon.stub(storage, 'setCookie'); getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); removeDataFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage'); + + triggerPixelStub = sinon.stub(utils, 'triggerPixel'); }); afterEach(function () { @@ -158,6 +161,7 @@ describe('The Criteo bidding adapter', function () { setCookieStub.restore(); getDataFromLocalStorageStub.restore(); removeDataFromLocalStorageStub.restore(); + triggerPixelStub.restore(); }); it('should not trigger sync if publisher did not enable iframe based syncs', function () { @@ -301,6 +305,30 @@ describe('The Criteo bidding adapter', function () { expect(removeDataFromLocalStorageStub.called).to.be.false; expect(ajaxStub.called).to.be.false; }); + + it('should trigger sync pixel from iframe response', function (done) { + const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined); + + const event = new MessageEvent('message', { + data: { + requestId: '123456', + callbacks: [ + 'https://example.com/pixel1', + 'https://example.com/pixel2' + ] + }, + origin: 'https://gum.criteo.com' + }); + + window.dispatchEvent(event); + setTimeout(() => { + expect(triggerPixelStub.calledTwice).to.be.true; + expect(triggerPixelStub.firstCall.calledWith('https://example.com/pixel1')).to.be.true; + expect(triggerPixelStub.secondCall.calledWith('https://example.com/pixel2')).to.be.true; + + done(); + }, 0); + }); }); describe('isBidRequestValid', function () {