Skip to content

Commit

Permalink
Smartyads Bid Adapter : add_regions (prebid#10545)
Browse files Browse the repository at this point in the history
* SmartyadsBidAdapter/add_regions

* fix docs

---------

Co-authored-by: vrishko <vasyl.rishko@smartyads.com>
  • Loading branch information
rishko00 and vrishko authored Oct 10, 2023
1 parent 2be3110 commit c4bf6ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
34 changes: 31 additions & 3 deletions modules/smartyadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { ajax } from '../src/ajax.js';

const BIDDER_CODE = 'smartyads';
const AD_URL = 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js';
const adUrls = {
US_EAST: 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
EU: 'https://n2.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
SGP: 'https://n6.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'
}

const URL_SYNC = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a';

function isBidResponseValid(bid) {
Expand All @@ -26,6 +31,25 @@ function isBidResponseValid(bid) {
}
}

function getAdUrlByRegion(bid) {
let adUrl;

if (bid.params.region && adUrls[bid.params.region]) {
adUrl = adUrls[bid.params.region];
} else {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const region = timezone.split('/')[0];
if (region === 'Europe') adUrl = adUrls['EU'];
else adUrl = adUrls['US_EAST'];
} catch (err) {
adUrl = adUrls['US_EAST'];
}
}

return adUrl;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
Expand Down Expand Up @@ -73,8 +97,11 @@ export const spec = {
}
const len = validBidRequests.length;

let adUrl;

for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
if (i === 0) adUrl = getAdUrlByRegion(bid);
let traff = bid.params.traffic || BANNER
placements.push({
placementId: bid.params.sourceid,
Expand All @@ -87,11 +114,12 @@ export const spec = {
placements.schain = bid.schain;
}
}

return {
method: 'POST',
url: AD_URL,
url: adUrl,
data: request
};
}
},

interpretResponse: (serverResponse) => {
Expand Down
18 changes: 12 additions & 6 deletions modules/smartyadsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Module that connects to SmartyAds' demand sources

| Name | Scope | Description | Example |
| :------------ | :------- | :------------------------ | :------------------- |
| `sourceid` | required (for prebid.js) | placement ID | "0" |
| `host` | required (for prebid-server) | const value, set to "prebid" | "prebid" |
| `accountid` | required (for prebid-server) | partner ID | "1901" |
| `sourceid` | required (for prebid.js) | Placement ID | "0" |
| `host` | required (for prebid-server) | Const value, set to "prebid" | "prebid" |
| `accountid` | required (for prebid-server) | Partner ID | "1901" |
| `traffic` | optional (for prebid.js) | Configures the mediaType that should be used. Values can be banner, native or video | "banner" |
| `region` | optional (for prebid.js) | Prefix of the region to which prebid must send requests. Possible values: "US_EAST", "EU" | "US_EAST" |

# Test Parameters
```
Expand All @@ -35,7 +36,9 @@ Module that connects to SmartyAds' demand sources
host: 'prebid',
sourceid: '0',
accountid: '0',
traffic: 'native'
traffic: 'native',
region: 'US_EAST'
}
}
]
Expand All @@ -55,7 +58,8 @@ Module that connects to SmartyAds' demand sources
host: 'prebid',
sourceid: '0',
accountid: '0',
traffic: 'banner'
traffic: 'banner',
region: 'US_EAST'
}
}
]
Expand All @@ -76,7 +80,9 @@ Module that connects to SmartyAds' demand sources
host: 'prebid',
sourceid: '0',
accountid: '0',
traffic: 'video'
traffic: 'video',
region: 'US_EAST'
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion test/spec/modules/smartyadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ describe('SmartyadsAdapter', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js');
expect(serverRequest.url).to.be.oneOf([
'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
'https://n2.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
'https://n6.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'
]);
});
it('Returns valid data if array of bids is valid', function () {
let data = serverRequest.data;
Expand Down

0 comments on commit c4bf6ae

Please sign in to comment.