Skip to content

Commit

Permalink
Trigger iframe based sync pixel (prebid#12144)
Browse files Browse the repository at this point in the history
  • Loading branch information
afewcc authored Sep 9, 2024
1 parent 72bf1cf commit 08c1cc0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 29 additions & 1 deletion test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ describe('The Criteo bidding adapter', function () {
getCookieStub,
setCookieStub,
getDataFromLocalStorageStub,
removeDataFromLocalStorageStub;
removeDataFromLocalStorageStub,
triggerPixelStub;

beforeEach(function () {
getConfigStub = sinon.stub(config, 'getConfig');
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 08c1cc0

Please sign in to comment.