Skip to content

Commit 1a4c964

Browse files
matthewlanejsnellbaker
authored andcommitted
Send url value when replacing image and icons types (#3609)
1 parent 7dd9f8a commit 1a4c964

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/native.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ export function getNativeTargeting(bid, bidReq) {
157157

158158
Object.keys(bid['native']).forEach(asset => {
159159
const key = CONSTANTS.NATIVE_KEYS[asset];
160-
let value = bid['native'][asset];
161-
162-
// native image-type assets can be a string or an object with a url prop
163-
if (typeof value === 'object' && value.url) {
164-
value = value.url;
165-
}
160+
let value = getAssetValue(bid['native'][asset]);
166161

167162
const sendPlaceholder = deepAccess(
168163
bidReq,
@@ -195,10 +190,22 @@ export function getAssetMessage(data, adObject) {
195190

196191
data.assets.forEach(asset => {
197192
const key = getKeyByValue(CONSTANTS.NATIVE_KEYS, asset);
198-
const value = adObject.native[key];
193+
const value = getAssetValue(adObject.native[key]);
199194

200195
message.assets.push({ key, value });
201196
});
202197

203198
return message;
204199
}
200+
201+
/**
202+
* Native assets can be a string or an object with a url prop. Returns the value
203+
* appropriate for sending in adserver targeting or placeholder replacement.
204+
*/
205+
function getAssetValue(value) {
206+
if (typeof value === 'object' && value.url) {
207+
return value.url;
208+
}
209+
210+
return value;
211+
}

test/spec/native_spec.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ const bid = {
99
title: 'Native Creative',
1010
body: 'Cool description great stuff',
1111
cta: 'Do it',
12+
image: {
13+
url: 'http://cdn.example.com/p/creative-image/image.png',
14+
height: 83,
15+
width: 127
16+
},
17+
icon: {
18+
url: 'http://cdn.example.com/p/creative-image/icon.jpg',
19+
height: 742,
20+
width: 989
21+
},
1222
sponsoredBy: 'AppNexus',
1323
clickUrl: 'https://www.link.example',
1424
clickTrackers: ['https://tracker.example'],
@@ -96,16 +106,20 @@ describe('native.js', function () {
96106
message: 'Prebid Native',
97107
action: 'assetRequest',
98108
adId: '123',
99-
assets: ['hb_native_body', 'hb_native_linkurl'],
109+
assets: ['hb_native_body', 'hb_native_image', 'hb_native_linkurl'],
100110
};
101111

102112
const message = getAssetMessage(messageRequest, bid);
103113

104-
expect(message.assets.length).to.equal(2);
114+
expect(message.assets.length).to.equal(3);
105115
expect(message.assets).to.deep.include({
106116
key: 'body',
107117
value: bid.native.body
108118
});
119+
expect(message.assets).to.deep.include({
120+
key: 'image',
121+
value: bid.native.image.url
122+
});
109123
expect(message.assets).to.deep.include({
110124
key: 'clickUrl',
111125
value: bid.native.clickUrl

0 commit comments

Comments
 (0)