Skip to content

Commit

Permalink
PubMatic adapter to support image sync (#5104)
Browse files Browse the repository at this point in the history
* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* little revamp in iframe user sync code

* added support for image based sync as well
  • Loading branch information
pm-harshad-mane authored Apr 13, 2020
1 parent 7438f5a commit 758abf3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
12 changes: 8 additions & 4 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {config} from '../src/config.js';
const BIDDER_CODE = 'pubmatic';
const LOG_WARN_PREFIX = 'PubMatic: ';
const ENDPOINT = 'https://hbopenbid.pubmatic.com/translator?source=prebid-client';
const USYNCURL = 'https://ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=';
const USER_SYNC_URL_IFRAME = 'https://ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=';
const USER_SYNC_URL_IMAGE = 'https://image8.pubmatic.com/AdServer/ImgSync?p=';
const DEFAULT_CURRENCY = 'USD';
const AUCTION_TYPE = 1;
const PUBMATIC_DIGITRUST_KEY = 'nFIn8aLzbd';
Expand Down Expand Up @@ -1057,7 +1058,7 @@ export const spec = {
* Register User Sync.
*/
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => {
let syncurl = USYNCURL + publisherId;
let syncurl = '' + publisherId;

// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
Expand All @@ -1078,10 +1079,13 @@ export const spec = {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: syncurl
url: USER_SYNC_URL_IFRAME + syncurl
}];
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Please enable iframe based user sync.');
return [{
type: 'image',
url: USER_SYNC_URL_IMAGE + syncurl
}];
}
},

Expand Down
49 changes: 37 additions & 12 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2711,37 +2711,53 @@ describe('PubMatic adapter', function () {
});

describe('getUserSyncs', function() {
const syncurl = 'https://ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=5670';
const syncurl_iframe = 'https://ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=5670';
const syncurl_image = 'https://image8.pubmatic.com/AdServer/ImgSync?p=5670';
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
})
});

it('execute only if iframeEnabled', function() {
it('execute as per config', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: syncurl
type: 'iframe', url: syncurl_iframe
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.deep.equal([{
type: 'image', url: syncurl_image
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.equal(undefined);
});

it('CCPA/USP', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{
type: 'iframe', url: `${syncurl}&us_privacy=1NYN`
type: 'iframe', url: `${syncurl_iframe}&us_privacy=1NYN`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, '1NYN')).to.deep.equal([{
type: 'image', url: `${syncurl_image}&us_privacy=1NYN`
}]);
});

it('GDPR', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl}&gdpr=1&gdpr_consent=foo`
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl}&gdpr=0&gdpr_consent=foo`
type: 'iframe', url: `${syncurl_iframe}&gdpr=0&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl}&gdpr=1&gdpr_consent=`
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=`
}]);

expect(spec.getUserSyncs({ iframeEnabled: false }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'image', url: `${syncurl_image}&gdpr=1&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'image', url: `${syncurl_image}&gdpr=0&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{
type: 'image', url: `${syncurl_image}&gdpr=1&gdpr_consent=`
}]);
});

Expand All @@ -2753,7 +2769,10 @@ describe('PubMatic adapter', function () {
return config[key];
});
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl}&coppa=1`
type: 'iframe', url: `${syncurl_iframe}&coppa=1`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.deep.equal([{
type: 'image', url: `${syncurl_image}&coppa=1`
}]);
});

Expand All @@ -2765,7 +2784,10 @@ describe('PubMatic adapter', function () {
return config[key];
});
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl}`
type: 'iframe', url: `${syncurl_iframe}`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.deep.equal([{
type: 'image', url: `${syncurl_image}`
}]);
});

Expand All @@ -2777,7 +2799,10 @@ describe('PubMatic adapter', function () {
return config[key];
});
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.deep.equal([{
type: 'iframe', url: `${syncurl}&gdpr=1&gdpr_consent=foo&us_privacy=1NYN&coppa=1`
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=foo&us_privacy=1NYN&coppa=1`
}]);
expect(spec.getUserSyncs({ iframeEnabled: false }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.deep.equal([{
type: 'image', url: `${syncurl_image}&gdpr=1&gdpr_consent=foo&us_privacy=1NYN&coppa=1`
}]);
});
});
Expand Down

0 comments on commit 758abf3

Please sign in to comment.