Skip to content

Commit

Permalink
Rvr 2369 add trackable add ad units event (#3691)
Browse files Browse the repository at this point in the history
* RVR-2177 - Refactor events handling

* RVR-2087 - Inject pbjsGlobalVariable into rivraddon

* RVR-2087 - update adapterManager dependency

* RVR-2087 - Add ADD_AD_UNITS to Prebid.JS trackable events

* RVR-2369 - Update package-lock.json

* RVR-2369 - Revert rivrAnalyticsAdapter changed

Handled in separate PR #3683

* RVR-2369 - Add REQUEST_BIDS to trackable events
  • Loading branch information
AlessandroDG authored and Isaac Dettman committed Apr 1, 2019
1 parent 3b43f25 commit 6723904
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
EVENTS: {
AUCTION_INIT,
AUCTION_END,
REQUEST_BIDS,
BID_REQUESTED,
BID_TIMEOUT,
BID_RESPONSE,
Expand All @@ -16,7 +17,8 @@ const {
BID_ADJUSTMENT,
BIDDER_DONE,
SET_TARGETING,
AD_RENDER_FAILED
AD_RENDER_FAILED,
ADD_AD_UNITS
}
} = CONSTANTS;

Expand Down Expand Up @@ -99,6 +101,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
// Next register event listeners to send data immediately

_handlers = {
[REQUEST_BIDS]: args => this.enqueue({ eventType: REQUEST_BIDS, args }),
[BID_REQUESTED]: args => this.enqueue({ eventType: BID_REQUESTED, args }),
[BID_RESPONSE]: args => this.enqueue({ eventType: BID_RESPONSE, args }),
[NO_BID]: args => this.enqueue({ eventType: NO_BID, args }),
Expand All @@ -109,6 +112,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
[SET_TARGETING]: args => this.enqueue({ eventType: SET_TARGETING, args }),
[AUCTION_END]: args => this.enqueue({ eventType: AUCTION_END, args }),
[AD_RENDER_FAILED]: args => this.enqueue({ eventType: AD_RENDER_FAILED, args }),
[ADD_AD_UNITS]: args => this.enqueue({ eventType: ADD_AD_UNITS, args }),
[AUCTION_INIT]: args => {
args.config = typeof config === 'object' ? config.options || {} : {}; // enableAnaltyics configuration object
this.enqueue({ eventType: AUCTION_INIT, args });
Expand Down
24 changes: 24 additions & 0 deletions test/spec/AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { expect } from 'chai';
import events from 'src/events';
import CONSTANTS from 'src/constants.json';

const REQUEST_BIDS = CONSTANTS.EVENTS.REQUEST_BIDS;
const BID_REQUESTED = CONSTANTS.EVENTS.BID_REQUESTED;
const BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE;
const BID_WON = CONSTANTS.EVENTS.BID_WON;
const BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT;
const AD_RENDER_FAILED = CONSTANTS.EVENTS.AD_RENDER_FAILED;
const ADD_AD_UNITS = CONSTANTS.EVENTS.ADD_AD_UNITS;

const AnalyticsAdapter = require('src/AnalyticsAdapter').default;
const config = {
Expand Down Expand Up @@ -86,6 +88,28 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'});
});

it('SHOULD call global when an addAdUnits event occurs', function () {
const eventType = ADD_AD_UNITS;
const args = { call: 'addAdUnits' };

adapter.enableAnalytics();
events.emit(eventType, args);

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'addAdUnits'}, eventType: 'addAdUnits'});
});

it('SHOULD call global when a requestBids event occurs', function () {
const eventType = REQUEST_BIDS;
const args = { call: 'request' };

adapter.enableAnalytics();
events.emit(eventType, args);

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'requestBids'});
});

it('SHOULD call global when a bidRequest event occurs', function () {
const eventType = BID_REQUESTED;
const args = { call: 'request' };
Expand Down

0 comments on commit 6723904

Please sign in to comment.