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

TE Medya Prebid Adapter #6168

Merged
merged 5 commits into from
Jan 8, 2021
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
144 changes: 144 additions & 0 deletions modules/temedyaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';

const BIDDER_CODE = 'temedya';
const ENDPOINT_URL = 'https://adm.vidyome.com/';
const ENDPOINT_METHOD = 'GET';
const CURRENCY = 'TRY';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.widgetId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(req => {
const mediaType = this._isBannerRequest(req) ? 'display' : NATIVE;
const data = {
wid: req.params.widgetId,
type: mediaType,
count: (req.params.count > 6 ? 6 : req.params.count) || 1,
mediaType: mediaType,
requestid: req.bidId
};
if (mediaType === 'display') {
data.sizes = utils.parseSizesInput(
req.mediaTypes && req.mediaTypes.banner && req.mediaTypes.banner.sizes
).join('|')
}
/** @type {ServerRequest} */
return {
method: ENDPOINT_METHOD,
url: ENDPOINT_URL,
data: utils.parseQueryStringParameters(data),
options: { withCredentials: false, requestId: req.bidId, mediaType: mediaType }
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
try {
const bidResponse = serverResponse.body;
const bidResponses = [];
if (bidResponse && bidRequest.options.mediaType == NATIVE) {
bidResponse.ads.forEach(function(ad) {
bidResponses.push({
requestId: bidRequest.options.requestId,
cpm: parseFloat(ad.assets.cpm) || 1,
width: 320,
height: 240,
creativeId: ad.assets.id,
currency: ad.currency || CURRENCY,
netRevenue: false,
mediaType: NATIVE,
ttl: 360,
native: {
title: ad.assets.title,
body: ad.assets.body || '',
icon: {
url: ad.assets.files[0],
width: 320,
height: 240
},
image: {
url: ad.assets.files[0],
width: 320,
height: 240
},
privacyLink: '',
clickUrl: ad.assets.click_url,
displayUrl: ad.assets.click_url,
cta: '',
sponsoredBy: ad.assets.sponsor || '',
impressionTrackers: [bidResponse.base.widget.impression + '&ids=' + ad.id + ':' + ad.assets.id],
},
});
});
} else if (bidResponse && bidRequest.options.mediaType == 'display') {
bidResponse.ads.forEach(function(ad) {
let w = ad.assets.width || 300;
let h = ad.assets.height || 250;
let htmlTag = '<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" href="https://widget.cdn.vidyome.com/builds/neytivme.css"></head>';
htmlTag += '<body><div id="tem_banner" class="size' + w + '-' + h + '" style="width:' + w + 'px;height:' + h + 'px">';
htmlTag += '<i onclick="window.open(\'https://www.temedya.com\', \'_blank\')">TE Medya</i>';
htmlTag += '<a href="' + ad.assets.click_url + '" target="_blank">';
htmlTag += '<div class="image-with-text">';
htmlTag += '<div class="tem-img"><img src="' + ad.assets.files[0] + '" style="width:' + w + 'px;height:' + h + 'px;"/></div>';
if (ad.assets.title) {
htmlTag += '<div class="text-elements">';
htmlTag += '<h2>' + ad.assets.title + '</h2>';
htmlTag += '<p>' + (ad.assets.sponsor || '') + '</p>';
htmlTag += '<em><canvas height="100" width="100"></canvas></em>';
htmlTag += '</div>';
};
htmlTag += '</div></a><img style="display: none;" src="' + bidResponse.base.widget.impression + '&ids=' + ad.id + ':' + ad.assets.id + '">';
htmlTag += '</div></body></html>';
bidResponses.push({
requestId: bidRequest.options.requestId,
cpm: parseFloat(ad.assets.cpm) || 1,
width: w,
height: h,
creativeId: ad.assets.id,
currency: ad.currency || CURRENCY,
netRevenue: false,
ttl: 360,
mediaType: BANNER,
ad: htmlTag
});
});
}
return bidResponses;
} catch (err) {
utils.logError(err);
return [];
}
},
/**
* @param {BidRequest} req
* @return {boolean}
* @private
*/
_isBannerRequest(req) {
return !!(req.mediaTypes && req.mediaTypes.banner);
}
}
registerBidder(spec);
64 changes: 64 additions & 0 deletions modules/temedyaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Overview

Module Name: TE Medya Bidder Adapter
Module Type: Bidder Adapter
Maintainer: prebid@temedya.com

# Description

Module that connects to TE Medya's demand sources.

TE Medya supports Native and Banner.


# Test Parameters
# Native
```

var adUnits = [
{
code:'tme_div_id',
mediaTypes:{
native: {
title: {
required: true
}
}
},
bids:[
{
bidder: 'temedya',
params: {
widgetId: 753497,
count: 1
}
}
]
}
];
```
# Test Parameters
# Banner
```

var adUnits = [
{
code:'tme_div_id',
mediaTypes:{
banner: {
banner: {
sizes:[300, 250]
}
}
},
bids:[
{
bidder: 'temedya',
params: {
widgetId: 753497
}
}
]
}
];
```
177 changes: 177 additions & 0 deletions test/spec/modules/temedyaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import {expect} from 'chai';
import {spec} from 'modules/temedyaBidAdapter.js';
import * as utils from 'src/utils.js';

const ENDPOINT_URL = 'https://adm.vidyome.com/';

export const _getUrlVars = function(url) {
var hash;
var myJson = {};
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
myJson[hash[0]] = hash[1];
}
return myJson;
}

