Skip to content

Commit e2d074d

Browse files
authored
Smaato: Add iframe UserSyncs (prebid#12924)
1 parent 0f7c725 commit e2d074d

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

modules/smaatoBidAdapter.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import {ortbConverter} from '../libraries/ortbConverter/converter.js';
1919

2020
const BIDDER_CODE = 'smaato';
2121
const SMAATO_ENDPOINT = 'https://prebid.ad.smaato.net/oapi/prebid';
22-
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_3.2'
22+
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_3.3'
2323
const TTL = 300;
2424
const CURRENCY = 'USD';
2525
const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO, NATIVE];
26-
const SYNC_URL = 'https://s.ad.smaato.net/c/?adExInit=p'
26+
const IMAGE_SYNC_URL = 'https://s.ad.smaato.net/c/?adExInit=p'
27+
const IFRAME_SYNC_URL = 'https://s.ad.smaato.net/i/?adExInit=p'
2728

2829
export const spec = {
2930
code: BIDDER_CODE,
@@ -197,7 +198,7 @@ export const spec = {
197198
* @return {UserSync[]} The user syncs which should be dropped.
198199
*/
199200
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
200-
if (syncOptions && syncOptions.pixelEnabled) {
201+
if (syncOptions) {
201202
let gdprParams = '';
202203
if (gdprConsent && gdprConsent.consentString) {
203204
if (typeof gdprConsent.gdprApplies === 'boolean') {
@@ -207,10 +208,22 @@ export const spec = {
207208
}
208209
}
209210

210-
return [{
211-
type: 'image',
212-
url: SYNC_URL + gdprParams
213-
}];
211+
if (syncOptions.iframeEnabled) {
212+
let maxUrlsParam = '';
213+
if (config.getConfig('userSync') && config.getConfig('userSync').syncsPerBidder) {
214+
maxUrlsParam = `&maxUrls=${config.getConfig('userSync').syncsPerBidder}`;
215+
}
216+
217+
return [{
218+
type: 'iframe',
219+
url: IFRAME_SYNC_URL + gdprParams + maxUrlsParam
220+
}];
221+
} else if (syncOptions.pixelEnabled) {
222+
return [{
223+
type: 'image',
224+
url: IMAGE_SYNC_URL + gdprParams
225+
}];
226+
}
214227
}
215228

216229
return [];

test/spec/modules/smaatoBidAdapter_spec.js

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import 'modules/consentManagementTcf.js';
1212
import 'modules/consentManagementUsp.js';
1313
import 'modules/schain.js';
1414

15-
const SYNC_URL = 'https://s.ad.smaato.net/c/?adExInit=p'
15+
const IMAGE_SYNC_URL = 'https://s.ad.smaato.net/c/?adExInit=p'
16+
const IFRAME_SYNC_URL = 'https://s.ad.smaato.net/i/?adExInit=p'
1617

1718
const ADTYPE_IMG = 'Img';
1819
const ADTYPE_VIDEO = 'Video';
@@ -1670,41 +1671,101 @@ describe('smaatoBidAdapterTest', () => {
16701671
});
16711672

16721673
describe('getUserSyncs', () => {
1673-
it('when pixelEnabled false then returns no pixels', () => {
1674+
afterEach(() => {
1675+
config.resetConfig();
1676+
})
1677+
1678+
it('when pixelEnabled and iframeEnabled false then returns no syncs', () => {
16741679
expect(spec.getUserSyncs()).to.be.empty
16751680
})
16761681

1677-
it('when pixelEnabled true then returns pixel', () => {
1682+
it('when pixelEnabled true then returns image sync', () => {
16781683
expect(spec.getUserSyncs({pixelEnabled: true}, null, null, null)).to.deep.equal(
16791684
[
16801685
{
16811686
type: 'image',
1682-
url: SYNC_URL
1687+
url: IMAGE_SYNC_URL
16831688
}
16841689
]
16851690
)
16861691
})
16871692

1688-
it('when pixelEnabled true and gdprConsent then returns pixel with gdpr params', () => {
1693+
it('when iframeEnabled true then returns iframe sync', () => {
1694+
expect(spec.getUserSyncs({iframeEnabled: true}, null, null, null)).to.deep.equal(
1695+
[
1696+
{
1697+
type: 'iframe',
1698+
url: IFRAME_SYNC_URL
1699+
}
1700+
]
1701+
)
1702+
})
1703+
1704+
it('when iframeEnabled true and syncsPerBidder then returns iframe sync', () => {
1705+
config.setConfig({userSync: {syncsPerBidder: 5}});
1706+
expect(spec.getUserSyncs({iframeEnabled: true}, null, null, null)).to.deep.equal(
1707+
[
1708+
{
1709+
type: 'iframe',
1710+
url: `${IFRAME_SYNC_URL}&maxUrls=5`
1711+
}
1712+
]
1713+
)
1714+
})
1715+
1716+
it('when iframeEnabled and pixelEnabled true then returns iframe sync', () => {
1717+
expect(spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, null, null, null)).to.deep.equal(
1718+
[
1719+
{
1720+
type: 'iframe',
1721+
url: IFRAME_SYNC_URL
1722+
}
1723+
]
1724+
)
1725+
})
1726+
1727+
it('when pixelEnabled true and gdprConsent then returns image sync with gdpr params', () => {
16891728
expect(spec.getUserSyncs({pixelEnabled: true}, null, {gdprApplies: true, consentString: CONSENT_STRING}, null)).to.deep.equal(
16901729
[
16911730
{
16921731
type: 'image',
1693-
url: `${SYNC_URL}&gdpr=1&gdpr_consent=${CONSENT_STRING}`
1732+
url: `${IMAGE_SYNC_URL}&gdpr=1&gdpr_consent=${CONSENT_STRING}`
16941733
}
16951734
]
16961735
)
16971736
})
16981737

1699-
it('when pixelEnabled true and gdprConsent without gdpr then returns pixel with gdpr_consent', () => {
1738+
it('when iframeEnabled true and gdprConsent then returns iframe with gdpr params', () => {
1739+
expect(spec.getUserSyncs({iframeEnabled: true}, null, {gdprApplies: true, consentString: CONSENT_STRING}, null)).to.deep.equal(
1740+
[
1741+
{
1742+
type: 'iframe',
1743+
url: `${IFRAME_SYNC_URL}&gdpr=1&gdpr_consent=${CONSENT_STRING}`
1744+
}
1745+
]
1746+
)
1747+
})
1748+
1749+
it('when pixelEnabled true and gdprConsent without gdpr then returns pixel sync with gdpr_consent', () => {
17001750
expect(spec.getUserSyncs({pixelEnabled: true}, null, {consentString: CONSENT_STRING}, null), null).to.deep.equal(
17011751
[
17021752
{
17031753
type: 'image',
1704-
url: `${SYNC_URL}&gdpr_consent=${CONSENT_STRING}`
1754+
url: `${IMAGE_SYNC_URL}&gdpr_consent=${CONSENT_STRING}`
17051755
}
17061756
]
17071757
)
17081758
})
1759+
1760+
it('when iframeEnabled true and gdprConsent without gdpr then returns iframe sync with gdpr_consent', () => {
1761+
expect(spec.getUserSyncs({iframeEnabled: true}, null, {consentString: CONSENT_STRING}, null), null).to.deep.equal(
1762+
[
1763+
{
1764+
type: 'iframe',
1765+
url: `${IFRAME_SYNC_URL}&gdpr_consent=${CONSENT_STRING}`
1766+
}
1767+
]
1768+
)
1769+
})
17091770
})
17101771
});

0 commit comments

Comments
 (0)