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

ucfunnelAnalyticsAdapter #4432

Merged
merged 40 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d18db95
Add a new ucfunnel Adapter and test page
Jun 5, 2017
f82a4b7
Add a new ucfunnel Adapter and test page
Jun 5, 2017
4c91775
1. Use prebid lib in the repo to keep updated
RyanChouTw Jun 16, 2017
52eaecb
Merge branch 'master' into master
RyanChouTw Jun 16, 2017
96a70a4
utils.getTopWindowLocation is a function
RyanChouTw Jun 20, 2017
7202a62
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw Jun 28, 2017
858b833
Change to modules from adapters
RyanChouTw Jun 28, 2017
8b46932
Migrate to module design
RyanChouTw Jun 28, 2017
d7e043b
[Dev Fix] Remove width and height which can be got from ad unit id
RyanChouTw Jul 13, 2017
badfa53
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw Jul 13, 2017
8d81704
Merge pull request #1 from prebid/master
RyanChouTw Sep 25, 2017
8e7fe31
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw Dec 21, 2017
5dc00f3
Update ucfunnelBidAdapter to fit into new spec
RyanChouTw Dec 21, 2017
66c3a06
Correct the endpoint. Fix the error of query string
RyanChouTw Dec 21, 2017
0328e97
Add test case for ucfunnelBidAdapter
RyanChouTw Jan 11, 2018
c2c5eb0
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw Jan 11, 2018
86fdd23
Fix lint error
RyanChouTw Jan 12, 2018
c331f57
Update version number
RyanChouTw Jan 16, 2018
28acb40
Combine all checks on bid request
RyanChouTw Jan 18, 2018
93621b8
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw May 25, 2018
f7f2515
Add GDPR support for ucfunnel adapter
RyanChouTw May 25, 2018
d4f3467
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw Jun 14, 2018
1f79c44
Add in-stream video and native support for ucfunnel adapter
RyanChouTw Jun 14, 2018
7d8dc52
Remove demo page. Add more test cases.
RyanChouTw Jun 20, 2018
99fa86e
Change request method from POST to GET
RyanChouTw Jun 26, 2018
03e37e6
Remove unnecessary comment
RyanChouTw Jun 27, 2018
aabfdd4
Support vastXml and vastUrl for video request
RyanChouTw Jul 3, 2018
2177c15
Merge branch 'master' of https://github.com/prebid/Prebid.js
Dec 2, 2018
af05d07
update TTL to 30 mins
Dec 2, 2018
45614c9
Avoid using arrow function which is not discuraged in mocha
Dec 3, 2018
a5b402c
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jul 9, 2019
c22723e
ucfunnel tdid support
Jul 9, 2019
644b900
Merge branch 'master' of https://github.com/prebid/Prebid.js into HEAD
Oct 21, 2019
0175c57
ucfunnel fix error message in debug mode
Oct 17, 2019
7c20e1d
Create ucfunnelAnalyticsAdapter.js
Nov 1, 2019
5f9f2e8
[Dev Fix]add id
Nov 5, 2019
02ed2ae
Update ucfunnelAnalyticsAdapter.js
Nov 6, 2019
5c3d35c
Update ucfunnelAnalyticsAdapter.md
Nov 6, 2019
4cc7d34
add test
Nov 7, 2019
81badfa
Bug Fix and test passed
Nov 8, 2019
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
198 changes: 198 additions & 0 deletions modules/ucfunnelAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import {ajax} from '../src/ajax';
import adapter from '../src/AnalyticsAdapter';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager';
import {logError, logInfo, deepClone} from '../src/utils';

const analyticsType = 'endpoint';

export const ANALYTICS_VERSION = '1.0.0';

const ANALYTICS_SERVER = 'https://hbwa.aralego.com';

const {
EVENTS: {
AUCTION_END,
BID_WON,
BID_TIMEOUT
}
} = CONSTANTS;

export const BIDDER_STATUS = {
BID: 'bid',
NO_BID: 'noBid',
BID_WON: 'bidWon',
TIMEOUT: 'timeout'
};

const analyticsOptions = {};

export const parseBidderCode = function (bid) {
let bidderCode = bid.bidderCode || bid.bidder;
return bidderCode.toLowerCase();
};

export const parseAdUnitCode = function (bidResponse) {
return bidResponse.adUnitCode.toLowerCase();
};

