Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamma Bid Adapter : Support multi endpoint by region #11263

Merged
merged 7 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions modules/gammaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
*/

const ENDPOINT = 'https://hb.gammaplatform.com';
const ENDPOINT_USERSYNC = 'https://cm-supply-web.gammaplatform.com';
const BIDDER_CODE = 'gamma';
const ENDPOINTS = {
SGP: 'https://hb.gammaplatform.com',
JPN: 'https://hb-jp.gammaplatform.com',
US_WEST: 'https://hb-us.gammaplatform.com',
EU: 'https://hb-eu.gammaplatform.com'
}

export const spec = {
code: BIDDER_CODE,
Expand All @@ -33,8 +37,10 @@ export const spec = {
buildRequests: function(bidRequests, bidderRequest) {
const serverRequests = [];
const bidderRequestReferer = bidderRequest?.refererInfo?.page || '';
let ENDPOINT;
for (var i = 0, len = bidRequests.length; i < len; i++) {
const gaxObjParams = bidRequests[i];
ENDPOINT = getAdUrlByRegion(gaxObjParams);
serverRequests.push({
method: 'GET',
url: ENDPOINT + '/adx/request?wid=' + gaxObjParams.params.siteId + '&zid=' + gaxObjParams.params.zoneId + '&hb=pbjs&bidid=' + gaxObjParams.bidId + '&urf=' + encodeURIComponent(bidderRequestReferer)
Expand All @@ -60,16 +66,45 @@ export const spec = {
}

return bids;
},
}
}

getUserSyncs: function(syncOptions) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: ENDPOINT_USERSYNC + '/adx/usersync'
}];
/**
* Get endpoint url by region
* @param bid
* @return aUrl
*/
function getAdUrlByRegion(bid) {
let ENDPOINT;

if (bid.params.region && ENDPOINTS[bid.params.region]) {
ENDPOINT = ENDPOINTS[bid.params.region];
} else {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const region = timezone.split('/')[0];

switch (region) {
case 'Europe':
ENDPOINT = ENDPOINTS['EU'];
break;
case 'Australia':
ENDPOINT = ENDPOINTS['JPN'];
break;
case 'Asia':
ENDPOINT = ENDPOINTS['SGP'];
break;
case 'America':
ENDPOINT = ENDPOINTS['US_WEST'];
break;
default: ENDPOINT = ENDPOINTS['SGP'];
}
} catch (err) {
ENDPOINT = ENDPOINTS['SGP'];
}
}

return ENDPOINT;
}

/**
Expand Down
23 changes: 17 additions & 6 deletions modules/gammaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Connects to Gamma exchange for bids.

Gamma bid adapter supports Banner, Video.

# Parameters

| Name | Scope | Description | Example |
| :------------ | :------- | :------------------------ | :------------------- |
| `zoneId` | required | Zone ID | "1398219417" |
| `siteId` | required | Website ID | "1398219351" |
| `region` | optional (for prebid.js) | Prefix of the region to which prebid must send requests. Possible values: "SGP", "JPN", "US_WEST", "EU" | "SGP" |

# Test Parameters: For Banner
```
var adUnits = [{
Expand All @@ -22,8 +30,9 @@ var adUnits = [{
bids: [{
bidder: 'gamma',
params: {
siteId: '1465446377',
zoneId: '1515999290'
siteId: '1398219351',
zoneId: '1398219417',
region: 'SGP'
}
}]

Expand All @@ -39,8 +48,9 @@ var adUnits = [{
bids: [{
bidder: 'gamma',
params: {
siteId: '1465446377',
zoneId: '1493280341'
siteId: '1398219351',
zoneId: '1614755846',
region: 'SGP'
}
}]

Expand All @@ -59,8 +69,9 @@ In order to receive bids please map localhost to (any) test domain.
bids: [{
bidder: 'gamma',
params: {
siteId: '1465446377',
zoneId: '1515999290'
siteId: '1398219351',
zoneId: '1398219417',
region: 'SGP'
}
}]
}];
Expand Down
7 changes: 4 additions & 3 deletions test/spec/modules/gammaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ describe('gammaBidAdapter', function() {
let bid = {
'bidder': 'gamma',
'params': {
siteId: '1465446377',
zoneId: '1515999290'
siteId: '1398219351',
zoneId: '1398219417',
region: 'SGP'
},
'adUnitCode': 'adunit-code',
'sizes': [
Expand Down Expand Up @@ -84,7 +85,7 @@ describe('gammaBidAdapter', function() {
'width': 300,
'height': 250,
'creativeId': '1515999070',
'dealId': 'gax-paj2qarjf2g',
'dealId': 'gax-lvpjgs5b9k4n',
'currency': 'USD',
'netRevenue': true,
'ttl': 300,
Expand Down