Skip to content
Open
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
18,108 changes: 44 additions & 18,064 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"webpack-common-shake": "^1.0.0"
},
"dependencies": {
"axios": "^1.5.1",
"babel-plugin-transform-object-assign": "^6.22.0",
"base-64": "^1.0.0",
"postscribe": "^2.0.8"
}
}
97 changes: 97 additions & 0 deletions src/adpushupUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import constants from "./constants";

function getPageFeedbackData() {
const adp = window.parent.adpushup;
const { siteId, platform, pageGroup, packetId, country, siteDomain } = adp.config;
return {
url: adp.utils.getURLForFeedback(),
platform,
pageGroup,
siteDomain,
siteId,
packetId,
country
};
}

function getCurrentApSlot() {
const adp = window.parent.adpushup;
/**
* TODO:
* Currently only one slot will be present in every iframe so taking only the first element
* of adpSlots object,
* But will need to change this in future with prebid request batching support
*/
const slot = Object.values(adp.adpTags.adpSlots)[0];
return slot;
}

export function sendApBidWonFeedback(auctionData, bidObject) {
const adp = window.parent.adpushup;
const mode = adp.config.mode;
const errorCode = constants.ERROR_CODES.NO_ERROR;
const renderedAdSize = auctionData.size;
const winner = auctionData.bidderCode || constants.FEEDBACK.DEFAULT_WINNER;
const winningRevenue = (bidObject.price || auctionData.hbPb) / 1000;
const winnerNetworkRelation = constants.NETWORK_RELATIONS.DIRECT;
const winnerAdUnitId = bidObject.adid || auctionData.adId || null;
const formatType = (bidObject.ext && bidObject.ext.prebid && bidObject.ext.prebid.type) || constants.DEFAULT_FORMAT_TYPE;
const slot = getCurrentApSlot();
const services = slot.services;
const refreshcount = slot.refreshcount || parseInt(auctionData.targetingMap.refreshcount) || constants.DEFAULT_REFRESH_COUNT;
const sectionId = slot.sectionId || (slot.optionalParam && (slot.optionalParam.originalId || slot.optionalParam.adId));
const sectionName = slot.sectionName;

const slotFeedbackData = {
bids: [
{
bidder: winner,
revenue: winningRevenue,
networkRelation: winnerNetworkRelation
}
],
mode,
errorCode,
renderedAdSize,
winner,
winningRevenue,
winnerNetworkRelation,
winnerAdUnitId,
formatType,
services,
refreshcount,
sectionId,
sectionName
};

const feedbackData = adp.$.extend({}, getPageFeedbackData(), slotFeedbackData);

return adp.$.get(constants.FEEDBACK.HB_FEEDBACK_URL + adp.utils.base64Encode(JSON.stringify(feedbackData)));
}

export function transformAdpushupTargetingData(tagData) {
let auctionData = {};
Object.keys(tagData).forEach(key => {
if (key === 'targetingMap') {
auctionData[key] = transformAdpushupTargetingData(tagData[key]);
} else if (Array.isArray(tagData[key])) {
auctionData[key] = tagData[key][0];
} else {
auctionData[key] = tagData[key];
}
})
return auctionData;
}

export function resizeGoogleAdIframe(size) {
const win = window.parent;
const [ width, height ] = size.split('x').map(Number);
const parentAdIframes = Array.from(win.document.getElementsByTagName("iframe"));
parentAdIframes.forEach(frame => {
if(frame.name.indexOf(constants.GOOGLE_AD_IFRAME_NAME) === -1) {
return;
}
frame.width = width;
frame.height = height;
});
}
44 changes: 44 additions & 0 deletions src/cdnUpload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const base64 = require('base-64');
const fs = require('fs');
const axios = require('axios');
const path = require('path');

const filePath = 'amp-hybrid/creative.js';
const sourceFilePath = path.join(__dirname, "../dist/creative.js");

const QUEUE_PUBLISHER_SERVICE_URL = 'http://queuepublisher.adpushup.com';

const uploadToCdn = (data) => {
const body = {
queue: 'CDN_ORIGIN',
data
};

const uri = Array.isArray(data)
? `${QUEUE_PUBLISHER_SERVICE_URL}/publishBulk`
: `${QUEUE_PUBLISHER_SERVICE_URL}/publish`;

const config = {
method: 'post',
url: uri,
data: body
};

return axios(config)
.then((response) => response.data)
.catch((e) => {
console.log(`error CDN upload:${e}`);
throw e;
});
};

const content = fs.readFileSync(sourceFilePath);

