Skip to content

Commit

Permalink
Fix API calls for rivr analytics impressions and clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroDG committed Nov 2, 2018
1 parent 144e212 commit 3fff417
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 12 additions & 6 deletions modules/rivrAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function sendAuction() {
`http://${rivrAnalytics.context.host}/${rivrAnalytics.context.clientID}/auctions`,
() => {},
JSON.stringify(req),
// TODO extract this object to variable
{
contentType: 'application/json',
customHeaders: {
Expand All @@ -80,7 +79,7 @@ export function sendImpressions() {
let impressionsReq = Object.assign({}, {impressions});
logInfo('sending impressions request to analytics => ', impressionsReq);
ajax(
`http://${rivrAnalytics.context.host}/impressions`,
`http://${rivrAnalytics.context.host}/${rivrAnalytics.context.clientID}/impressions`,
() => {},
JSON.stringify(impressionsReq),
{
Expand Down Expand Up @@ -240,10 +239,17 @@ export function reportClickEvent(event) {
'click_url': clickUrl
};
logInfo('Sending click events with parameters: ', req);

// TODO add Authentication header
ajax(`http://${rivrAnalytics.context.host}/${rivrAnalytics.context.clientID}/clicks`, () => {
}, JSON.stringify(req));
ajax(
`http://${rivrAnalytics.context.host}/${rivrAnalytics.context.clientID}/clicks`,
() => {},
JSON.stringify(req),
{
contentType: 'application/json',
customHeaders: {
'Authorization': 'Basic ' + rivrAnalytics.context.authToken
}
}
);
};

function addClickHandler(bannerId) {
Expand Down
11 changes: 8 additions & 3 deletions test/spec/modules/rivrAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ describe('RIVR Analytics adapter', () => {
it('sendImpressions(), when authToken is defined and there are impressions, it sends impressions to the tracker', () => {
const aMockString = 'anImpressionPropertyValue';
const IMPRESSION_MOCK = { anImpressionProperty: aMockString };
const CLIENT_ID_MOCK = 'aClientID';
analyticsAdapter.context = utils.deepClone(CONTEXT_AFTER_AUCTION_INIT);
analyticsAdapter.context.authToken = 'anAuthToken';
analyticsAdapter.context.clientID = CLIENT_ID_MOCK;
analyticsAdapter.context.queue = new ExpiringQueue(
() => {},
() => {},
Expand All @@ -376,12 +378,13 @@ describe('RIVR Analytics adapter', () => {

expect(ajaxStub.callCount).to.be.equal(1);
expect(payload.impressions.length).to.be.equal(1);
expect(ajaxStub.getCall(0).args[0]).to.match(/http:\/\/tracker.rivr.simplaex.com\/impressions/);
expect(ajaxStub.getCall(0).args[0]).to.match(/http:\/\/tracker.rivr.simplaex.com\/aClientID\/impressions/);
expect(payload.impressions[0].anImpressionProperty).to.be.equal(aMockString);
});

it('reportClickEvent(), when authToken is not defined, it calls endpoint', () => {
it('reportClickEvent() calls endpoint', () => {
const CLIENT_ID_MOCK = 'aClientId';
const AUTH_TOKEN_MOCK = 'aToken';
const CLICK_URL_MOCK = 'clickURLMock';
const EVENT_MOCK = {
currentTarget: {
Expand All @@ -397,7 +400,7 @@ describe('RIVR Analytics adapter', () => {
}
};
analyticsAdapter.context = utils.deepClone(CONTEXT_AFTER_AUCTION_INIT);
analyticsAdapter.context.authToken = undefined;
analyticsAdapter.context.authToken = AUTH_TOKEN_MOCK;
analyticsAdapter.context.clientID = CLIENT_ID_MOCK;
analyticsAdapter.context.auctionObject.nullProperty = null;
analyticsAdapter.context.auctionObject.notNullProperty = 'aValue';
Expand All @@ -407,9 +410,11 @@ describe('RIVR Analytics adapter', () => {
reportClickEvent(EVENT_MOCK);

const payload = JSON.parse(ajaxStub.getCall(0).args[2]);
const options = ajaxStub.getCall(0).args[3];

expect(ajaxStub.callCount).to.be.equal(1);
expect(ajaxStub.getCall(0).args[0]).to.match(/http:\/\/tracker.rivr.simplaex.com\/aClientId\/clicks/);
expect(options.customHeaders.Authorization).to.equal('Basic aToken');
expect(payload.timestamp).to.be.equal('1970-01-01T00:00:00.000Z');
expect(payload.request_id).to.be.a('string');
expect(payload.click_url).to.be.equal(CLICK_URL_MOCK);
Expand Down

0 comments on commit 3fff417

Please sign in to comment.