Skip to content

Commit

Permalink
Only set native targeting if value exists. (prebid#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanek authored and Pedro López Jiménez committed Mar 18, 2019
1 parent 8c10dcf commit 54c5bba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function fireNativeTrackers(message, adObject) {
}

/**
* Gets native targeting key-value paris
* Gets native targeting key-value pairs
* @param {Object} bid
* @return {Object} targeting
*/
Expand All @@ -163,7 +163,7 @@ export function getNativeTargeting(bid) {
value = value.url;
}

if (key) {
if (key && value) {
keyValues[key] = value;
}
});
Expand Down
23 changes: 23 additions & 0 deletions test/spec/native_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ const bid = {
}
};

const bidWithUndefinedFields = {
native: {
title: 'Native Creative',
body: undefined,
cta: undefined,
sponsoredBy: 'AppNexus',
clickUrl: 'https://www.link.example',
clickTrackers: ['https://tracker.example'],
impressionTrackers: ['https://impression.example'],
javascriptTrackers: '<script src=\"http://www.foobar.js\"></script>'
}
};

describe('native.js', function () {
let triggerPixelStub;
let insertHtmlIntoIframeStub;
Expand All @@ -37,6 +50,16 @@ describe('native.js', function () {
expect(targeting[CONSTANTS.NATIVE_KEYS.clickUrl]).to.equal(bid.native.clickUrl);
});

it('should only include native targeting keys with values', function () {
const targeting = getNativeTargeting(bidWithUndefinedFields);

expect(Object.keys(targeting)).to.deep.equal([
CONSTANTS.NATIVE_KEYS.title,
CONSTANTS.NATIVE_KEYS.sponsoredBy,
CONSTANTS.NATIVE_KEYS.clickUrl
]);
});

it('fires impression trackers', function () {
fireNativeTrackers({}, bid);
sinon.assert.calledOnce(triggerPixelStub);
Expand Down

0 comments on commit 54c5bba

Please sign in to comment.