Skip to content

Commit

Permalink
cpmstarBidAdapter: added gvlid, additional request data (prebid#11881)
Browse files Browse the repository at this point in the history
* cpmstarBidAdapter - added gvlid, added ortb and banner request data, various cleanups

* cpmstarBidAdapter - fixed schain test for different url encoding

* cpmstarBidAdapter: removed extra blank line
  • Loading branch information
JoshuaMGoldstein authored and DecayConstant committed Jul 18, 2024
1 parent c13fe68 commit e3d3f99
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
88 changes: 52 additions & 36 deletions modules/cpmstarBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import {getBidIdParameter} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';

const BIDDER_CODE = 'cpmstar';

Expand All @@ -12,15 +12,18 @@ const ENDPOINT_PRODUCTION = 'https://server.cpmstar.com/view.aspx';

const DEFAULT_TTL = 300;
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_NET_REVENUE = true;

function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
export const converter = ortbConverter({
context: {
ttl: DEFAULT_TTL,
netRevenue: DEFAULT_NET_REVENUE
}
});

export const spec = {
code: BIDDER_CODE,
gvlid: 1317,
supportedMediaTypes: [BANNER, VIDEO],
pageID: Math.floor(Math.random() * 10e6),

Expand All @@ -43,22 +46,30 @@ export const spec = {

buildRequests: function (validBidRequests, bidderRequest) {
var requests = [];
// This reference to window.top can cause issues when loaded in an iframe if not protected with a try/catch.

for (var i = 0; i < validBidRequests.length; i++) {
var bidRequest = validBidRequests[i];
var referer = bidderRequest.refererInfo.page ? bidderRequest.refererInfo.page : bidderRequest.refererInfo.domain;
referer = encodeURIComponent(referer);
var e = getBidIdParameter('endpoint', bidRequest.params);
var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION;
var mediaType = spec.getMediaType(bidRequest);
var playerSize = spec.getPlayerSize(bidRequest);
var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : '');
var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') +
'&json=c_b&mv=1&poolid=' + getBidIdParameter('placementId', bidRequest.params) +
'&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) +
'&requestid=' + bidRequest.bidId +
'&referer=' + encodeURIComponent(referer);
const referer = bidderRequest.refererInfo.page ? bidderRequest.refererInfo.page : bidderRequest.refererInfo.domain;
const e = utils.getBidIdParameter('endpoint', bidRequest.params);
const ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION;
const url = new URL(ENDPOINT);
const body = {};
const mediaType = spec.getMediaType(bidRequest);
const playerSize = spec.getPlayerSize(bidRequest);
url.searchParams.set('media', mediaType);
if (mediaType == VIDEO) {
url.searchParams.set('fv', 0);
if (playerSize) {
url.searchParams.set('w', playerSize?.[0]);
url.searchParams.set('h', playerSize?.[1]);
}
}
url.searchParams.set('json', 'c_b');
url.searchParams.set('mv', 1);
url.searchParams.set('poolid', utils.getBidIdParameter('placementId', bidRequest.params));
url.searchParams.set('reachedTop', bidderRequest.refererInfo.reachedTop);
url.searchParams.set('requestid', bidRequest.bidId);
url.searchParams.set('referer', referer);

if (bidRequest.schain && bidRequest.schain.nodes) {
var schain = bidRequest.schain;
Expand All @@ -67,45 +78,49 @@ export const spec = {
for (var i2 = 0; i2 < schain.nodes.length; i2++) {
var node = schain.nodes[i2];
schainString += '!' +
fixedEncodeURIComponent(node.asi || '') + ',' +
fixedEncodeURIComponent(node.sid || '') + ',' +
fixedEncodeURIComponent(node.hp || '') + ',' +
fixedEncodeURIComponent(node.rid || '') + ',' +
fixedEncodeURIComponent(node.name || '') + ',' +
fixedEncodeURIComponent(node.domain || '');
(node.asi || '') + ',' +
(node.sid || '') + ',' +
(node.hp || '') + ',' +
(node.rid || '') + ',' +
(node.name || '') + ',' +
(node.domain || '');
}
url += '&schain=' + schainString;
url.searchParams.set('schain', schainString);
}

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString != null) {
url += '&gdpr_consent=' + bidderRequest.gdprConsent.consentString;
url.searchParams.set('gdpr_consent', bidderRequest.gdprConsent.consentString);
}
if (bidderRequest.gdprConsent.gdprApplies != null) {
url += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0);
url.searchParams.set('gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}
}

if (bidderRequest.uspConsent != null) {
url += '&us_privacy=' + bidderRequest.uspConsent;
url.searchParams.set('us_privacy', bidderRequest.uspConsent);
}

if (config.getConfig('coppa')) {
url += '&tfcd=' + (config.getConfig('coppa') ? 1 : 0);
url.searchParams.set('tfcd', (config.getConfig('coppa') ? 1 : 0));
}

let body = {};
let adUnitCode = bidRequest.adUnitCode;
if (adUnitCode) {
body.adUnitCode = adUnitCode;
}
if (mediaType == VIDEO) {
body.video = utils.deepAccess(bidRequest, 'mediaTypes.video');
} else if (mediaType == BANNER) {
body.banner = utils.deepAccess(bidRequest, 'mediaTypes.banner');
}

const ortb = converter.toORTB({ bidderRequest, bidRequests: [bidRequest] });
Object.assign(body, ortb);

requests.push({
method: 'POST',
url: url,
url: url.toString(),
bidRequest: bidRequest,
data: body
});
Expand Down Expand Up @@ -144,7 +159,7 @@ export const spec = {
width: rawBid.width || 0,
height: rawBid.height || 0,
currency: rawBid.currency ? rawBid.currency : DEFAULT_CURRENCY,
netRevenue: rawBid.netRevenue ? rawBid.netRevenue : true,
netRevenue: rawBid.netRevenue ? rawBid.netRevenue : DEFAULT_NET_REVENUE,
ttl: rawBid.ttl ? rawBid.ttl : DEFAULT_TTL,
creativeId: rawBid.creativeid || 0,
meta: {
Expand Down Expand Up @@ -191,4 +206,5 @@ export const spec = {
}

};

registerBidder(spec);
5 changes: 1 addition & 4 deletions modules/cpmstarBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
```
Module Name: Cpmstar Bidder Adapter
Module Type: Bidder Adapter
Maintainer: josh@cpmstar.com
gdpr_supported: true
usp_supported: true
coppa_supported: true
Maintainer: prebid@cpmstar.com
```

# Description
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/cpmstarBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Cpmstar Bid Adapter', function () {
};
var requests = spec.buildRequests(reqs, bidderRequest);
expect(requests[0]).to.have.property('url');
expect(requests[0].url).to.include('&schain=1.0,1!exchange1.com,1234,1,,,!exchange2.com,abcd,1,,,');
expect(requests[0].url).to.include('&schain=1.0%2C1%21exchange1.com%2C1234%2C1%2C%2C%2C%21exchange2.com%2Cabcd%2C1%2C%2C%2C');
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit e3d3f99

Please sign in to comment.