From 3bb635295dd7037955cb0797ee1d1498074e1f5e Mon Sep 17 00:00:00 2001 From: renebaudisch Date: Tue, 29 Sep 2020 12:47:13 +0200 Subject: [PATCH 1/5] adding options to renderAd method --- src/prebid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prebid.js b/src/prebid.js index 31e0140cfe2..3ea349ac985 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -342,7 +342,7 @@ function emitAdRenderFail({ reason, message, bid, id }) { * @param {string} id bid id to locate the ad * @alias module:pbjs.renderAd */ -$$PREBID_GLOBAL$$.renderAd = function (doc, id) { +$$PREBID_GLOBAL$$.renderAd = function (doc, id, options) { utils.logInfo('Invoking $$PREBID_GLOBAL$$.renderAd', arguments); utils.logMessage('Calling renderAd with adId :' + id); From 3c3318d207c5a8ff56aa02ee16e30b2cb9f56270 Mon Sep 17 00:00:00 2001 From: renebaudisch Date: Tue, 29 Sep 2020 12:47:34 +0200 Subject: [PATCH 2/5] adding replaceClickThrough method to utils --- src/utils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils.js b/src/utils.js index 9426308daf4..025ac393af0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -718,6 +718,11 @@ export function replaceAuctionPrice(str, cpm) { return str.replace(/\$\{AUCTION_PRICE\}/g, cpm); } +export function replaceClickThrough(str, clicktag) { + if (!str) return; + return str.replace(/\$\{CLICKTHROUGH\}/g, clicktag); +} + export function timestamp() { return new Date().getTime(); } From c521bbb79113d78dadf4e06f91cf8c204179a695 Mon Sep 17 00:00:00 2001 From: renebaudisch Date: Tue, 29 Sep 2020 12:49:12 +0200 Subject: [PATCH 3/5] implemented replaceClickThrough method in render ad to enable ssps adding url param clickthrough for publisher side counting --- src/prebid.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/prebid.js b/src/prebid.js index 3ea349ac985..9a91e3eea57 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -354,6 +354,12 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id, options) { // replace macros according to openRTB with price paid = bid.cpm bid.ad = utils.replaceAuctionPrice(bid.ad, bid.cpm); bid.adUrl = utils.replaceAuctionPrice(bid.adUrl, bid.cpm); + + // replacing clickthrough if submitted + const { clickThrough } = options; + bid.ad = utils.replaceClickThrough(bid.ad, clickThrough); + bid.adUrl = utils.replaceClickThrough(bid.adUrl, clickThrough); + // save winning bids auctionManager.addWinningBid(bid); From 2f8d90ea8acae4fd51f65a1dc416825e2497d965 Mon Sep 17 00:00:00 2001 From: renebaudisch Date: Thu, 1 Oct 2020 09:38:52 +0200 Subject: [PATCH 4/5] update to cover some validation and unit tests as requested by harpere --- src/prebid.js | 8 +++++--- src/utils.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/prebid.js b/src/prebid.js index 9a91e3eea57..8d1d7ca1253 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -356,9 +356,11 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id, options) { bid.adUrl = utils.replaceAuctionPrice(bid.adUrl, bid.cpm); // replacing clickthrough if submitted - const { clickThrough } = options; - bid.ad = utils.replaceClickThrough(bid.ad, clickThrough); - bid.adUrl = utils.replaceClickThrough(bid.adUrl, clickThrough); + if (options && options.clickThrough) { + const { clickThrough } = options; + bid.ad = utils.replaceClickThrough(bid.ad, clickThrough); + bid.adUrl = utils.replaceClickThrough(bid.adUrl, clickThrough); + } // save winning bids auctionManager.addWinningBid(bid); diff --git a/src/utils.js b/src/utils.js index 025ac393af0..8af7a25668d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -719,8 +719,8 @@ export function replaceAuctionPrice(str, cpm) { } export function replaceClickThrough(str, clicktag) { - if (!str) return; - return str.replace(/\$\{CLICKTHROUGH\}/g, clicktag); + if (!str || !clicktag || typeof clicktag !== 'string') return; + return str.replace(/\${CLICKTHROUGH}/g, clicktag); } export function timestamp() { From 0233f81ddebd081282fd2b5b783248b8a5857ed2 Mon Sep 17 00:00:00 2001 From: renebaudisch Date: Thu, 1 Oct 2020 18:44:37 +0200 Subject: [PATCH 5/5] adding unit test for clickthrough implementation; --- test/spec/unit/pbjs_api_spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 960ccf08c92..efb1338ac5d 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1197,6 +1197,14 @@ describe('Unit: Prebid Module', function () { assert.deepEqual($$PREBID_GLOBAL$$.getAllWinningBids()[0], adResponse); }); + it('should replace ${CLICKTHROUGH} macro in winning bids response', function () { + pushBidResponseToAuction({ + ad: "" + }); + $$PREBID_GLOBAL$$.renderAd(doc, bidId, {clickThrough: 'https://someadserverclickurl.com'}); + expect(adResponse).to.have.property('ad').and.to.match(/https:\/\/someadserverclickurl\.com/i); + }); + it('fires billing url if present on s2s bid', function () { const burl = 'http://www.example.com/burl'; pushBidResponseToAuction({