forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartyadsAnalyticsAdapter.js
133 lines (116 loc) · 3.12 KB
/
smartyadsAnalyticsAdapter.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { EVENTS } from '../src/constants.js';
import { ajax } from '../src/ajax.js';
const {
AUCTION_INIT,
AUCTION_END,
BID_WON,
BID_TIMEOUT,
BIDDER_ERROR,
BID_REJECTED,
BID_REQUESTED,
AD_RENDER_FAILED,
AD_RENDER_SUCCEEDED,
AUCTION_TIMEOUT
} = EVENTS;
const URL = 'https://ps.itdsmr.com';
const ANALYTICS_TYPE = 'endpoint';
const BIDDER_CODE = 'smartyads';
const GVLID = 534;
let smartyParams = {};
let smartyadsAdapter = Object.assign({},
adapter({
url: URL,
analyticsType: ANALYTICS_TYPE,
}),
{
track({ eventType, args }) {
switch (eventType) {
case AUCTION_INIT:
case AUCTION_TIMEOUT:
case AUCTION_END:
auctionHandler(eventType, args);
break;
case BID_REQUESTED:
if (args.bidderCode === BIDDER_CODE) {
for (const bid of args.bids) {
const bidParams = bid.params?.length ? bid.params[0] : bid.params;
smartyParams[bid.bidId] = bidParams;
}
};
break;
case BID_WON:
case BID_TIMEOUT:
case BID_REJECTED:
bidHandler(eventType, args);
break;
case BIDDER_ERROR:
onBidderError(args);
break;
case AD_RENDER_FAILED:
case AD_RENDER_SUCCEEDED:
onAdRender(eventType, args);
break;
default:
break;
}
}
}
);
const sendDataToServer = (data) => {
ajax(URL, () => {}, JSON.stringify(data));
}
const auctionHandler = (eventType, data) => {
const auctionData = {
auctionId: data.auctionId,
status: eventType,
timeout: data.timeout,
metrics: data.metrics,
bidderRequests: data.bidderRequests?.map(bidderRequest => {
delete bidderRequest.gdprConsent;
delete bidderRequest.refererInfo;
return bidderRequest;
}).filter(request => request.bidderCode === BIDDER_CODE),
}
sendDataToServer({ eventType, auctionData });
}
const bidHandler = (eventType, bid) => {
let bids = bid.length ? bid : [ bid ];
for (const bidObj of bids) {
let bidToSend;
if (bidObj.bidderCode != BIDDER_CODE) {
if (eventType === BID_WON) {
bidToSend = {
cpm: bidObj.cpm,
auctionId: bidObj.auctionId
};
} else continue;
}
bidToSend = bidObj;
if (eventType === BID_REJECTED) {
bidToSend.params = smartyParams[bid.requestId];
}
sendDataToServer({ eventType, bid: bidToSend });
}
}
const onBidderError = (data) => {
sendDataToServer({
eventType: BIDDER_ERROR,
error: data.error,
bidderRequests: data?.bidderRequests?.length
? data.bidderRequests.filter(request => request.bidderCode === BIDDER_CODE)
: [ data.bidderRequest ]
});
}
const onAdRender = (eventType, data) => {
if (data?.bid?.bidderCode === BIDDER_CODE) {
sendDataToServer({ eventType, renderData: data });
}
}
adapterManager.registerAnalyticsAdapter({
adapter: smartyadsAdapter,
code: BIDDER_CODE,
gvlid: GVLID
})
export default smartyadsAdapter;