Skip to content

Commit

Permalink
Yieldlab Bid Adapter: Add Support for User Matching (prebid#8148)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkloeber authored Mar 31, 2022
1 parent e87ac61 commit 76d29fd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
43 changes: 37 additions & 6 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {_each, deepAccess, isArray, isPlainObject} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {find} from '../src/polyfill.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
import {config} from '../src/config.js';
import { _each, deepAccess, isArray, isPlainObject, timestamp } from '../src/utils.js'
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { find } from '../src/polyfill.js'
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'
import { Renderer } from '../src/Renderer.js'
import { config } from '../src/config.js'

const ENDPOINT = 'https://ad.yieldlab.net'
const BIDDER_CODE = 'yieldlab'
Expand Down Expand Up @@ -174,6 +174,37 @@ export const spec = {
}
})
return bidResponses
},

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @param {Object} gdprConsent Is the GDPR Consent object wrapping gdprApplies {boolean} and consentString {string} attributes.
* @param {string} uspConsent Is the US Privacy Consent string.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];

if (syncOptions.iframeEnabled) {
let params = [];
params.push(`ts=${timestamp()}`);
params.push(`type=h`)
if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) {
params.push(`gdpr=${Number(gdprConsent.gdprApplies)}`);
}
if (gdprConsent && (typeof gdprConsent.consentString === 'string')) {
params.push(`gdpr_consent=${gdprConsent.consentString}`);
}
syncs.push({
type: 'iframe',
url: `${ENDPOINT}/d/6846326/766/2x2?${params.join('&')}`
});
}

return syncs;
}
};

Expand Down
36 changes: 36 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,40 @@ describe('yieldlabBidAdapter', function () {
expect(result[0].vastUrl).to.include('&iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0')
})
})

describe('getUserSyncs', function () {
const syncOptions = {
iframeEnabled: true,
pixelEnabled: false
};
const expectedUrlSnippets = ['https://ad.yieldlab.net/d/6846326/766/2x2?', 'ts=', 'type=h'];

it('should return user sync as expected', function () {
const bidRequest = {
gdprConsent: {
consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA',
gdprApplies: true
},
uspConsent: '1YYY'
};
const sync = spec.getUserSyncs(syncOptions, [], bidRequest.gdprConsent, bidRequest.uspConsent);
expect(expectedUrlSnippets.every(urlSnippet => sync[0].url.includes(urlSnippet)));
expect(sync[0].url).to.have.string('gdpr=' + Number(bidRequest.gdprConsent.gdprApplies));
expect(sync[0].url).to.have.string('gdpr_consent=' + bidRequest.gdprConsent.consentString);
// USP consent should be ignored
expect(sync[0].url).not.have.string('usp_consent=');
expect(sync[0].type).to.have.string('iframe');
});

it('should return user sync even without gdprApplies in gdprConsent', function () {
const gdprConsent = {
consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA'
}
const sync = spec.getUserSyncs(syncOptions, [], gdprConsent, undefined);
expect(expectedUrlSnippets.every(urlSnippet => sync[0].url.includes(urlSnippet)));
expect(sync[0].url).to.have.string('gdpr_consent=' + gdprConsent.consentString);
expect(sync[0].url).not.have.string('gdpr=');
expect(sync[0].type).to.have.string('iframe');
});
});
})

0 comments on commit 76d29fd

Please sign in to comment.