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

Add Native ad capability to AdYouLike adapter #6198

Merged
merged 36 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
32adbfc
Merge remote-tracking branch 'origin/master'
guiann May 29, 2019
140b538
Remove useless bidderCode in bid response
guiann May 29, 2019
1bd5a3a
Merge remote-tracking branch 'guiann-prebid/master'
guiann May 29, 2019
613824c
Merge remote-tracking branch 'origin/master'
guiann Jun 13, 2019
8fb7857
Merge remote-tracking branch 'origin/master'
guiann Jul 18, 2019
21734b3
Merge branch 'master' into adYouLike-handleMultipleSizes
guiann Jul 18, 2019
e4a5f63
send all the available sizes in the bid request
guiann Jul 22, 2019
111dc49
Merge branch 'adYouLike-handleMultipleSizes'
guiann Jul 22, 2019
908eaab
Merge remote-tracking branch 'origin/master'
guiann Jul 22, 2019
edf4cd3
Use the banner sizes if given
guiann Jul 25, 2019
008ded4
avoid compatibility issue with old bid format
guiann Jul 25, 2019
9664b1a
Merge remote-tracking branch 'origin/master'
guiann Oct 10, 2019
b46765a
Merge remote-tracking branch 'Adyoulike/master'
guiann Dec 24, 2019
1a4f452
Merge remote-tracking branch 'Adyoulike/master'
guiann Dec 24, 2019
c8cf2fc
Merge remote-tracking branch 'origin/master'
guiann Jan 8, 2020
24af97c
Merge remote-tracking branch 'origin/master'
guiann Jan 8, 2020
f945f2a
Merge remote-tracking branch 'origin/master'
guiann Apr 14, 2020
6440311
Merge remote-tracking branch 'Adyoulike/master'
guiann Oct 5, 2020
6844fab
ad iframe and publisher domain paramters to bid requests
guiann Oct 5, 2020
679c963
add publisher domain info in ad request
guiann Oct 6, 2020
5a44ef4
add a check in unit tests for publisherDomain
guiann Oct 6, 2020
4188bb5
Merge branch 'AYL-addIframeInfo'
guiann Oct 6, 2020
8dda59f
encode uri components
guiann Oct 6, 2020
592a1ed
Merge remote-tracking branch 'origin/master'
guiann Jan 6, 2021
63bfe7c
add native assets support
guiann Jan 7, 2021
3919556
add native information to ad request
guiann Jan 8, 2021
29cb464
fix native ad parsing
guiann Jan 8, 2021
ddd117c
fix nativ condition to set mediatype
guiann Jan 8, 2021
1398aaa
fix image access and add trackers
guiann Jan 14, 2021
8552e63
fix and add unit test on native ad
guiann Jan 15, 2021
29cd8c1
update md file
guiann Jan 15, 2021
7e58dab
Merge remote-tracking branch 'origin/master'
guiann Jan 15, 2021
86aead0
Merge branch 'adyoulike-nativeAd'
guiann Jan 15, 2021
24530ff
remove usage of URLSearchParams
guiann Jan 15, 2021
52575ea
allox pure native ad with no adm provided
guiann Jan 18, 2021
bfa5c29
Merge tag '4.23.0'
guiann Jan 21, 2021
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
177 changes: 163 additions & 14 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import find from 'core-js-pure/features/array/find.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';

