Skip to content

Commit

Permalink
Yield one bid adapter: Conditionally stop sending push_sync requests (#…
Browse files Browse the repository at this point in the history
…12591)

* stop sending push_sync requests in YieldOne adapter in case of Safari browser OR iOS device

* stop sending push_sync requests in YieldOne adapter in case of GDPR applies

* fix linter

* adjust unit tests for Safari and iOS cases

* adjust unit tests for GDPR applies cases

---------

Co-authored-by: alukonin <[email protected]>
  • Loading branch information
alukonin1 and alukonin authored Dec 26, 2024
1 parent 0a14016 commit 9d733b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
24 changes: 22 additions & 2 deletions modules/yieldoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {deepAccess, isEmpty, isStr, logWarn, parseSizesInput} from '../src/utils
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {Renderer} from '../src/Renderer.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getBrowser, getOS} from '../libraries/userAgentUtils/index.js';
import {browserTypes, osTypes} from '../libraries/userAgentUtils/userAgentTypes.enums.js';

/**
* @typedef {import('../src/adapters/bidderFactory').Bid} Bid
Expand Down Expand Up @@ -219,10 +221,12 @@ export const spec = {
/**
* 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.
* @returns {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions) {
if (syncOptions.iframeEnabled) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
if (syncOptions.iframeEnabled && !skipSync(gdprConsent)) {
return [{
type: 'iframe',
url: USER_SYNC_URL
Expand Down Expand Up @@ -393,4 +397,20 @@ function cmerRender(bid) {
});
}

/**
* Stop sending push_sync requests in case it's either Safari browser OR iOS device OR GDPR applies.
* Data extracted from navigator's userAgent
* @param {Object} gdprConsent Is the GDPR Consent object wrapping gdprApplies {boolean} and consentString {string} attributes.
*/
function skipSync(gdprConsent) {
return (getBrowser() === browserTypes.SAFARI || getOS() === osTypes.IOS) || gdprApplies(gdprConsent);
}

/**
* Check if GDPR applies.
*/
function gdprApplies(gdprConsent) {
return gdprConsent && typeof gdprConsent.gdprApplies === 'boolean' && gdprConsent.gdprApplies;
}

registerBidder(spec);
27 changes: 21 additions & 6 deletions test/spec/modules/yieldoneBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { expect } from 'chai';
import { spec } from 'modules/yieldoneBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { getBrowser, getOS } from '../../../libraries/userAgentUtils/index.js';
import { browserTypes, osTypes } from '../../../libraries/userAgentUtils/userAgentTypes.enums.js';

const ENDPOINT = 'https://y.one.impact-ad.jp/h_bid';
const USER_SYNC_URL = 'https://y.one.impact-ad.jp/push_sync';
const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/dac-video-prebid.min.js';

const DEFAULT_VIDEO_SIZE = {w: 640, h: 360};

describe('yieldoneBidAdapter', function() {
describe('yieldoneBidAdapter', function () {
const adapter = newBidder(spec);

describe('isBidRequestValid', function () {
Expand Down Expand Up @@ -638,12 +640,25 @@ describe('yieldoneBidAdapter', function() {
expect(spec.getUserSyncs({})).to.be.undefined;
});

it('should return a sync url if iframe syncs are enabled', function () {
expect(spec.getUserSyncs({
it('should return a sync url if iframe syncs are enabled and UserAgent is not Safari or iOS', function () {
const result = spec.getUserSyncs({
'iframeEnabled': true
})).to.deep.equal([{
type: 'iframe', url: USER_SYNC_URL
}]);
});

if (getBrowser() === browserTypes.SAFARI || getOS() === osTypes.IOS) {
expect(result).to.be.undefined;
} else {
expect(result).to.deep.equal([{
type: 'iframe', url: USER_SYNC_URL
}]);
}
});

it('should skip sync request in case GDPR applies', function () {
expect(spec.getUserSyncs({'iframeEnabled': true}, [], {
consentString: 'GDPR_CONSENT_STRING',
gdprApplies: true,
})).to.be.undefined;
});
});
});

0 comments on commit 9d733b5

Please sign in to comment.