Skip to content

Commit

Permalink
Integrate option to pass clickThrough urls to renderAd method (prebid…
Browse files Browse the repository at this point in the history
…#5796)

* adding options to renderAd method

* adding replaceClickThrough method to utils

* implemented replaceClickThrough method in render ad to enable ssps adding url param clickthrough for publisher side counting

* update to cover some validation and unit tests as requested by harpere

* adding unit test for clickthrough implementation;
  • Loading branch information
renebaudisch authored and stsepelin committed May 28, 2021
1 parent cb71a40 commit ebe9476
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -354,6 +354,14 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id) {
// 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
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);

Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ export function replaceAuctionPrice(str, cpm) {
return str.replace(/\$\{AUCTION_PRICE\}/g, cpm);
}

export function replaceClickThrough(str, clicktag) {
if (!str || !clicktag || typeof clicktag !== 'string') return;
return str.replace(/\${CLICKTHROUGH}/g, clicktag);
}

export function timestamp() {
return new Date().getTime();
}
Expand Down
8 changes: 8 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<script type='text/javascript' src='http://server.example.com/ad/ad.js?clickthrough=${CLICKTHROUGH}'></script>"
});
$$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({
Expand Down

0 comments on commit ebe9476

Please sign in to comment.