const VERSION = '1.0';
const BIDDER_CODE = 'adyoulike';
const DEFAULT_DC = 'hb-api';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
aliases: ['ayl'], // short code
/**
* Determines whether or not the given bid request is valid.
Expand All @@ -18,10 +20,11 @@ export const spec = {
*/
isBidRequestValid: function (bid) {
const sizes = getSize(getSizeArray(bid));
if (!bid.params || !bid.params.placement || !sizes.width || !sizes.height) {
return false;
}
return true;
const sizeValid = sizes.width > 0 && sizes.height > 0;

// allows no size fornative only
return (bid.params && bid.params.placement &&
(sizeValid || (bid.mediaTypes && bid.mediaTypes.native)));
},
/**
* Make a server request from the list of BidRequests.
Expand All @@ -41,6 +44,7 @@ export const spec = {
accumulator[bid.bidId].Width = size.width;
accumulator[bid.bidId].Height = size.height;
accumulator[bid.bidId].AvailableSizes = sizesArray.join(',');
if (bid.mediaTypes && bid.mediaTypes.native) accumulator[bid.bidId].Native = bid.mediaTypes.native;
return accumulator;
}, {}),
PageRefreshed: getPageRefreshed()
Expand Down Expand Up @@ -171,9 +175,9 @@ function createEndpointQS(bidderRequest) {
}

function getSizeArray(bid) {
let inputSize = bid.sizes;
let inputSize = bid.sizes || [];
if (bid.mediaTypes && bid.mediaTypes.banner) {
inputSize = bid.mediaTypes.banner.sizes;
inputSize = bid.mediaTypes.banner.sizes || [];
}

return utils.parseSizesInput(inputSize);
Expand Down Expand Up @@ -203,34 +207,179 @@ function getSize(sizesArray) {
return parsed;
}

function getInternalImgUrl(uid) {
if (!uid) return '';
return 'https://blobs.omnitagjs.com/blobs/' + uid.substr(16, 2) + '/' + uid.substr(16) + '/' + uid;
}

function getImageUrl(config, resource, width, height) {
let url = '';

switch (resource.Kind) {
case 'INTERNAL':
url = getInternalImgUrl(resource.Data.Internal.BlobReference.Uid);

break;

case 'EXTERNAL':
const dynPrefix = config.DynamicPrefix;
let extUrl = resource.Data.External.Url;
extUrl = extUrl.replace(/\[height\]/i, '' + height);
extUrl = extUrl.replace(/\[width\]/i, '' + width);

if (extUrl.indexOf(dynPrefix) >= 0) {
const urlmatch = (/.*url=([^&]*)/gm).exec(extUrl);
url = urlmatch ? urlmatch[1] : '';
if (!url) {
url = getInternalImgUrl((/.*key=([^&]*)/gm).exec(extUrl)[1]);
}
} else {
url = extUrl;
}

break;
}

return url;
}

function getTrackers(eventsArray, jsTrackers) {
const result = [];

if (!eventsArray) return result;

eventsArray.map((item, index) => {
if ((jsTrackers && item.Kind === 'JAVASCRIPT_URL') ||
(!jsTrackers && item.Kind === 'PIXEL_URL')) {
result.push(item.Url);
}
});
return result;
}

function getNativeAssets(response, nativeConfig) {
const native = {};

var adJson = {};
var textsJson = {};
if (typeof response.Ad === 'string') {
adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]);
textsJson = adJson.Content.Preview.Text;

var impressionUrl = adJson.TrackingPrefix +
'/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt;

if (adJson.Campaign) {
impressionUrl += '&campaign=' + adJson.Campaign;
}

native.clickUrl = adJson.TrackingPrefix + '/ar?event_kind=CLICK&attempt=' + adJson.Attempt +
'&campaign=' + adJson.Campaign + '&url=' + encodeURIComponent(adJson.Content.Landing.Url);

native.clickTrackers = getTrackers(adJson.OnEvents['CLICK']);
native.impressionTrackers = getTrackers(adJson.OnEvents['IMPRESSION']);
native.impressionTrackers.push(impressionUrl);
native.javascriptTrackers = getTrackers(adJson.OnEvents['IMPRESSION'], true);
}

Object.keys(nativeConfig).map(function(key, index) {
if (typeof response.Native === 'object') {
native[key] = response.Native[key];
} else {
switch (key) {
case 'title':
native[key] = textsJson.TITLE;
break;
case 'body':
native[key] = textsJson.DESCRIPTION;
break;
case 'cta':
native[key] = textsJson.CALLTOACTION;
break;
case 'sponsoredBy':
native[key] = adJson.Content.Preview.Sponsor.Name;
break;
case 'image':
// main image requested size
const imgSize = nativeConfig.image.sizes || [];
if (!imgSize.length) {
imgSize[0] = response.Width || 300;
imgSize[1] = response.Height || 250;
}

native[key] = {
url: getImageUrl(adJson, adJson.Content.Preview.Thumbnail.Image, imgSize[0], imgSize[1]),
width: imgSize[0],
height: imgSize[1]
};
break;
case 'icon':
if (adJson.HasSponsorImage) {
// icon requested size
const iconSize = nativeConfig.icon.sizes || [];
if (!iconSize.length) {
iconSize[0] = 50;
iconSize[1] = 50;
}

native[key] = {
url: getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, iconSize[0], iconSize[1]),
width: iconSize[0],
height: iconSize[1]
};
}
break;
case 'privacyIcon':
native[key] = getImageUrl(adJson, adJson.Content.Preview.Credit.Logo.Resource, 25, 25);
break;
case 'privacyLink':
native[key] = adJson.Content.Preview.Credit.Url;
break;
}
}
});

return native;
}

/* Create bid from response */
function createBid(response, bidRequests) {
if (!response || !response.Ad) {
if (!response || (!response.Ad && !response.Native)) {
return
}

const request = bidRequests && bidRequests[response.BidID];

// In case we don't retreive the size from the adserver, use the given one.
if (bidRequests && bidRequests[response.BidID]) {
if (request) {
if (!response.Width || response.Width === '0') {
response.Width = bidRequests[response.BidID].Width;
response.Width = request.Width;
}

if (!response.Height || response.Height === '0') {
response.Height = bidRequests[response.BidID].Height;
response.Height = request.Height;
}
}

return {
const bid = {
requestId: response.BidID,
width: response.Width,
height: response.Height,
ad: response.Ad,
ttl: 3600,
creativeId: response.CreativeID,
cpm: response.Price,
netRevenue: true,
currency: 'USD'
};

if (request && request.Native) {
bid.native = getNativeAssets(response, request.Native);
bid.mediaType = 'native';
} else {
bid.width = response.Width;
bid.height = response.Height;
bid.ad = response.Ad;
}

return bid;
}

registerBidder(spec);
60 changes: 45 additions & 15 deletions modules/adyoulikeBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,49 @@ Banner formats are supported.

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]],
bids: [
{
bidder: "adyoulike",
params: {
placement: 194f787b85c829fb8822cdaf1ae64435,
DC: 'fra01', // Optional for set the data center name
}
}
]
}
];
var adUnits = {
"code": "test-div",
"mediaTypes": {
"banner": {
"sizes": ["300x250"]
},
"native": {
"image": {
"required": true,
},
"title": {
"required": true,
"len": 80
},
"cta": {
"required": false
},
"sponsoredBy": {
"required": true
},
"clickUrl": {
"required": true
},
"privacyIcon": {
"required": false
},
"privacyLink": {
"required": false
},
"body": {
"required": true
},
"icon": {
"required": true,
"sizes": []
}
}
bids: [{
bidder: "adyoulike",
params: {
placement: 194 f787b85c829fb8822cdaf1ae64435,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an accidental space in the placement. Very minor, but it could throw some people off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, will be fixed in a future release. thx

DC: "fra01", // Optional for set the data center name
}
}]
};
```
Loading