forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PubWise Analytics * Updates based on Feedback
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |