Skip to content

Commit

Permalink
Add PubWise Analytics (prebid#1151)
Browse files Browse the repository at this point in the history
* PubWise Analytics

* Updates based on Feedback
  • Loading branch information
GLStephen authored and mobfxoHB committed Aug 21, 2023
1 parent 2c3d0a4 commit b443906
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/adapters/analytics/pubwiseanalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {ajax} from 'src/ajax';
import adapter from 'AnalyticsAdapter';
const utils = require('../../utils');

/****
* PubWise.io Analytics
* Contact: support@pubwise.io
* Developer: Stephen Johnston
*/

const analyticsType = 'endpoint';
let target_site = 'unknown';
let target_url = 'https://staging.api.pubwise.io';
let pw_version = '2.1.3';

let pubwiseAnalytics = Object.assign(adapter(
{
target_url,
analyticsType
}
),
{
// Override AnalyticsAdapter functions by supplying custom methods
track({eventType, args}) {
/*
The args object is not always available, in addition neither is the config object
it is available on the first call and we can setup our config. Potential additional
PR for later, but this solves this for now.
*/
if (args !== undefined && args.config !== undefined && args.config.site !== undefined && args.config.endpoint !== undefined) {
target_site = args.config.site;
target_url = args.config.endpoint;
}
utils.logInfo('Sending PubWise Analytics Event ' + eventType, args);
ajax(target_url,
(result) => utils.logInfo('PubWise Analytics Result', result), JSON.stringify({
eventType,
args,
target_site,
pw_version
})
);
}
});
export default pubwiseAnalytics;
37 changes: 37 additions & 0 deletions test/spec/adapters/analytics/pubwiseanalytics_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pubwiseAnalytics from 'src/adapters/analytics/pubwiseanalytics';
let events = require('../../../../src/events');
let adaptermanager = require('../../../../src/adaptermanager');
let constants = require('../../../../src/constants.json');

describe('PubWise Prebid Analytics', function () {

describe('enableAnalytics', function () {

it('should catch all events', function () {
sinon.spy(pubwiseAnalytics, 'track');

adaptermanager.registerAnalyticsAdapter({
code: 'pubwiseanalytics',
adapter: pubwiseAnalytics
});

adaptermanager.enableAnalytics({
provider: 'pubwiseanalytics',
options: {
site: ['test-test-test-test']
}
});

events.emit(constants.EVENTS.AUCTION_INIT, {});
events.emit(constants.EVENTS.BID_REQUESTED, {});
events.emit(constants.EVENTS.BID_RESPONSE, {});
events.emit(constants.EVENTS.BID_WON, {});

events.emit(constants.EVENTS.AUCTION_END, {});
events.emit(constants.EVENTS.BID_TIMEOUT, {});

/* testing for 6 calls, including the 2 we're not currently tracking */
sinon.assert.callCount(pubwiseAnalytics.track, 6);
});
});
});

0 comments on commit b443906

Please sign in to comment.