Skip to content

Commit

Permalink
Ad Generation: adding new format and adomain support (prebid#7533)
Browse files Browse the repository at this point in the history
* adding new format.

adding test spec.

adding test spec.

* fix adgeneration adapter
  • Loading branch information
banakemi authored and Chris Pabst committed Jan 10, 2022
1 parent 3b630ae commit 15af727
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 54 deletions.
32 changes: 28 additions & 4 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tryAppendQueryString, getBidIdParameter } from '../src/utils.js';
import {tryAppendQueryString, getBidIdParameter} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
Expand All @@ -25,7 +25,7 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
const ADGENE_PREBID_VERSION = '1.1.0';
const ADGENE_PREBID_VERSION = '1.2.0';
let serverRequests = [];
for (let i = 0, len = validBidRequests.length; i < len; i++) {
const validReq = validBidRequests[i];
Expand Down Expand Up @@ -118,13 +118,25 @@ export const spec = {
function createAd(body, bidRequest) {
let ad = body.ad;
if (body.vastxml && body.vastxml.length > 0) {
ad = `<body><div id="apvad-${bidRequest.bidId}"></div>${createAPVTag()}${insertVASTMethod(bidRequest.bidId, body.vastxml)}</body>`;
if (isUpperBillboard(body)) {
const marginTop = bidRequest.params.marginTop ? bidRequest.params.marginTop : '0';
ad = `<body>${createADGBrowserMTag()}${insertVASTMethodForADGBrowserM(body.vastxml, marginTop)}</body>`;
} else {
ad = `<body><div id="apvad-${bidRequest.bidId}"></div>${createAPVTag()}${insertVASTMethodForAPV(bidRequest.bidId, body.vastxml)}</body>`;
}
}
ad = appendChildToBody(ad, body.beacon);
if (removeWrapper(ad)) return removeWrapper(ad);
return ad;
}

function isUpperBillboard(body) {
if (body.location_params && body.location_params.option && body.location_params.option.ad_type) {
return body.location_params.option.ad_type === 'upper_billboard';
}
return false;
}

function isNative(body) {
if (!body) return false;
return body.native_ad && body.native_ad.assets.length > 0;
Expand Down Expand Up @@ -190,7 +202,12 @@ function createAPVTag() {
return apvScript.outerHTML;
}

function insertVASTMethod(targetId, vastXml) {
function createADGBrowserMTag() {
const ADGBrowserMURL = 'https://i.socdm.com/sdk/js/adg-browser-m.js';
return `<script type="text/javascript" src="${ADGBrowserMURL}"></script>`;
}

function insertVASTMethodForAPV(targetId, vastXml) {
let apvVideoAdParam = {
s: targetId
};
Expand All @@ -200,6 +217,13 @@ function insertVASTMethod(targetId, vastXml) {
return script.outerHTML;
}

function insertVASTMethodForADGBrowserM(vastXml, marginTop) {
const script = document.createElement(`script`);
script.type = 'text/javascript';
script.innerHTML = `window.ADGBrowserM.init({vastXml: '${vastXml.replace(/\r?\n/g, '')}', marginTop: '${marginTop}'});`;
return script.outerHTML;
}

/**
*
* @param ad
Expand Down
Loading

0 comments on commit 15af727

Please sign in to comment.