diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index 6dfe8f6b2c2..c8616894826 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -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: { @@ -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), { @@ -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) { diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index dca63bf935e..f903f6e9c2d 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -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( () => {}, () => {}, @@ -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: { @@ -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'; @@ -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);