From 140b538ddc4b35ef29d26d89f0a8948cd951273f Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 29 May 2019 09:29:39 +0200 Subject: [PATCH 01/17] Remove useless bidderCode in bid response --- modules/adyoulikeBidAdapter.js | 1 - test/spec/modules/adyoulikeBidAdapter_spec.js | 5 ----- 2 files changed, 6 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 4624bdba8b5..fd7a1697bac 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -187,7 +187,6 @@ function createBid(response) { return { requestId: response.BidID, - bidderCode: spec.code, width: response.Width, height: response.Height, ad: response.Ad, diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index 3f28acaaf97..7edb9416b03 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -7,7 +7,6 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('Adyoulike Adapter', function () { const canonicalUrl = 'http://canonical.url/?t=%26'; const defaultDC = 'hb-api'; - const bidderCode = 'adyoulike'; const bidRequestWithEmptyPlacement = [ { 'bidId': 'bid_id_0', @@ -18,7 +17,6 @@ describe('Adyoulike Adapter', function () { } ]; const bidRequestWithEmptySizes = { - 'bidderCode': 'adyoulike', 'bids': [ { 'bidId': 'bid_id_0', @@ -193,7 +191,6 @@ describe('Adyoulike Adapter', function () { it('should add gdpr consent information to the request', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { - 'bidderCode': 'adyoulike', 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, @@ -306,13 +303,11 @@ describe('Adyoulike Adapter', function () { expect(result.length).to.equal(2); - expect(result[0].bidderCode).to.equal(bidderCode); expect(result[0].cpm).to.equal(0.5); expect(result[0].ad).to.equal('placement_0'); expect(result[0].width).to.equal(300); expect(result[0].height).to.equal(300); - expect(result[1].bidderCode).to.equal(bidderCode); expect(result[1].cpm).to.equal(0.6); expect(result[1].ad).to.equal('placement_1'); expect(result[1].width).to.equal(300); From e4a5f63b7bb4fe90ef2111e0bffa7ea25157b32f Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 22 Jul 2019 11:10:43 +0200 Subject: [PATCH 02/17] send all the available sizes in the bid request --- modules/adyoulikeBidAdapter.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index fd7a1697bac..0f0fb3eca33 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -18,7 +18,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - const sizes = getSize(bid.sizes); + const sizes = getSize(utils.parseSizesInput(bid.sizes)); if (!bid.params || !bid.params.placement || !sizes.width || !sizes.height) { return false; } @@ -34,12 +34,14 @@ export const spec = { const payload = { Version: VERSION, Bids: bidRequests.reduce((accumulator, bid) => { - let size = getSize(bid.sizes); + let sizesArray = utils.parseSizesInput(bid.sizes); + let size = getSize(sizesArray); accumulator[bid.bidId] = {}; accumulator[bid.bidId].PlacementID = bid.params.placement; accumulator[bid.bidId].TransactionID = bid.transactionId; accumulator[bid.bidId].Width = size.width; accumulator[bid.bidId].Height = size.height; + accumulator[bid.bidId].AvaiableSizes = sizesArray.join(','); return accumulator; }, {}), PageRefreshed: getPageRefreshed() @@ -157,9 +159,10 @@ function createEndpointQS(bidderRequest) { } /* Get parsed size from request size */ -function getSize(requestSizes) { +function getSize(sizesArray) { const parsed = {}; - const size = utils.parseSizesInput(requestSizes)[0]; + // the main requested size is the first one + const size = sizesArray[0]; if (typeof size !== 'string') { return parsed; From edf4cd3f20736cce0b3ea1b74f9c6bcdb5c80ceb Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 25 Jul 2019 16:40:03 +0200 Subject: [PATCH 03/17] Use the banner sizes if given --- modules/adyoulikeBidAdapter.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 0f0fb3eca33..7a6b4c0e5fd 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -18,7 +18,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - const sizes = getSize(utils.parseSizesInput(bid.sizes)); + const sizes = getSize(getSizeArray(bid)); if (!bid.params || !bid.params.placement || !sizes.width || !sizes.height) { return false; } @@ -34,7 +34,7 @@ export const spec = { const payload = { Version: VERSION, Bids: bidRequests.reduce((accumulator, bid) => { - let sizesArray = utils.parseSizesInput(bid.sizes); + let sizesArray = getSizeArray(bid); let size = getSize(sizesArray); accumulator[bid.bidId] = {}; accumulator[bid.bidId].PlacementID = bid.params.placement; @@ -158,6 +158,15 @@ function createEndpointQS(bidderRequest) { return qs; } +function getSizeArray(bid) { + let inputSize = bid.sizes; + if (bid.mediaTypes.banner) { + inputSize = bid.mediaTypes.banner.sizes; + } + + return utils.parseSizesInput(inputSize); +} + /* Get parsed size from request size */ function getSize(sizesArray) { const parsed = {}; From 008ded4d2b4bfa896de06fb2f5b51d2fc57b8710 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 25 Jul 2019 16:49:42 +0200 Subject: [PATCH 04/17] avoid compatibility issue with old bid format --- modules/adyoulikeBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 7a6b4c0e5fd..12891b6e155 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -160,7 +160,7 @@ function createEndpointQS(bidderRequest) { function getSizeArray(bid) { let inputSize = bid.sizes; - if (bid.mediaTypes.banner) { + if (bid.mediaTypes && bid.mediaTypes.banner) { inputSize = bid.mediaTypes.banner.sizes; } From 6844fab962df34ee96aebbff9ab1ec9830d7c659 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 5 Oct 2020 17:34:01 +0200 Subject: [PATCH 05/17] ad iframe and publisher domain paramters to bid requests --- modules/adyoulikeBidAdapter.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 725ee0f5626..7cd83aad042 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -1,5 +1,6 @@ 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'; const VERSION = '1.0'; @@ -104,15 +105,6 @@ function getHostname(bidderRequest) { return ''; } -/* Get current page referrer url */ -function getReferrerUrl(bidderRequest) { - let referer = ''; - if (bidderRequest && bidderRequest.refererInfo) { - referer = bidderRequest.refererInfo.referer; - } - return referer; -} - /* Get current page canonical url */ function getCanonicalUrl() { let link; @@ -155,9 +147,14 @@ function createEndpoint(bidRequests, bidderRequest) { function createEndpointQS(bidderRequest) { const qs = {}; - const ref = getReferrerUrl(bidderRequest); - if (ref) { - qs.RefererUrl = encodeURIComponent(ref); + if (bidderRequest) { + const ref = bidderRequest.refererInfo; + if (ref) { + qs.RefererUrl = encodeURIComponent(ref.referer); + if (ref.numIframes > 0) { + qs.SafeFrame = true; + } + } } const can = getCanonicalUrl(); @@ -165,6 +162,11 @@ function createEndpointQS(bidderRequest) { qs.CanonicalUrl = encodeURIComponent(can); } + const domain = config.getConfig('publisherDomain'); + if (domain) { + qs.pubDomain = domain; + } + return qs; } From 679c963b5703b5b8549242d73844c000e4389619 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Tue, 6 Oct 2020 12:04:27 +0200 Subject: [PATCH 06/17] add publisher domain info in ad request --- modules/adyoulikeBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 7cd83aad042..54059592b74 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -164,7 +164,7 @@ function createEndpointQS(bidderRequest) { const domain = config.getConfig('publisherDomain'); if (domain) { - qs.pubDomain = domain; + qs.PublisherDomain = domain; } return qs; From 5a44ef4f8f081cfc598feb4fd727dfae65ed6093 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Tue, 6 Oct 2020 12:09:25 +0200 Subject: [PATCH 07/17] add a check in unit tests for publisherDomain --- test/spec/modules/adyoulikeBidAdapter_spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index d2d4e10c17f..5f2eb14ad31 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -306,6 +306,7 @@ describe('Adyoulike Adapter', function () { expect(request.method).to.equal('POST'); expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); + expect(request.url).to.contains('PublisherDomain=http://localhost:9876'); expect(payload.Version).to.equal('1.0'); expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); From 8dda59f880a774eb282aaf9afa899910bfc699b0 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Tue, 6 Oct 2020 16:25:50 +0200 Subject: [PATCH 08/17] encode uri components --- modules/adyoulikeBidAdapter.js | 2 +- test/spec/modules/adyoulikeBidAdapter_spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 54059592b74..40d3cf84369 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -164,7 +164,7 @@ function createEndpointQS(bidderRequest) { const domain = config.getConfig('publisherDomain'); if (domain) { - qs.PublisherDomain = domain; + qs.PublisherDomain = encodeURIComponent(domain); } return qs; diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index 5f2eb14ad31..ec8f2f00923 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -306,7 +306,7 @@ describe('Adyoulike Adapter', function () { expect(request.method).to.equal('POST'); expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); - expect(request.url).to.contains('PublisherDomain=http://localhost:9876'); + expect(request.url).to.contains('PublisherDomain=http%3A%2F%2Flocalhost%3A9876'); expect(payload.Version).to.equal('1.0'); expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); From 63bfe7c23b0947fc1e215f00ed53878a7aefb683 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 7 Jan 2021 17:07:54 +0100 Subject: [PATCH 09/17] add native assets support --- modules/adyoulikeBidAdapter.js | 127 +++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 5 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 40d3cf84369..98da9aff040 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -9,6 +9,7 @@ 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. @@ -203,34 +204,150 @@ function getSize(sizesArray) { return parsed; } +function getImageUrl(config, resource, width, height) { + // use default cropping + var auto = resource.ZoneHeight === 0 || resource.ZoneWidth === 0; + + let url = ''; + const crop = 1 / 3; + + const dynPrefix = config.DynamicPrefix; + + switch (resource.Kind) { + case 'INTERNAL': + url = dynPrefix + '/native/preview/image?key=' + resource.Data.Internal.BlobReference.Uid; + url += '&kind=INTERNAL'; + if (!auto) { + url += '&ztop=' + resource.ZoneTop; + url += '&zleft=' + resource.ZoneLeft; + url += '&zwidth=' + resource.ZoneWidth; + url += '&zheight=' + resource.ZoneHeight; + } else { + url += '&ztop=' + crop; + url += '&zleft=' + crop; + url += '&zwidth=' + crop; + url += '&zheight=' + crop; + } + url += '&width=' + width; + url += '&height=' + height; + + break; + + case 'EXTERNAL': + let extUrl = resource.Data.External.Url; + extUrl = extUrl.replace(/\[height\]/i, '' + height); + extUrl = extUrl.replace(/\[width\]/i, '' + width); + if (extUrl.indexOf(dynPrefix) >= 0) { + url = extUrl; + } else { + url = dynPrefix + '/native/preview/image?url=' + extUrl; + url += '&kind=' + resource.Kind; + if (!auto) { + url += '&ztop=' + resource.ZoneTop; + url += '&zleft=' + resource.ZoneLeft; + url += '&zwidth=' + resource.ZoneWidth; + url += '&zheight=' + resource.ZoneHeight; + } else { + url += '&ztop=' + crop; + url += '&zleft=' + crop; + url += '&zwidth=' + crop; + url += '&zheight=' + crop; + } + url += '&width=' + width; + url += '&height=' + height; + } + + if (resource.Smart) { // resource.Smart could have the string value 'false' + url += '&smart=' + (resource.Smart); + } + + if (resource.NoTransform) { + url += '¬ransform=' + resource.NoTransform; + } + + break + } + + return url; +} + +function getNativeAssets(response) { + if (typeof response.Native === 'object') { + return response.Native; + } else { + const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)); + const textsJson = adJson.Content.Preview.Text; + + const width = response.Width || 300; + const height = response.Height || 250; + + var impressionUrl = adJson.TrackingPrefix + + '/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt; + + if (adJson.Campaign) { + impressionUrl += '&campaign=' + adJson.Campaign; + } + + return { + title: textsJson.TITLE, + body: textsJson.DESCRIPTION, + cta: textsJson.CALLTOACTION, + sponsoredBy: textsJson.SPONSOR, + image: { + url: getImageUrl(adJson, adJson.Thumbnail.Image, width, height), + height: height, + width: width, + }, + icon: { + url: adJson.HasSponsorImage && getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, 50, 50), + height: 50, + width: 50, + }, + clickUrl: adJson.Content.Landing.Url, + impressionTrackers: [ + impressionUrl + ], + }; + } +} + /* Create bid from response */ function createBid(response, bidRequests) { if (!response || !response.Ad) { 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.mediaTypes === 'native') { + bid.native = getNativeAssets(response); + } else { + bid.ad = response.Ad; + } + + return bid; } registerBidder(spec); From 391955635246cee91bb705a61ba5c3025b22fbb4 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 8 Jan 2021 19:51:29 +0100 Subject: [PATCH 10/17] add native information to ad request --- modules/adyoulikeBidAdapter.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 98da9aff040..3a78b375071 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -2,6 +2,7 @@ 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'; @@ -9,7 +10,7 @@ const DEFAULT_DC = 'hb-api'; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: ['BANNER', 'NATIVE'], + supportedMediaTypes: [BANNER, NATIVE], aliases: ['ayl'], // short code /** * Determines whether or not the given bid request is valid. @@ -19,10 +20,10 @@ 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; + + // allows no size fornative only + return bid.params && bid.params.placement && + (bid.mediaTypes.native || (sizes.width && sizes.height)); }, /** * Make a server request from the list of BidRequests. @@ -42,6 +43,7 @@ export const spec = { accumulator[bid.bidId].Width = size.width; accumulator[bid.bidId].Height = size.height; accumulator[bid.bidId].AvailableSizes = sizesArray.join(','); + accumulator[bid.bidId].Native = !!bid.mediaTypes.native; return accumulator; }, {}), PageRefreshed: getPageRefreshed() From 29cb4646ee86f670f85588bde719176bccb2d314 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 8 Jan 2021 19:52:23 +0100 Subject: [PATCH 11/17] fix native ad parsing --- modules/adyoulikeBidAdapter.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 3a78b375071..f883f286e63 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -277,7 +277,7 @@ function getNativeAssets(response) { if (typeof response.Native === 'object') { return response.Native; } else { - const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)); + const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); const textsJson = adJson.Content.Preview.Text; const width = response.Width || 300; @@ -290,26 +290,30 @@ function getNativeAssets(response) { impressionUrl += '&campaign=' + adJson.Campaign; } - return { + const native = { title: textsJson.TITLE, body: textsJson.DESCRIPTION, cta: textsJson.CALLTOACTION, - sponsoredBy: textsJson.SPONSOR, + sponsoredBy: adJson.Content.Preview.Sponsor.Name, image: { - url: getImageUrl(adJson, adJson.Thumbnail.Image, width, height), + url: getImageUrl(adJson, adJson.Content.Preview.Thumbnail.Image, width, height), height: height, width: width, }, - icon: { - url: adJson.HasSponsorImage && getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, 50, 50), - height: 50, - width: 50, - }, clickUrl: adJson.Content.Landing.Url, impressionTrackers: [ impressionUrl ], }; + + if (adJson.HasSponsorImage) { + native.icon = { + url: getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, 50, 50), + height: 50, + width: 50, + }; + } + return native; } } From ddd117ca26a04f62b9af731fea1ddce4cd92b370 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 8 Jan 2021 19:52:54 +0100 Subject: [PATCH 12/17] fix nativ condition to set mediatype --- modules/adyoulikeBidAdapter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index f883f286e63..e543e152061 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -347,9 +347,12 @@ function createBid(response, bidRequests) { currency: 'USD' }; - if (request && request.mediaTypes === 'native') { + if (request && request.Native) { bid.native = getNativeAssets(response); + bid.mediaType = 'native'; } else { + bid.width = response.Width; + bid.height = response.Height; bid.ad = response.Ad; } From 1398aaa9ebafd0079cfecef91177ed8fd93c8e6d Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 14 Jan 2021 16:17:53 +0100 Subject: [PATCH 13/17] fix image access and add trackers --- modules/adyoulikeBidAdapter.js | 190 ++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 86 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index e543e152061..8d564ed8215 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -43,7 +43,7 @@ export const spec = { accumulator[bid.bidId].Width = size.width; accumulator[bid.bidId].Height = size.height; accumulator[bid.bidId].AvailableSizes = sizesArray.join(','); - accumulator[bid.bidId].Native = !!bid.mediaTypes.native; + if (bid.mediaTypes.native) accumulator[bid.bidId].Native = bid.mediaTypes.native; return accumulator; }, {}), PageRefreshed: getPageRefreshed() @@ -206,115 +206,135 @@ function getSize(sizesArray) { return parsed; } -function getImageUrl(config, resource, width, height) { - // use default cropping - var auto = resource.ZoneHeight === 0 || resource.ZoneWidth === 0; +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 = ''; - const crop = 1 / 3; - - const dynPrefix = config.DynamicPrefix; switch (resource.Kind) { case 'INTERNAL': - url = dynPrefix + '/native/preview/image?key=' + resource.Data.Internal.BlobReference.Uid; - url += '&kind=INTERNAL'; - if (!auto) { - url += '&ztop=' + resource.ZoneTop; - url += '&zleft=' + resource.ZoneLeft; - url += '&zwidth=' + resource.ZoneWidth; - url += '&zheight=' + resource.ZoneHeight; - } else { - url += '&ztop=' + crop; - url += '&zleft=' + crop; - url += '&zwidth=' + crop; - url += '&zheight=' + crop; - } - url += '&width=' + width; - url += '&height=' + height; + 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) { - url = extUrl; - } else { - url = dynPrefix + '/native/preview/image?url=' + extUrl; - url += '&kind=' + resource.Kind; - if (!auto) { - url += '&ztop=' + resource.ZoneTop; - url += '&zleft=' + resource.ZoneLeft; - url += '&zwidth=' + resource.ZoneWidth; - url += '&zheight=' + resource.ZoneHeight; - } else { - url += '&ztop=' + crop; - url += '&zleft=' + crop; - url += '&zwidth=' + crop; - url += '&zheight=' + crop; + const urlParams = new URLSearchParams(extUrl.split('?')[1]); + url = urlParams.get('url'); + if (!url) { + url = getInternalImgUrl(urlParams.get('key')); } - url += '&width=' + width; - url += '&height=' + height; - } - - if (resource.Smart) { // resource.Smart could have the string value 'false' - url += '&smart=' + (resource.Smart); - } - - if (resource.NoTransform) { - url += '¬ransform=' + resource.NoTransform; + } else { + url = extUrl; } - break + break; } return url; } -function getNativeAssets(response) { - if (typeof response.Native === 'object') { - return response.Native; - } else { - const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); - const textsJson = adJson.Content.Preview.Text; - - const width = response.Width || 300; - const height = response.Height || 250; +function getTrackers(eventsArray, jsTrackers) { + const result = []; - var impressionUrl = adJson.TrackingPrefix + - '/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt; + if (!eventsArray) return result; - if (adJson.Campaign) { - impressionUrl += '&campaign=' + adJson.Campaign; + eventsArray.map((item, index) => { + if ((jsTrackers && item.Kind === 'JAVASCRIPT_URL') || + (!jsTrackers && item.Kind === 'PIXEL_URL')) { + result.push(item.Url); } + }); + return result; +} - const native = { - title: textsJson.TITLE, - body: textsJson.DESCRIPTION, - cta: textsJson.CALLTOACTION, - sponsoredBy: adJson.Content.Preview.Sponsor.Name, - image: { - url: getImageUrl(adJson, adJson.Content.Preview.Thumbnail.Image, width, height), - height: height, - width: width, - }, - clickUrl: adJson.Content.Landing.Url, - impressionTrackers: [ - impressionUrl - ], - }; +function getNativeAssets(response, nativeConfig) { + const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); + const textsJson = adJson.Content.Preview.Text; - if (adJson.HasSponsorImage) { - native.icon = { - url: getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, 50, 50), - height: 50, - width: 50, - }; - } - return native; + var impressionUrl = adJson.TrackingPrefix + + '/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt; + + if (adJson.Campaign) { + impressionUrl += '&campaign=' + adJson.Campaign; } + + const native = {}; + + 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 */ @@ -338,8 +358,6 @@ function createBid(response, bidRequests) { const bid = { requestId: response.BidID, - width: response.Width, - height: response.Height, ttl: 3600, creativeId: response.CreativeID, cpm: response.Price, @@ -348,7 +366,7 @@ function createBid(response, bidRequests) { }; if (request && request.Native) { - bid.native = getNativeAssets(response); + bid.native = getNativeAssets(response, request.Native); bid.mediaType = 'native'; } else { bid.width = response.Width; From 8552e6369cc7c17f9fee831a957a0e909430f6d3 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 15 Jan 2021 12:06:37 +0100 Subject: [PATCH 14/17] fix and add unit test on native ad --- modules/adyoulikeBidAdapter.js | 11 +- test/spec/modules/adyoulikeBidAdapter_spec.js | 143 +++++++++++++++++- 2 files changed, 144 insertions(+), 10 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 8d564ed8215..91a6198b6a4 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -20,10 +20,11 @@ export const spec = { */ isBidRequestValid: function (bid) { const sizes = getSize(getSizeArray(bid)); + const sizeValid = sizes.width > 0 && sizes.height > 0; // allows no size fornative only - return bid.params && bid.params.placement && - (bid.mediaTypes.native || (sizes.width && sizes.height)); + return (bid.params && bid.params.placement && + (sizeValid || (bid.mediaTypes && bid.mediaTypes.native))); }, /** * Make a server request from the list of BidRequests. @@ -43,7 +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.native) accumulator[bid.bidId].Native = bid.mediaTypes.native; + if (bid.mediaTypes && bid.mediaTypes.native) accumulator[bid.bidId].Native = bid.mediaTypes.native; return accumulator; }, {}), PageRefreshed: getPageRefreshed() @@ -174,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); diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index ec8f2f00923..4c108ed9f1d 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -58,12 +58,83 @@ describe('Adyoulike Adapter', function () { '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': [] } + }, }, 'transactionId': 'bid_id_0_transaction_id' } ]; + const sentBidNative = { + 'bid_id_0': { + 'PlacementID': 'e622af275681965d3095808561a1e510', + 'TransactionID': 'e8355240-d976-4cd5-a493-640656fe08e8', + 'AvailableSizes': '', + 'Native': { + 'image': { + 'required': true, + 'sizes': [] + }, + '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': [] + } + } + } + }; + const bidRequestWithDCPlacement = [ { 'bidId': 'bid_id_0', @@ -165,11 +236,12 @@ describe('Adyoulike Adapter', function () { 'Placement': 'placement_0' } ]; + const admSample = "\u003cscript id=\"ayl-prebid-a11a121205932e75e622af275681965d\"\u003e\n(function(){\n\twindow.isPrebid = true\n\tvar prebidResults = /*PREBID*/{\"OnEvents\":{\"CLICK\":[{\"Kind\":\"PIXEL_URL\",\"Url\":\"https://testPixelCLICK.com/fake\"}],\"IMPRESSION\":[{\"Kind\":\"PIXEL_URL\",\"Url\":\"https://testPixelIMP.com/fake\"},{\"Kind\":\"JAVASCRIPT_URL\",\"Url\":\"https://testJsIMP.com/fake.js\"}]},\"Disabled\":false,\"Attempt\":\"a11a121205932e75e622af275681965d\",\"ApiPrefix\":\"https://fo-api.omnitagjs.com/fo-api\",\"TrackingPrefix\":\"https://tracking.omnitagjs.com/tracking\",\"DynamicPrefix\":\"https://tag-dyn.omnitagjs.com/fo-dyn\",\"StaticPrefix\":\"https://fo-static.omnitagjs.com/fo-static\",\"BlobPrefix\":\"https://fo-api.omnitagjs.com/fo-api/blobs\",\"SspPrefix\":\"https://fo-ssp.omnitagjs.com/fo-ssp\",\"VisitorPrefix\":\"https://visitor.omnitagjs.com/visitor\",\"Trusted\":true,\"Placement\":\"e622af275681965d3095808561a1e510\",\"PlacementAccess\":\"ALL\",\"Site\":\"6e2df7a92203c3c7a25561ed63f25a27\",\"Lang\":\"EN\",\"SiteLogo\":null,\"HasSponsorImage\":false,\"ResizeIframe\":true,\"IntegrationConfig\":{\"Kind\":\"WIDGET\",\"Widget\":{\"ExtraStyleSheet\":\"\",\"Placeholders\":{\"Body\":{\"Color\":{\"R\":77,\"G\":21,\"B\":82,\"A\":100},\"BackgroundColor\":{\"R\":255,\"G\":255,\"B\":255,\"A\":100},\"FontFamily\":\"Lato\",\"Width\":\"100%\",\"Align\":\"\",\"BoxShadow\":true},\"CallToAction\":{\"Color\":{\"R\":26,\"G\":157,\"B\":212,\"A\":100}},\"Description\":{\"Length\":130},\"Image\":{\"Width\":600,\"Height\":600,\"Lowres\":false,\"Raw\":false},\"Size\":{\"Height\":\"250px\",\"Width\":\"300px\"},\"Sponsor\":{\"Color\":{\"R\":35,\"G\":35,\"B\":35,\"A\":100},\"Label\":true,\"WithoutLogo\":false},\"Title\":{\"Color\":{\"R\":219,\"G\":181,\"B\":255,\"A\":100}}},\"Selector\":{\"Kind\":\"CSS\",\"Css\":\"#ayl-prebid-a11a121205932e75e622af275681965d\"},\"Insertion\":\"AFTER\",\"ClickFormat\":true,\"Creative20\":true,\"WidgetKind\":\"CREATIVE_TEMPLATE_4\"}},\"Legal\":\"Sponsored\",\"ForcedCampaign\":\"f1c80d4bb5643c222ae8de75e9b2f991\",\"ForcedTrack\":\"\",\"ForcedCreative\":\"\",\"ForcedSource\":\"\",\"DisplayMode\":\"DEFAULT\",\"Campaign\":\"f1c80d4bb5643c222ae8de75e9b2f991\",\"CampaignAccess\":\"ALL\",\"CampaignKind\":\"AD_TRAFFIC\",\"DataSource\":\"LOCAL\",\"DataSourceUrl\":\"\",\"DataSourceOnEventsIsolated\":false,\"DataSourceWithoutCookie\":false,\"Content\":{\"Preview\":{\"Thumbnail\":{\"Image\":{\"Kind\":\"EXTERNAL\",\"Data\":{\"External\":{\"Url\":\"https://tag-dyn.omnitagjs.com/fo-dyn/native/preview/image?key=fd4362d35bb174d6f1c80d4bb5643c22\\u0026kind=INTERNAL\\u0026ztop=0.000000\\u0026zleft=0.000000\\u0026zwidth=0.333333\\u0026zheight=1.000000\\u0026width=[width]\\u0026height=[height]\"}},\"ZoneTop\":0,\"ZoneLeft\":0,\"ZoneWidth\":1,\"ZoneHeight\":1,\"Smart\":false,\"NoTransform\":false,\"Quality\":\"NORMAL\"}},\"Text\":{\"CALLTOACTION\":\"Click here to learn more\",\"DESCRIPTION\":\"Considérant l'extrémité conjoncturelle, il serait bon d'anticiper toutes les voies de bon sens.\",\"SPONSOR\":\"Tested by\",\"TITLE\":\"Adserver Traffic Redirect Internal\"},\"Sponsor\":{\"Name\":\"QA Team\"},\"Credit\":{\"Logo\":{\"Resource\":{\"Kind\":\"EXTERNAL\",\"Data\":{\"External\":{\"Url\":\"https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png\"}},\"ZoneTop\":0,\"ZoneLeft\":0,\"ZoneWidth\":1,\"ZoneHeight\":1,\"Smart\":false,\"NoTransform\":false,\"Quality\":\"NORMAL\"}},\"Url\":\"https://blobs.omnitagjs.com/adchoice/\"}},\"Landing\":{\"Url\":\"https://www.w3.org/People/mimasa/test/xhtml/entities/entities-11.xhtml#lat1\",\"LegacyTracking\":false},\"ViewButtons\":{\"Close\":{\"Skip\":6000}},\"InternalContentFields\":{\"AnimatedImage\":false}},\"AdDomain\":\"adyoulike.com\",\"Opener\":\"REDIRECT\",\"PerformUITriggers\":[\"CLICK\"],\"RedirectionTarget\":\"TAB\"}/*PREBID*/;\n\tvar insertAds = function insertAds() {\insertAds();\n\t}\n})();\n\u003c/script\u003e"; const responseWithSinglePlacement = [ { 'BidID': 'bid_id_0', 'Placement': 'placement_0', - 'Ad': 'placement_0', + 'Ad': admSample, 'Price': 0.5, 'Height': 600, } @@ -214,15 +286,34 @@ describe('Adyoulike Adapter', function () { 'transactionId': 'bid_id_1_transaction_id' }; + let nativeBid = { + 'bidId': 'bid_id_1', + 'bidder': 'adyoulike', + 'placementCode': 'adunit/hb-1', + 'params': { + 'placement': 'placement_1' + }, + mediaTypes: { + native: { + + } + }, + 'transactionId': 'bid_id_1_transaction_id' + }; + it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); + expect(!!spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return true when required params found for native ad', function () { + expect(!!spec.isBidRequestValid(nativeBid)).to.equal(true); }); it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.size; - expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(!!spec.isBidRequestValid(bid)).to.equal(false); }); it('should return false when required params are not passed', function () { @@ -231,7 +322,7 @@ describe('Adyoulike Adapter', function () { bid.params = { 'placement': 0 }; - expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(!!spec.isBidRequestValid(bid)).to.equal(false); }); }); @@ -384,7 +475,7 @@ describe('Adyoulike Adapter', function () { expect(result.length).to.equal(1); expect(result[0].cpm).to.equal(0.5); - expect(result[0].ad).to.equal('placement_0'); + expect(result[0].ad).to.equal(admSample); expect(result[0].width).to.equal(300); expect(result[0].height).to.equal(600); }); @@ -405,5 +496,47 @@ describe('Adyoulike Adapter', function () { expect(result[1].width).to.equal(400); expect(result[1].height).to.equal(250); }); + + it('receive reponse with Native ad', function () { + serverResponse.body = responseWithSinglePlacement; + let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidNative) + '}'}); + + expect(result.length).to.equal(1); + + expect(result).to.deep.equal([{ + cpm: 0.5, + creativeId: undefined, + currency: 'USD', + netRevenue: true, + requestId: 'bid_id_0', + ttl: 3600, + mediaType: 'native', + native: { + body: 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.', + clickTrackers: [ + 'https://testPixelCLICK.com/fake' + ], + clickUrl: 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1', + cta: 'Click here to learn more', + image: { + height: 600, + url: 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22', + width: 300, + }, + impressionTrackers: [ + 'https://testPixelIMP.com/fake', + 'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991' + ], + javascriptTrackers: [ + 'https://testJsIMP.com/fake.js' + ], + privacyIcon: 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png', + privacyLink: 'https://blobs.omnitagjs.com/adchoice/', + sponsoredBy: 'QA Team', + title: 'Adserver Traffic Redirect Internal', + } + + }]); + }); }); }); From 29cd8c16e9f8bc0257b2a19caad78d11e90c6990 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 15 Jan 2021 15:46:09 +0100 Subject: [PATCH 15/17] update md file --- modules/adyoulikeBidAdapter.md | 60 +++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/modules/adyoulikeBidAdapter.md b/modules/adyoulikeBidAdapter.md index 120bee3bcbb..d0e7fa8883b 100644 --- a/modules/adyoulikeBidAdapter.md +++ b/modules/adyoulikeBidAdapter.md @@ -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, + DC: "fra01", // Optional for set the data center name + } + }] + }; ``` From 24530ffccc5003c712a5b23ac41a2cfbbf94b198 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 15 Jan 2021 17:20:45 +0100 Subject: [PATCH 16/17] remove usage of URLSearchParams --- modules/adyoulikeBidAdapter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 91a6198b6a4..66dfe1635f7 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -228,10 +228,10 @@ function getImageUrl(config, resource, width, height) { extUrl = extUrl.replace(/\[width\]/i, '' + width); if (extUrl.indexOf(dynPrefix) >= 0) { - const urlParams = new URLSearchParams(extUrl.split('?')[1]); - url = urlParams.get('url'); + const urlmatch = (/.*url=([^&]*)/gm).exec(extUrl); + url = urlmatch ? urlmatch[1] : ''; if (!url) { - url = getInternalImgUrl(urlParams.get('key')); + url = getInternalImgUrl((/.*key=([^&]*)/gm).exec(extUrl)[1]); } } else { url = extUrl; From 52575eafac52763d00e0bcdc7f324e1054bfd8e1 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 18 Jan 2021 15:17:00 +0100 Subject: [PATCH 17/17] allox pure native ad with no adm provided --- modules/adyoulikeBidAdapter.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 66dfe1635f7..308d474d2c4 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -258,25 +258,29 @@ function getTrackers(eventsArray, jsTrackers) { } function getNativeAssets(response, nativeConfig) { - const adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); - const textsJson = adJson.Content.Preview.Text; + const native = {}; - var impressionUrl = adJson.TrackingPrefix + - '/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt; + var adJson = {}; + var textsJson = {}; + if (typeof response.Ad === 'string') { + adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); + textsJson = adJson.Content.Preview.Text; - if (adJson.Campaign) { - impressionUrl += '&campaign=' + adJson.Campaign; - } + var impressionUrl = adJson.TrackingPrefix + + '/pixel?event_kind=IMPRESSION&attempt=' + adJson.Attempt; - const native = {}; + 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.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); + 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') { @@ -340,7 +344,7 @@ function getNativeAssets(response, nativeConfig) { /* Create bid from response */ function createBid(response, bidRequests) { - if (!response || !response.Ad) { + if (!response || (!response.Ad && !response.Native)) { return }