export const ucfunnelAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER, analyticsType}), {

cachedAuctions: {},

initConfig(config) {
/**
* Required option: pbuid
* Required option: adid
* @type {boolean}
*/
analyticsOptions.options = deepClone(config.options);
if (typeof config.options.pbuid !== 'string' || config.options.pbuid.length < 1) {
logError('"options.pbuid" is required.');
return false;
}
if (typeof config.options.adid !== 'string' || config.options.adid.length < 1) {
logError('"options.adid" is required.');
return false;
}
analyticsOptions.sampled = true;
if (typeof config.options.sampling === 'number') {
analyticsOptions.sampled = Math.random() < parseFloat(config.options.sampling);
}

analyticsOptions.pbuid = config.options.pbuid
analyticsOptions.adid = config.options.adid
analyticsOptions.server = ANALYTICS_SERVER;
return true;
},
sendEventMessage(endPoint, data) {
logInfo(`AJAX: ${endPoint}: ` + JSON.stringify(data));

ajax(`${analyticsOptions.server}/${endPoint}`, null, JSON.stringify(data), {
contentType: 'application/json',
withCredentials: true
});
},
createCommonMessage(auctionId) {
return {
version: ANALYTICS_VERSION,
auctionId: auctionId,
referrer: window.location.href,
sampling: analyticsOptions.options.sampling,
prebid: '$prebid.version$',
adid: analyticsOptions.adid,
pbuid: analyticsOptions.pbuid,
adUnits: {},
};
},
serializeBidResponse(bid, status) {
const result = {
prebidWon: (status === BIDDER_STATUS.BID_WON),
isTimeout: (status === BIDDER_STATUS.TIMEOUT),
status: status,
};
if (status === BIDDER_STATUS.BID || status === BIDDER_STATUS.BID_WON) {
Object.assign(result, {
time: bid.timeToRespond,
cpm: bid.cpm,
currency: bid.currency,
});
}
return result;
},
addBidResponseToMessage(message, bid, status) {
const adUnitCode = parseAdUnitCode(bid);
message.adUnits[adUnitCode] = message.adUnits[adUnitCode] || {};
const bidder = parseBidderCode(bid);
const bidResponse = this.serializeBidResponse(bid, status);
message.adUnits[adUnitCode][bidder] = bidResponse;
},
createBidMessage(auctionEndArgs, winningBids, timeoutBids) {
const {auctionId, timestamp, auctionEnd, adUnitCodes, bidsReceived, noBids} = auctionEndArgs;
const message = this.createCommonMessage(auctionId);

message.auctionElapsed = (auctionEnd - timestamp);

adUnitCodes.forEach((adUnitCode) => {
message.adUnits[adUnitCode] = {};
});

// In this situation, the bid exists in both noBids and bids arrays.
noBids.forEach(bid => this.addBidResponseToMessage(message, bid, BIDDER_STATUS.NO_BID));

// This array may contain some timeout bids (responses come back after auction timeout)
bidsReceived.forEach(bid => this.addBidResponseToMessage(message, bid, BIDDER_STATUS.BID));

// We handle timeout after bids since it's possible that a bid has a response, but the response comes back
// after auction end. In this case, the bid exists in both bidsReceived and timeoutBids arrays.
timeoutBids.forEach(bid => this.addBidResponseToMessage(message, bid, BIDDER_STATUS.TIMEOUT));

// mark the winning bids with prebidWon = true
winningBids.forEach(bid => {
const adUnitCode = parseAdUnitCode(bid);
const bidder = parseBidderCode(bid);
message.adUnits[adUnitCode][bidder].prebidWon = true;
});
return message;
},
createImpressionMessage(bid) {
const message = this.createCommonMessage(bid.auctionId);
this.addBidResponseToMessage(message, bid, BIDDER_STATUS.BID_WON);
return message;
},
getCachedAuction(auctionId) {
this.cachedAuctions[auctionId] = this.cachedAuctions[auctionId] || {
timeoutBids: [],
};
return this.cachedAuctions[auctionId];
},
handleAuctionEnd(auctionEndArgs) {
const cachedAuction = this.getCachedAuction(auctionEndArgs.auctionId);
const highestCpmBids = pbjs.getHighestCpmBids();
this.sendEventMessage('bid',
this.createBidMessage(auctionEndArgs, highestCpmBids, cachedAuction.timeoutBids)
);
},
handleBidTimeout(timeoutBids) {
timeoutBids.forEach((bid) => {
const cachedAuction = this.getCachedAuction(bid.auctionId);
cachedAuction.timeoutBids.push(bid);
});
},
handleBidWon(bidWonArgs) {
this.sendEventMessage('imp', this.createImpressionMessage(bidWonArgs));
},
track({eventType, args}) {
if (analyticsOptions.sampled) {
switch (eventType) {
case BID_WON:
this.handleBidWon(args);
break;
case BID_TIMEOUT:
this.handleBidTimeout(args);
break;
case AUCTION_END:
this.handleAuctionEnd(args);
break;
}
}
},
getAnalyticsOptions() {
return analyticsOptions;
},
});

// save the base class function
ucfunnelAnalyticsAdapter.originEnableAnalytics = ucfunnelAnalyticsAdapter.enableAnalytics;

// override enableAnalytics so we can get access to the config passed in from the page
ucfunnelAnalyticsAdapter.enableAnalytics = function (config) {
if (this.initConfig(config)) {
ucfunnelAnalyticsAdapter.originEnableAnalytics(config); // call the base class function
}
};

adapterManager.registerAnalyticsAdapter({
adapter: ucfunnelAnalyticsAdapter,
code: 'ucfunnelAnalytics'
});
23 changes: 23 additions & 0 deletions modules/ucfunnelAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Overview

```
Module Name: ucfunnel Analytics Adapter
Module Type: Analytics Adapter
Maintainer: [email protected]
```

# Description

Analytics adapter for ucfunnel

# Test Parameters

```
{
provider: 'ucfunnelAnalytics',
options: {
pbuid: "PBUID_FROM_UCFUNNEL"
adid: "BIDDING_ADID_FROM_UCFUNNEL"
}
}
```
9 changes: 5 additions & 4 deletions modules/ucfunnelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const spec = {
let bid = {
requestId: bidRequest.bidId,
cpm: ad.cpm || 0,
creativeId: ad.ad_id,
creativeId: ad.ad_id || bidRequest.params.adid,
dealId: ad.deal || null,
currency: 'USD',
netRevenue: true,
Expand Down Expand Up @@ -108,10 +108,11 @@ export const spec = {
break;
case BANNER:
default:
var size = parseSizes(bidRequest);
Object.assign(bid, {
width: ad.width,
height: ad.height,
ad: ad.adm
width: ad.width || size[0],
height: ad.height || size[1],
ad: ad.adm || ''
});
}

Expand Down
Loading