Skip to content

Commit

Permalink
ZetaGlobalSsp Adapter: crop page (prebid#11198)
Browse files Browse the repository at this point in the history
Co-authored-by: Surovenko Alexey <[email protected]>
Co-authored-by: Alexey Surovenko <[email protected]>
  • Loading branch information
3 people committed Mar 14, 2024
1 parent 5018b6b commit 4b4e83e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 25 additions & 1 deletion modules/zeta_global_sspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const spec = {
};
const rInfo = bidderRequest.refererInfo;
// TODO: do the fallbacks make sense here?
payload.site.page = rInfo.page || rInfo.topmostLocation;
payload.site.page = cropPage(rInfo.page || rInfo.topmostLocation);
payload.site.domain = parseDomain(payload.site.page, {noLeadingWww: true});

payload.device.ua = navigator.userAgent;
Expand Down Expand Up @@ -386,6 +386,30 @@ function provideMediaType(zetaBid, bid, bidRequest) {
}
}

function cropPage(page) {
if (page) {
if (page.length > 100) {
page = page.substring(0, 100);
}
if (page.startsWith('https://')) {
page = page.substring(8);
} else if (page.startsWith('http://')) {
page = page.substring(7);
}
if (page.startsWith('www.')) {
page = page.substring(4);
}
for (let i = 3; i < page.length; i++) {
const c = page[i];
if (c === '#' || c === '?') {
return page.substring(0, i);
}
}
return page;
}
return '';
}

function clearEmpties(o) {
for (let k in o) {
if (o[k] === null) {
Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/zeta_global_sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Zeta Ssp Bid Adapter', function () {
sid: 'publisherId',
tagid: 'test_tag_id',
site: {
page: 'testPage'
page: 'http://www.zetaglobal.com/page?param=value'
},
app: {
bundle: 'testBundle'
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('Zeta Ssp Bid Adapter', function () {
id: '123',
site: {
id: 'SITE_ID',
page: 'page.com',
page: 'http://www.zetaglobal.com/page?param=value',
domain: 'domain.com'
},
user: {
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Zeta Ssp Bid Adapter', function () {
id: '123',
site: {
id: 'SITE_ID',
page: 'page.com',
page: 'http://www.zetaglobal.com/page?param=value',
domain: 'domain.com'
},
user: {
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('Zeta Ssp Bid Adapter', function () {
it('Test page and domain in site', function () {
const request = spec.buildRequests(bannerRequest, bannerRequest[0]);
const payload = JSON.parse(request.data);
expect(payload.site.page).to.eql('http://www.zetaglobal.com/page?param=value');
expect(payload.site.page).to.eql('zetaglobal.com/page');
expect(payload.site.domain).to.eql('zetaglobal.com');
});

Expand Down

0 comments on commit 4b4e83e

Please sign in to comment.