Skip to content

Commit 08c1cc0

Browse files
authored
Trigger iframe based sync pixel (#12144)
1 parent 72bf1cf commit 08c1cc0

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

modules/criteoBidAdapter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {deepAccess, deepSetValue, isArray, logError, logWarn, parseUrl} from '../src/utils.js';
1+
import {deepAccess, deepSetValue, isArray, logError, logWarn, parseUrl, triggerPixel} from '../src/utils.js';
22
import {registerBidder} from '../src/adapters/bidderFactory.js';
33
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
44
import {getStorageManager} from '../src/storageManager.js';
@@ -283,6 +283,10 @@ export const spec = {
283283
if (response.bundle) {
284284
saveOnAllStorages(BUNDLE_COOKIE_NAME, response.bundle, GUID_RETENTION_TIME_HOUR);
285285
}
286+
287+
if (response.callbacks) {
288+
response.callbacks.forEach(triggerPixel);
289+
}
286290
}
287291
}, true);
288292

test/spec/modules/criteoBidAdapter_spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ describe('The Criteo bidding adapter', function () {
123123
getCookieStub,
124124
setCookieStub,
125125
getDataFromLocalStorageStub,
126-
removeDataFromLocalStorageStub;
126+
removeDataFromLocalStorageStub,
127+
triggerPixelStub;
127128

128129
beforeEach(function () {
129130
getConfigStub = sinon.stub(config, 'getConfig');
@@ -146,6 +147,8 @@ describe('The Criteo bidding adapter', function () {
146147
setCookieStub = sinon.stub(storage, 'setCookie');
147148
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
148149
removeDataFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage');
150+
151+
triggerPixelStub = sinon.stub(utils, 'triggerPixel');
149152
});
150153

151154
afterEach(function () {
@@ -158,6 +161,7 @@ describe('The Criteo bidding adapter', function () {
158161
setCookieStub.restore();
159162
getDataFromLocalStorageStub.restore();
160163
removeDataFromLocalStorageStub.restore();
164+
triggerPixelStub.restore();
161165
});
162166

163167
it('should not trigger sync if publisher did not enable iframe based syncs', function () {
@@ -301,6 +305,30 @@ describe('The Criteo bidding adapter', function () {
301305
expect(removeDataFromLocalStorageStub.called).to.be.false;
302306
expect(ajaxStub.called).to.be.false;
303307
});
308+
309+
it('should trigger sync pixel from iframe response', function (done) {
310+
const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined);
311+
312+
const event = new MessageEvent('message', {
313+
data: {
314+
requestId: '123456',
315+
callbacks: [
316+
'https://example.com/pixel1',
317+
'https://example.com/pixel2'
318+
]
319+
},
320+
origin: 'https://gum.criteo.com'
321+
});
322+
323+
window.dispatchEvent(event);
324+
setTimeout(() => {
325+
expect(triggerPixelStub.calledTwice).to.be.true;
326+
expect(triggerPixelStub.firstCall.calledWith('https://example.com/pixel1')).to.be.true;
327+
expect(triggerPixelStub.secondCall.calledWith('https://example.com/pixel2')).to.be.true;
328+
329+
done();
330+
}, 0);
331+
});
304332
});
305333

306334
describe('isBidRequestValid', function () {

0 commit comments

Comments
 (0)