Skip to content

Commit 0b9dc7b

Browse files
GLStephenMatt Kendall
authored and
Matt Kendall
committed
Add PubWise Analytics (#1151)
* PubWise Analytics * Updates based on Feedback
1 parent 0eba2bc commit 0b9dc7b

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {ajax} from 'src/ajax';
2+
import adapter from 'AnalyticsAdapter';
3+
const utils = require('../../utils');
4+
5+
/****
6+
* PubWise.io Analytics
7+
* Contact: [email protected]
8+
* Developer: Stephen Johnston
9+
*/
10+
11+
const analyticsType = 'endpoint';
12+
let target_site = 'unknown';
13+
let target_url = 'https://staging.api.pubwise.io';
14+
let pw_version = '2.1.3';
15+
16+
let pubwiseAnalytics = Object.assign(adapter(
17+
{
18+
target_url,
19+
analyticsType
20+
}
21+
),
22+
{
23+
// Override AnalyticsAdapter functions by supplying custom methods
24+
track({eventType, args}) {
25+
/*
26+
The args object is not always available, in addition neither is the config object
27+
it is available on the first call and we can setup our config. Potential additional
28+
PR for later, but this solves this for now.
29+
*/
30+
if (args !== undefined && args.config !== undefined && args.config.site !== undefined && args.config.endpoint !== undefined) {
31+
target_site = args.config.site;
32+
target_url = args.config.endpoint;
33+
}
34+
utils.logInfo('Sending PubWise Analytics Event ' + eventType, args);
35+
ajax(target_url,
36+
(result) => utils.logInfo('PubWise Analytics Result', result), JSON.stringify({
37+
eventType,
38+
args,
39+
target_site,
40+
pw_version
41+
})
42+
);
43+
}
44+
});
45+
export default pubwiseAnalytics;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pubwiseAnalytics from 'src/adapters/analytics/pubwiseanalytics';
2+
let events = require('../../../../src/events');
3+
let adaptermanager = require('../../../../src/adaptermanager');
4+
let constants = require('../../../../src/constants.json');
5+
6+
describe('PubWise Prebid Analytics', function () {
7+
8+
describe('enableAnalytics', function () {
9+
10+
it('should catch all events', function () {
11+
sinon.spy(pubwiseAnalytics, 'track');
12+
13+
adaptermanager.registerAnalyticsAdapter({
14+
code: 'pubwiseanalytics',
15+
adapter: pubwiseAnalytics
16+
});
17+
18+
adaptermanager.enableAnalytics({
19+
provider: 'pubwiseanalytics',
20+
options: {
21+
site: ['test-test-test-test']
22+
}
23+
});
24+
25+
events.emit(constants.EVENTS.AUCTION_INIT, {});
26+
events.emit(constants.EVENTS.BID_REQUESTED, {});
27+
events.emit(constants.EVENTS.BID_RESPONSE, {});
28+
events.emit(constants.EVENTS.BID_WON, {});
29+
30+
events.emit(constants.EVENTS.AUCTION_END, {});
31+
events.emit(constants.EVENTS.BID_TIMEOUT, {});
32+
33+
/* testing for 6 calls, including the 2 we're not currently tracking */
34+
sinon.assert.callCount(pubwiseAnalytics.track, 6);
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)