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

Integrate option to pass clickThrough urls to renderAd method #5796

Merged
merged 5 commits into from
Oct 7, 2020
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
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