Skip to content

Commit

Permalink
eTarget Bid Adapter: add "getMetaData" function to adapter, support f…
Browse files Browse the repository at this point in the history
…or advertiserDomains (#6901)
  • Loading branch information
etargetse authored Jun 1, 2021
1 parent 7647b97 commit 17e446d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
39 changes: 37 additions & 2 deletions modules/etargetBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

Expand Down Expand Up @@ -57,10 +57,40 @@ export const spec = {
data: bidderRequest,
bids: validBidRequests,
netRevenue: netRevenue,
metaData: getMetaData(),
bidder: 'etarget',
gdpr: gdprObject
};

function getMetaData() {
var mts = {};
var hmetas = document.getElementsByTagName('meta');
var wnames = ['title', 'og:title', 'description', 'og:description', 'og:url', 'base', 'keywords'];
try {
for (var k in hmetas) {
if (typeof hmetas[k] == 'object') {
var mname = hmetas[k].name || hmetas[k].getAttribute('property');
var mcont = hmetas[k].content;
if (!!mname && mname != 'null' && !!mcont) {
if (wnames.indexOf(mname) >= 0) {
if (!mts[mname]) {
mts[mname] = [];
}
mts[mname].push(mcont);
}
}
}
}
mts['title'] = [(document.getElementsByTagName('title')[0] || []).innerHTML];
mts['base'] = [(document.getElementsByTagName('base')[0] || {}).href];
mts['referer'] = [document.location.href];
mts['ortb2'] = (config.getConfig('ortb2') || {});
} catch (e) {
mts.error = e;
}
return mts;
}

function formRequestUrl(reqData) {
var key;
var url = [];
Expand Down Expand Up @@ -107,9 +137,14 @@ export const spec = {
bidObject.gdpr = bidRequest.gdpr.gdpr;
bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent;
}

if (bid.adomain) {
utils.deepSetValue(bidObject, 'meta.advertiserDomains', Array.isArray(bid.adomain) ? bid.adomain : [bid.adomain]);
}
bidRespones.push(bidObject);
}
}

return bidRespones;

function verifySize(adItem, validSizes) {
Expand Down
5 changes: 5 additions & 0 deletions test/spec/modules/etargetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe('etarget adapter', function () {
assert.lengthOf(parsedUrl.items, 7);
});

it('should be an object', function () {
let request = spec.buildRequests(bids);
assert.isNotNull(request.metaData);
});

it('should handle global request parameters', function () {
let parsedUrl = parseUrl(spec.buildRequests([bids[0]]).url);
assert.equal(parsedUrl.path, 'https://sk.search.etargetnet.com/hb');
Expand Down

0 comments on commit 17e446d

Please sign in to comment.