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

AJA Bid Adapter: add Global Placement ID support, remove native/video ad support #10945

Merged
merged 2 commits into from
Jan 23, 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
157 changes: 43 additions & 114 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {createTrackPixelHtml, logError, logWarn, deepAccess, getBidIdParameter} from '../src/utils.js';
import { Renderer } from '../src/Renderer.js';
import {createTrackPixelHtml, logError, getBidIdParameter} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js';
import { BANNER } from '../src/mediaTypes.js';
import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js';

const BidderCode = 'aja';
Expand All @@ -25,7 +24,7 @@ const BannerSizeMap = {

export const spec = {
code: BidderCode,
supportedMediaTypes: [VIDEO, BANNER, NATIVE],
supportedMediaTypes: [BANNER],

/**
* Determines whether or not the given bid has all the params needed to make a valid request.
Expand All @@ -51,32 +50,29 @@ export const spec = {

for (let i = 0, len = validBidRequests.length; i < len; i++) {
const bidRequest = validBidRequests[i];
if (
(bidRequest.mediaTypes?.native || bidRequest.mediaTypes?.video) &&
bidRequest.mediaTypes?.banner) {
continue
}

let queryString = '';

const asi = getBidIdParameter('asi', bidRequest.params);
queryString = tryAppendQueryString(queryString, 'asi', asi);
queryString = tryAppendQueryString(queryString, 'skt', SDKType);
queryString = tryAppendQueryString(queryString, 'gpid', bidRequest.ortb2Imp?.ext?.gpid)
queryString = tryAppendQueryString(queryString, 'tid', bidRequest.ortb2Imp?.ext?.tid)
queryString = tryAppendQueryString(queryString, 'cdep', bidRequest.ortb2?.device?.ext?.cdep)
queryString = tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId);
queryString = tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$');

if (pageUrl) {
queryString = tryAppendQueryString(queryString, 'page_url', pageUrl);
}

const banner = deepAccess(bidRequest, `mediaTypes.${BANNER}`)
if (banner) {
const adFormatIDs = [];
for (const size of banner.sizes || []) {
if (size.length !== 2) {
continue
}

const adFormatID = BannerSizeMap[`${size[0]}x${size[1]}`];
if (adFormatID) {
adFormatIDs.push(adFormatID);
}
}
const adFormatIDs = pickAdFormats(bidRequest)
if (adFormatIDs && adFormatIDs.length > 0) {
queryString = tryAppendQueryString(queryString, 'ad_format_ids', adFormatIDs.join(','));
}

Expand All @@ -87,7 +83,7 @@ export const spec = {
}));
}

const sua = deepAccess(bidRequest, 'ortb2.device.sua');
const sua = bidRequest.ortb2?.device?.sua
if (sua) {
queryString = tryAppendQueryString(queryString, 'sua', JSON.stringify(sua));
}
Expand All @@ -110,90 +106,34 @@ export const spec = {
}

const ad = bidderResponseBody.ad;
if (AdType.Banner !== ad.ad_type) {
return []
}

const bannerAd = bidderResponseBody.ad.banner;
const bid = {
requestId: ad.prebid_id,
mediaType: BANNER,
ad: bannerAd.tag,
width: bannerAd.w,
height: bannerAd.h,
cpm: ad.price,
creativeId: ad.creative_id,
dealId: ad.deal_id,
currency: ad.currency || 'USD',
netRevenue: true,
ttl: 300, // 5 minutes
meta: {
advertiserDomains: []
advertiserDomains: bannerAd.adomain,
},
}

if (AdType.Video === ad.ad_type) {
const videoAd = bidderResponseBody.ad.video;
Object.assign(bid, {
vastXml: videoAd.vtag,
width: videoAd.w,
height: videoAd.h,
renderer: newRenderer(bidderResponseBody),
adResponse: bidderResponseBody,
mediaType: VIDEO
});

Array.prototype.push.apply(bid.meta.advertiserDomains, videoAd.adomain)
} else if (AdType.Banner === ad.ad_type) {
const bannerAd = bidderResponseBody.ad.banner;
Object.assign(bid, {
width: bannerAd.w,
height: bannerAd.h,
ad: bannerAd.tag,
mediaType: BANNER
try {
bannerAd.imps.forEach(impTracker => {
const tracker = createTrackPixelHtml(impTracker);
bid.ad += tracker;
});
try {
bannerAd.imps.forEach(impTracker => {
const tracker = createTrackPixelHtml(impTracker);
bid.ad += tracker;
});
} catch (error) {
logError('Error appending tracking pixel', error);
}

Array.prototype.push.apply(bid.meta.advertiserDomains, bannerAd.adomain)
} else if (AdType.Native === ad.ad_type) {
const nativeAds = ad.native.template_and_ads.ads;
if (nativeAds.length === 0) {
return [];
}

const nativeAd = nativeAds[0];
const assets = nativeAd.assets;

Object.assign(bid, {
mediaType: NATIVE
});

bid.native = {
title: assets.title,
body: assets.description,
cta: assets.cta_text,
sponsoredBy: assets.sponsor,
clickUrl: assets.lp_link,
impressionTrackers: nativeAd.imps,
privacyLink: assets.adchoice_url
};

if (assets.img_main !== undefined) {
bid.native.image = {
url: assets.img_main,
width: parseInt(assets.img_main_width, 10),
height: parseInt(assets.img_main_height, 10)
};
}

if (assets.img_icon !== undefined) {
bid.native.icon = {
url: assets.img_icon,
width: parseInt(assets.img_icon_width, 10),
height: parseInt(assets.img_icon_height, 10)
};
}

Array.prototype.push.apply(bid.meta.advertiserDomains, nativeAd.adomain)
} catch (error) {
logError('Error appending tracking pixel', error);
}

return [bid];
Expand Down Expand Up @@ -229,34 +169,23 @@ export const spec = {
},
}

function newRenderer(bidderResponse) {
const renderer = Renderer.install({
id: bidderResponse.ad.prebid_id,
url: bidderResponse.ad.video.purl,
loaded: false,
});
function pickAdFormats(bidRequest) {
let sizes = bidRequest.sizes || []
sizes.push(...(bidRequest.mediaTypes?.banner?.sizes || []))

try {
renderer.setRender(outstreamRender);
} catch (err) {
logWarn('Prebid Error calling setRender on newRenderer', err);
}
const adFormatIDs = [];
for (const size of sizes) {
if (size.length !== 2) {
continue
}

return renderer;
}
const adFormatID = BannerSizeMap[`${size[0]}x${size[1]}`];
if (adFormatID) {
adFormatIDs.push(adFormatID);
}
}

function outstreamRender(bid) {
bid.renderer.push(() => {
window['aja_vast_player'].init({
vast_tag: bid.adResponse.ad.video.vtag,
ad_unit_code: bid.adUnitCode, // target div id to render video
width: bid.width,
height: bid.height,
progress: bid.adResponse.ad.video.progress,
loop: bid.adResponse.ad.video.loop,
inread: bid.adResponse.ad.video.inread
});
});
return [...new Set(adFormatIDs)]
}

registerBidder(spec);
60 changes: 1 addition & 59 deletions modules/ajaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Maintainer: ssp_support@aja-kk.co.jp

# Description
Connects to Aja exchange for bids.
Aja bid adapter supports Banner and Outstream Video.
Aja bid adapter supports Banner.

# Test Parameters
```js
Expand All @@ -29,64 +29,6 @@ var adUnits = [
asi: 'tk82gbLmg'
}
}]
},
// Video outstream adUnit
{
code: 'prebid_video',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [300, 250]
}
},
bids: [{
bidder: 'aja',
params: {
asi: '1-KwEG_iR'
}
}]
},
// Native adUnit
{
code: 'prebid_native',
mediaTypes: {
native: {
image: {
required: true,
sendId: false
},
title: {
required: true,
sendId: true
},
sponsoredBy: {
required: false,
sendId: true
},
clickUrl: {
required: false,
sendId: true
},
body: {
required: false,
sendId: true
},
icon: {
required: false,
sendId: false
},
privacyLink: {
required: true,
sendId: true
},
}
},
bids: [{
bidder: 'aja',
params: {
asi: 'qxueUGliR'
}
}]
}
];
```
Loading