uploadToCdn([
{
filePath,
content: base64.encode(unescape(encodeURIComponent(content)))
}
])
.then((d) => console.log('Uploaded Success', d))
.catch((e) => console.log('Failed'));
18 changes: 18 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
DEFAULT_AMP_PAGE_GROUP: 'AMP_DM_PG',
DEFAULT_PLATFORM: 'MOBILE',
DEFAULT_FORMAT_TYPE: 'banner',
GOOGLE_AD_IFRAME_NAME: 'google_ads_iframe',
DEFAULT_REFRESH_COUNT: 0,
ERROR_CODES: {
NO_ERROR: 1
},
FEEDBACK: {
DEFAULT_WINNER: 'adx',
HB_FEEDBACK_URL: '//e3.adpushup.com/AdPushupFeedbackWebService/feedback/aphb?data='
},
NETWORK_RELATIONS: {
AP_PARTNER: 1,
DIRECT: 2
}
}
4 changes: 2 additions & 2 deletions src/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
* - Outstream Video
* - All safeFrame creatives
*/

import { transformAuctionTargetingData } from './utils';
import { renderBannerOrDisplayAd } from './renderingManager';
import { renderAmpOrMobileAd } from './mobileAndAmpRender';
import { isMobileApp, isAmp } from './environment';
import { transformAdpushupTargetingData } from './adpushupUtils';

window.ucTag = (window.ucTag || {});

window.ucTag.renderAd = (doc, dataObject) => {
const targetingData = transformAuctionTargetingData(dataObject);
const targetingData = dataObject.isAPCreative ? transformAdpushupTargetingData(dataObject) : transformAuctionTargetingData(dataObject);

if (isMobileApp(targetingData.env) || isAmp(targetingData.uuid, window)) {
renderAmpOrMobileAd(dataObject);
Expand Down
23 changes: 16 additions & 7 deletions src/mobileAndAmpRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getCreativeCommentMarkup, triggerPixel, createTrackPixelHtml, loadScrip
import { isSafeFrame, isMobileApp } from './environment';
import { insertElement } from './domHelper';
import { writeAdHtml } from './postscribeRender';
import { transformAdpushupTargetingData, sendApBidWonFeedback, resizeGoogleAdIframe } from './adpushupUtils'

const DEFAULT_CACHE_HOST = 'prebid.adnxs.com';
const DEFAULT_CACHE_PATH = '/pbc/v1/cache';
Expand All @@ -16,7 +17,7 @@ const DEFAULT_CACHE_PATH = '/pbc/v1/cache';
* @param {Bool} isMobileApp flag to detect mobile app
*/
export function renderAmpOrMobileAd(dataObject) {
const targetingData = transformAuctionTargetingData(dataObject);
const targetingData = dataObject.isAPCreative ? transformAdpushupTargetingData(dataObject) : transformAuctionTargetingData(dataObject);
let { cacheHost, cachePath, uuid, size, hbPb } = targetingData;
uuid = uuid || '';
// For MoPub, creative is stored in localStorage via SDK.
Expand All @@ -28,8 +29,12 @@ export function renderAmpOrMobileAd(dataObject) {
} else {
let adUrl = `${getCacheEndpoint(cacheHost, cachePath)}?uuid=${uuid}`;
//register creative right away to not miss initial geom-update
updateIframe(size);
sendRequest(adUrl, responseCallback(isMobileApp(targetingData.env), hbPb));
if(dataObject.isAPCreative){
resizeGoogleAdIframe(size);
} else {
updateIframe(size);
}
sendRequest(adUrl, responseCallback(isMobileApp(targetingData.env), hbPb, targetingData));
}
}

Expand Down Expand Up @@ -91,10 +96,10 @@ function resizeIframe(width, height) {
* @param {string} cachePath Cache Endpoint path
*/
function getCacheEndpoint(cacheHost, cachePath) {
let host = (typeof cacheHost === 'undefined' || cacheHost === "") ? DEFAULT_CACHE_HOST : cacheHost;
let host = (typeof cacheHost === 'undefined' || cacheHost === "") ? DEFAULT_CACHE_HOST : cacheHost.replace('https://', '');
let path = (typeof cachePath === 'undefined' || cachePath === "") ? DEFAULT_CACHE_PATH : cachePath;

return `https://${host}${path}`;
return `https://${host}${path}`;;
}


Expand All @@ -104,14 +109,18 @@ function getCacheEndpoint(cacheHost, cachePath) {
* @param {string} hbPb final price of the winning bid
* @returns {function} a callback function that parses response
*/
function responseCallback(isMobileApp, hbPb) {
function responseCallback(isMobileApp, hbPb, targetingData) {
return function (response) {
let bidObject = parseResponse(response);
let auctionPrice = bidObject.price || hbPb;
let ad = getCreativeCommentMarkup(bidObject);
let width = (bidObject.width) ? bidObject.width : bidObject.w;
let height = (bidObject.height) ? bidObject.height : bidObject.h;

if(targetingData && targetingData.isAPCreative) {
sendApBidWonFeedback(targetingData, bidObject)
}

// When Prebid Universal Creative reads from Prebid Cache, we need to have it check for the existence of the wurl parameter. If it exists, hit it.
if (bidObject.wurl) {
triggerPixel(decodeURIComponent(bidObject.wurl));
Expand Down