Skip to content

Commit

Permalink
OpenX: decode campaign data in openxAnalyticsAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kenan-gillet committed Sep 16, 2020
1 parent d3b32c0 commit 8c5cdd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions modules/openxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ function isValidConfig({options: analyticsOptions}) {
}

function buildCampaignFromUtmCodes() {
const location = utils.getWindowLocation();
const queryParams = utils.parseQS(location && location.search);
let campaign = {};
let queryParams = utils.parseQS(utils.getWindowLocation() && utils.getWindowLocation().search);

UTM_TAGS.forEach(function(utmKey) {
let utmValue = queryParams[utmKey];
if (utmValue) {
let key = UTM_TO_CAMPAIGN_PROPERTIES[utmKey];
campaign[key] = utmValue;
campaign[key] = decodeURIComponent(utmValue);
}
});
return campaign;
Expand Down
5 changes: 3 additions & 2 deletions test/spec/modules/openxAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('openx analytics adapter', function() {

it('should track values from query params when they exist', function () {
sinon.stub(utils, 'getWindowLocation').returns({search: '?' +
'utm_campaign=test-campaign-name&' +
'utm_campaign=test%20campaign-name&' +
'utm_source=test-source&' +
'utm_medium=test-medium&'
});
Expand All @@ -350,7 +350,8 @@ describe('openx analytics adapter', function() {
clock.tick(SLOT_LOAD_WAIT_TIME);
auction = JSON.parse(server.requests[0].requestBody)[0];

expect(auction.campaign.name).to.equal('test-campaign-name');
// ensure that value are URI decoded
expect(auction.campaign.name).to.equal('test campaign-name');
expect(auction.campaign.source).to.equal('test-source');
expect(auction.campaign.medium).to.equal('test-medium');
expect(auction.campaign.content).to.be.undefined;
Expand Down

0 comments on commit 8c5cdd9

Please sign in to comment.