describe('temedya adapter', function() {
let bidRequests;
let nativeBidRequests;

beforeEach(function() {
bidRequests = [
{
bidder: 'temedya',
params: {
widgetId: 753497,
count: 1
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
}
]

nativeBidRequests = [
{
bidder: 'temedya',
params: {
widgetId: 753497,
count: 1
},
nativeParams: {
title: {
required: true
},
image: {
required: true
}
}
}
]
})

describe('isBidRequestValid', function () {
it('valid bid case', function () {
let validBid = {
bidder: 'temedya',
params: {
widgetId: 753497,
count: 1
}
}
let isValid = spec.isBidRequestValid(validBid);
expect(isValid).to.equal(true);
});

it('invalid bid case: widgetId and countId is not passed', function() {
let validBid = {
bidder: 'temedya',
params: {
}
}
let isValid = spec.isBidRequestValid(validBid);
expect(isValid).to.equal(false);
})
})

describe('buildRequests', function () {
it('sends bid request to ENDPOINT via GET', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.url).to.include(ENDPOINT_URL);
expect(request.method).to.equal('GET');
});

it('buildRequests function should not modify original bidRequests object', function () {
let originalBidRequests = utils.deepClone(bidRequests);
let request = spec.buildRequests(bidRequests);
expect(bidRequests).to.deep.equal(originalBidRequests);
});

it('buildRequests function should not modify original nativeBidRequests object', function () {
let originalBidRequests = utils.deepClone(nativeBidRequests);
let request = spec.buildRequests(nativeBidRequests);
expect(nativeBidRequests).to.deep.equal(originalBidRequests);
});

it('Request params check', function() {
let request = spec.buildRequests(bidRequests)[0];
const data = _getUrlVars(request.url)
data.type = 'native';
data.wid = bidRequests[0].params.widgetId;
data.count = bidRequests[0].params.count;
})
})

describe('interpretResponse', function () {
let response = {
ads: [
{
'id': 30,
'name': 'Pro Trader Desktop Ocak',
'assets': {
'sponsor': 'Yatırım Bülteni',
'cpm': '0.30188070875464',
'name': 'SLC2-DESKTOP',
'files': [
'https://dsp-vidyome.cdn.vidyome.com/dsp/assets/84066_SLC2_640X480_82KB.jpg'
],
'id': 9,
'title': '6 ayda zengin oldu! Günde 2 saat çalışarak bilgisayar başında zengin oldu.',
'body': 'Sizde yapabilirsiniz!',
'landing_url': 'https://bit.ly/3l6RhKG',
'click_url': 'https://adclick.adm.vidyome.com/collect?campaignId=30&creativeId=9&widId=122129&v=1609960813742&uri=https%3A%2F%2Fbit.ly%2F3l6RhKG%3Futm_source%3DVidyome%26utm_medium%3Dnative%26utm_campaign%3D30%26utm_term%3D9%26utm_content%3D122129'
},
'conversion_urls': [

],
'impression_urls': [

]
}
],
base: {
'isSmartphone': false,
'isTablet': false,
'isDesktop': true,
'isConnectedTv': false,
'country': 'tr',
'wid': 753497,
'type': 'native',
'locale': 'tr',
'widget': {
'click': 'https://stats.vidyome.com/s/widgets/collect?widgetId=122129&eventType=click',
'impression': 'https://impression.adm.vidyome.com/collect/v1?widgetId=122129'
}
},
};

it('should get correct bid response', function () {
let expectedResponse = [
{
'requestId': '1d236f7890b',
'cpm': 0.0920,
'width': 300,
'height': 250,
'netRevenue': false,
'mediaType': 'native',
'currency': 'TRY',
'creativeId': '<!-- CREATIVE ID -->',
'ttl': 700,
'ad': '<!-- ADS TAG -->'
}
];
let request = spec.buildRequests(bidRequests)[0];
let result = spec.interpretResponse({body: response}, request);
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
expect(result[0].cpm).to.not.equal(null);
expect(result[0].creativeId).to.not.equal(null);
expect(result[0].ad).to.not.equal(null);
expect(result[0].currency).to.equal('TRY');
expect(result[0].netRevenue).to.equal(false);
});
})
})