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

Audience Network: ensure interpretResponse can handle both string and array based sizes #1873

Merged
merged 1 commit into from
Nov 27, 2017
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
21 changes: 17 additions & 4 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const isBidRequestValid = bid =>
const flattenSize = size =>
(Array.isArray(size) && size.length === 2) ? `${size[0]}x${size[1]}` : size;

/**
* Expands a 'WxH' string as a 2-element [W, H] array
* @param {String} size
* @returns {Array}
*/
const expandSize = size => size.split('x').map(Number);

/**
* Is this a valid slot size?
* @param {String} size
Expand Down Expand Up @@ -84,6 +91,12 @@ const createAdHtml = (placementId, format, bidId) => {
${nativeContainer}</div></body></html>`;
};

/**
* Get the current window location URL correctly encoded for use in a URL query string.
* @returns {String} URI-encoded URL
*/
const getTopWindowUrlEncoded = () => encodeURIComponent(getTopWindowUrl());

/**
* Convert each bid request to a single URL to fetch those bids.
* @param {Array} bids - list of bids
Expand Down Expand Up @@ -118,7 +131,7 @@ const buildRequests = bids => {

// Build URL
const testmode = isTestmode();
const pageurl = getTopWindowUrl();
const pageurl = getTopWindowUrlEncoded();
const search = {
placementids,
adformats,
Expand Down Expand Up @@ -163,7 +176,7 @@ const interpretResponse = ({ body }, { adformats, requestIds, sizes }) => {
} = bid;

const format = adformats[i];
const [width, height] = sizes[i];
const [width, height] = expandSize(flattenSize(sizes[i]));
const ad = createAdHtml(creativeId, format, fb_bidid);
const requestId = requestIds[i];

Expand All @@ -186,9 +199,9 @@ const interpretResponse = ({ body }, { adformats, requestIds, sizes }) => {
};
// Video attributes
if (isVideo(format)) {
const pageurl = getTopWindowUrl();
const pageurl = getTopWindowUrlEncoded();
bidResponse.mediaType = 'video';
bidResponse.vastUrl = `https://an.facebook.com/v1/instream/vast.xml?placementid=${creativeId}&pageurl=${encodeURIComponent(pageurl)}&playerwidth=${width}&playerheight=${height}&bidid=${fb_bidid}`;
bidResponse.vastUrl = `https://an.facebook.com/v1/instream/vast.xml?placementid=${creativeId}&pageurl=${pageurl}&playerwidth=${width}&playerheight=${height}&bidid=${fb_bidid}`;
}
return bidResponse;
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('AudienceNetwork adapter', () => {
}, {
adformats: ['native', '300x250'],
requestIds: [requestId, requestId],
sizes: [[300, 250], [300, 250]]
sizes: ['300x250', [300, 250]]
});

expect(bidResponseNative.cpm).to.equal(1.23);
Expand Down