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

Engageya bid adapter improvements #7656

Merged
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
122 changes: 68 additions & 54 deletions modules/engageyaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
BANNER,
NATIVE
} from '../src/mediaTypes.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { createTrackPixelHtml } from '../src/utils.js';

const {
Expand All @@ -10,14 +7,21 @@ const {
const BIDDER_CODE = 'engageya';
const ENDPOINT_URL = 'https://recs.engageya.com/rec-api/getrecs.json';
const ENDPOINT_METHOD = 'GET';
const SUPPORTED_SIZES = [
[100, 75], [236, 202], [100, 100], [130, 130], [200, 200], [250, 250], [300, 272], [300, 250], [300, 230], [300, 214], [300, 187], [300, 166], [300, 150], [300, 133], [300, 120], [400, 200], [300, 200], [250, 377], [620, 410], [207, 311], [310, 166], [310, 333], [190, 106], [228, 132], [300, 174], [80, 60], [600, 500], [600, 600], [1080, 610], [1080, 610], [624, 350], [650, 1168], [1080, 1920], [300, 374]
];

function getPageUrl() {
var pUrl = window.location.href;
if (isInIframe()) {
pUrl = document.referrer ? document.referrer : pUrl;
function getPageUrl(bidRequest, bidderRequest) {
if (bidRequest.params.pageUrl && bidRequest.params.pageUrl != '[PAGE_URL]') {
return bidRequest.params.pageUrl;
}
pUrl = encodeURIComponent(pUrl);
return pUrl;
if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) {
return bidderRequest.refererInfo.referer;
}
const pageUrl = (isInIframe() && document.referrer)
? document.referrer
: window.location.href;
return encodeURIComponent(pageUrl);
}

function isInIframe() {
Expand All @@ -33,13 +37,14 @@ function getImageSrc(rec) {
return rec.thumbnail_path.indexOf('http') === -1 ? 'https:' + rec.thumbnail_path : rec.thumbnail_path;
}

function getImpressionTrackers(rec) {
function getImpressionTrackers(rec, response) {
const responseTrackers = [response.viewPxl];
if (!rec.trackers) {
return [];
return responseTrackers;
}
const impressionTrackers = rec.trackers.impressionPixels || [];
const viewTrackers = rec.trackers.viewPixels || [];
return [...impressionTrackers, ...viewTrackers];
return [...impressionTrackers, ...viewTrackers, ...responseTrackers];
}

function parseNativeResponse(rec, response) {
Expand All @@ -56,7 +61,7 @@ function parseNativeResponse(rec, response) {
displayUrl: rec.url,
cta: '',
sponsoredBy: rec.displayName,
impressionTrackers: getImpressionTrackers(rec),
impressionTrackers: getImpressionTrackers(rec, response),
};
}

Expand All @@ -74,56 +79,65 @@ function parseBannerResponse(rec, response) {
}
const title = rec.title && rec.title.trim() ? `<div class="eng_tag_ttl" style="display: none">${rec.title}</div>` : '';
const displayName = rec.displayName && title ? `<div class="eng_tag_brnd" style="display: none">${rec.displayName}</div>` : '';
const trackers = getImpressionTrackers(rec)
const trackers = getImpressionTrackers(rec, response)
.map(createTrackPixelHtml)
.join('');
return `<html><body>${style}<div id="ENG_TAG"><a href="${rec.clickUrl}" target=_blank><img class="eng_tag_img" src="${getImageSrc(rec)}" style="width:${response.imageWidth}px;height:${response.imageHeight}px;" alt="${rec.title}"/>${displayName}${title}</a>${trackers}</div></body></html>`;
}

function getImageSize(bidRequest) {
if (bidRequest.sizes && bidRequest.sizes.length > 0) {
return bidRequest.sizes[0];
} else if (bidRequest.nativeParams && bidRequest.nativeParams.image && bidRequest.nativeParams.image.sizes) {
return bidRequest.nativeParams.image.sizes;
}
return [-1, -1];
}

function isValidSize([width, height]) {
if (!width || !height) {
return false;
}
return SUPPORTED_SIZES.some(([supportedWidth, supportedHeight]) => supportedWidth === width && supportedHeight === height);
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
isBidRequestValid: function (bid) {
return bid && bid.params && bid.params.hasOwnProperty('widgetId') && bid.params.hasOwnProperty('websiteId') && !isNaN(bid.params.widgetId) && !isNaN(bid.params.websiteId);

isBidRequestValid: function (bidRequest) {
return bidRequest &&
bidRequest.params &&
bidRequest.params.hasOwnProperty('widgetId') &&
bidRequest.params.hasOwnProperty('websiteId') &&
!isNaN(bidRequest.params.widgetId) &&
!isNaN(bidRequest.params.websiteId) &&
isValidSize(getImageSize(bidRequest));
},

buildRequests: function (validBidRequests, bidderRequest) {
var bidRequests = [];
if (validBidRequests && validBidRequests.length > 0) {
validBidRequests.forEach(function (bidRequest) {
if (bidRequest.params) {
var mediaType = bidRequest.hasOwnProperty('nativeParams') ? 1 : 2;
var imageWidth = -1;
var imageHeight = -1;
if (bidRequest.sizes && bidRequest.sizes.length > 0) {
imageWidth = bidRequest.sizes[0][0];
imageHeight = bidRequest.sizes[0][1];
} else if (bidRequest.nativeParams && bidRequest.nativeParams.image && bidRequest.nativeParams.image.sizes) {
imageWidth = bidRequest.nativeParams.image.sizes[0];
imageHeight = bidRequest.nativeParams.image.sizes[1];
}

var widgetId = bidRequest.params.widgetId;
var websiteId = bidRequest.params.websiteId;
var pageUrl = (bidRequest.params.pageUrl && bidRequest.params.pageUrl != '[PAGE_URL]') ? bidRequest.params.pageUrl : '';
if (!pageUrl) {
pageUrl = (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) ? bidderRequest.refererInfo.referer : getPageUrl();
}
var bidId = bidRequest.bidId;
var finalUrl = ENDPOINT_URL + '?pubid=0&webid=' + websiteId + '&wid=' + widgetId + '&url=' + pageUrl + '&ireqid=' + bidId + '&pbtpid=' + mediaType + '&imw=' + imageWidth + '&imh=' + imageHeight;
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprApplies && bidderRequest.consentString) {
finalUrl += '&is_gdpr=1&gdpr_consent=' + bidderRequest.consentString;
}
bidRequests.push({
url: finalUrl,
method: ENDPOINT_METHOD,
data: ''
});
}
});
if (!validBidRequests) {
return [];
}

return bidRequests;
return validBidRequests.map(bidRequest => {
if (bidRequest.params) {
const mediaType = bidRequest.hasOwnProperty('nativeParams') ? 1 : 2;
const [imageWidth, imageHeight] = getImageSize(bidRequest);
const widgetId = bidRequest.params.widgetId;
const websiteId = bidRequest.params.websiteId;
const pageUrl = getPageUrl(bidRequest, bidderRequest);
const bidId = bidRequest.bidId;
let finalUrl = ENDPOINT_URL + '?pubid=0&webid=' + websiteId + '&wid=' + widgetId + '&url=' + pageUrl + '&ireqid=' + bidId + '&pbtpid=' + mediaType + '&imw=' + imageWidth + '&imh=' + imageHeight;
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprApplies && bidderRequest.consentString) {
finalUrl += '&is_gdpr=1&gdpr_consent=' + bidderRequest.consentString;
}
return {
url: finalUrl,
method: ENDPOINT_METHOD,
data: ''
};
}
}).filter(Boolean);
},

interpretResponse: function (serverResponse, bidRequest) {
Expand All @@ -135,12 +149,12 @@ export const spec = {
return response.recs.map(rec => {
let bid = {
requestId: response.ireqId,
cpm: rec.ecpm,
width: response.imageWidth,
height: response.imageHeight,
creativeId: rec.postId,
cpm: rec.pecpm || (rec.ecpm / 100),
currency: 'USD',
netRevenue: false,
netRevenue: !!rec.pecpm,
ttl: 360,
meta: { advertiserDomains: rec.domain ? [rec.domain] : [] },
}
Expand Down
Loading