forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharethroughAnalyticsAdapter.js
71 lines (60 loc) · 2.14 KB
/
sharethroughAnalyticsAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js';
const emptyUrl = '';
const analyticsType = 'endpoint';
const STR_BIDDER_CODE = 'sharethrough';
const STR_VERSION = '0.1.0';
var sharethroughAdapter = Object.assign(adapter(
{
emptyUrl,
analyticsType
}
),
{
STR_BEACON_HOST: 'https://b.sharethrough.com/butler?',
placementCodeSet: {},
track({ eventType, args }) {
if (eventType === 'bidRequested' && args.bidderCode === 'sharethrough') {
var bids = args.bids;
var keys = Object.keys(bids);
for (var i = 0; i < keys.length; i++) {
this.placementCodeSet[bids[keys[i]].placementCode] = args.bids[keys[i]];
}
}
if (eventType === 'bidWon') {
this.bidWon(args);
}
},
bidWon(args) {
const curBidderCode = args.bidderCode;
if (curBidderCode !== STR_BIDDER_CODE && (args.adUnitCode in this.placementCodeSet)) {
let strBid = this.placementCodeSet[args.adUnitCode];
this.fireLoseBeacon(curBidderCode, args.cpm, strBid.adserverRequestId, 'headerBidLose');
}
},
fireLoseBeacon(winningBidderCode, winningCPM, arid, type) {
let loseBeaconUrl = this.STR_BEACON_HOST;
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerBidderCode', winningBidderCode);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerCpm', winningCPM);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'arid', arid);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'type', type);
loseBeaconUrl = this.appendEnvFields(loseBeaconUrl);
this.fireBeacon(loseBeaconUrl);
},
appendEnvFields(url) {
url = tryAppendQueryString(url, 'hbVersion', '$prebid.version$');
url = tryAppendQueryString(url, 'strVersion', STR_VERSION);
url = tryAppendQueryString(url, 'hbSource', 'prebid');
return url;
},
fireBeacon(theUrl) {
const img = new Image();
img.src = theUrl;
}
});
adapterManager.registerAnalyticsAdapter({
adapter: sharethroughAdapter,
code: 'sharethrough'
});
export default sharethroughAdapter;