prebid-universal-creative 1.14.1 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -2
- package/.github/workflows/issue_tracker.yml +0 -1
- package/README.md +19 -3
- package/dist/amp.js +3 -0
- package/dist/banner.js +3 -0
- package/dist/creative.js +4 -3
- package/dist/creative.max.js +537 -585
- package/dist/load-cookie-with-consent.html +1 -1
- package/dist/load-cookie.html +1 -1
- package/dist/mobile.js +3 -0
- package/dist/native-render.js +3 -3
- package/dist/native-trk.js +3 -3
- package/dist/native.js +3 -0
- package/dist/uid.js +3 -3
- package/dist/video.js +3 -0
- package/gulpfile.js +84 -41
- package/package.json +80 -82
- package/src/ampOrMobile.js +14 -0
- package/src/creative.js +2 -9
- package/src/environment.js +62 -75
- package/src/legacy.js +29 -0
- package/src/legacyNativeRender.js +6 -0
- package/src/mobileAndAmpRender.js +239 -0
- package/src/nativeAssetManager.js +3 -6
- package/src/nativeRender.js +2 -2
- package/src/nativeRenderManager.js +5 -5
- package/src/postscribeRender.js +8 -0
- package/src/renderingManager.js +102 -359
- package/src/utils.js +1 -2
- package/template/amp/dfp-creative.html +1 -1
- package/test/spec/environment_spec.js +4 -11
- package/test/spec/legacyNativeRender_spec.js +25 -0
- package/test/spec/mobileAndAmpRender_spec.js +308 -0
- package/test/spec/nativeAssetManager_spec.js +1 -0
- package/test/spec/nativeRenderManager_spec.js +12 -11
- package/test/spec/nativeRender_spec.js +23 -0
- package/test/spec/renderingManager_spec.js +16 -265
- package/webpack.conf.js +3 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { renderCrossDomain, renderLegacy } from 'src/renderingManager';
|
2
2
|
import * as utils from 'src/utils';
|
3
3
|
import * as domHelper from 'src/domHelper';
|
4
4
|
import { expect } from 'chai';
|
@@ -70,251 +70,12 @@ describe('renderingManager', function() {
|
|
70
70
|
xhr.restore();
|
71
71
|
});
|
72
72
|
|
73
|
-
describe('mobile creative', function() {
|
74
|
-
let writeHtmlSpy;
|
75
|
-
let sendRequestSpy;
|
76
|
-
let triggerPixelSpy;
|
77
|
-
let mockWin;
|
78
|
-
|
79
|
-
before(function() {
|
80
|
-
writeHtmlSpy = sinon.spy(utils, 'writeAdHtml');
|
81
|
-
sendRequestSpy = sinon.spy(utils, 'sendRequest');
|
82
|
-
triggerPixelSpy = sinon.spy(utils, 'triggerPixel');
|
83
|
-
mockWin = merge(mocks.createFakeWindow('http://example.com'), renderingMocks().getWindowObject());
|
84
|
-
});
|
85
|
-
|
86
|
-
afterEach(function() {
|
87
|
-
writeHtmlSpy.resetHistory();
|
88
|
-
sendRequestSpy.resetHistory();
|
89
|
-
triggerPixelSpy.resetHistory();
|
90
|
-
});
|
91
|
-
|
92
|
-
after(function() {
|
93
|
-
writeHtmlSpy.restore();
|
94
|
-
sendRequestSpy.restore();
|
95
|
-
triggerPixelSpy.restore();
|
96
|
-
});
|
97
|
-
|
98
|
-
const env = {
|
99
|
-
isMobileApp: () => true,
|
100
|
-
isSafeFrame: () => false
|
101
|
-
};
|
102
|
-
|
103
|
-
it('should render mobile app creative', function() {
|
104
|
-
const renderObject = newRenderingManager(mockWin, env);
|
105
|
-
let ucTagData = {
|
106
|
-
cacheHost: 'example.com',
|
107
|
-
cachePath: '/path',
|
108
|
-
uuid: '123',
|
109
|
-
size: '300x250'
|
110
|
-
};
|
111
|
-
|
112
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
113
|
-
|
114
|
-
let response = {
|
115
|
-
width: 300,
|
116
|
-
height: 250,
|
117
|
-
crid: 123,
|
118
|
-
adm: 'ad-markup',
|
119
|
-
wurl: 'https://test.prebidcache.wurl'
|
120
|
-
};
|
121
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
122
|
-
expect(writeHtmlSpy.callCount).to.equal(1);
|
123
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/path?uuid=123');
|
124
|
-
});
|
125
|
-
|
126
|
-
it('should render mobile app creative with missing cache wurl', function() {
|
127
|
-
const renderObject = newRenderingManager(mockWin, env);
|
128
|
-
let ucTagData = {
|
129
|
-
cacheHost: 'example.com',
|
130
|
-
cachePath: '/path',
|
131
|
-
uuid: '123',
|
132
|
-
size: '300x250'
|
133
|
-
};
|
134
|
-
|
135
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
136
|
-
|
137
|
-
let response = {
|
138
|
-
width: 300,
|
139
|
-
height: 250,
|
140
|
-
crid: 123,
|
141
|
-
adm: 'ad-markup'
|
142
|
-
};
|
143
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
144
|
-
expect(writeHtmlSpy.callCount).to.equal(1);
|
145
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/path?uuid=123');
|
146
|
-
});
|
147
|
-
|
148
|
-
it('should render mobile app creative using default cacheHost and cachePath', function() {
|
149
|
-
const renderObject = newRenderingManager(mockWin, env);
|
150
|
-
let ucTagData = {
|
151
|
-
uuid: '123',
|
152
|
-
size: '300x250'
|
153
|
-
};
|
154
|
-
|
155
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
156
|
-
|
157
|
-
let response = {
|
158
|
-
width: 300,
|
159
|
-
height: 250,
|
160
|
-
crid: 123,
|
161
|
-
adm: 'ad-markup'
|
162
|
-
};
|
163
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
164
|
-
expect(writeHtmlSpy.callCount).to.equal(1);
|
165
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://prebid.adnxs.com/pbc/v1/cache?uuid=123');
|
166
|
-
});
|
167
|
-
|
168
|
-
// it('should catch errors from creative', function (done) {
|
169
|
-
// window.addEventListener('error', e => {
|
170
|
-
// done(e.error);
|
171
|
-
// });
|
172
|
-
|
173
|
-
// const consoleErrorSpy = sinon.spy(console, 'error');
|
174
|
-
|
175
|
-
// const renderObject = newRenderingManager(mockWin, env);
|
176
|
-
// let ucTagData = {
|
177
|
-
// cacheHost: 'example.com',
|
178
|
-
// cachePath: '/path',
|
179
|
-
// uuid: '123',
|
180
|
-
// size: '300x250'
|
181
|
-
// };
|
182
|
-
|
183
|
-
// renderObject.renderAd(mockWin.document, ucTagData);
|
184
|
-
|
185
|
-
// let response = {
|
186
|
-
// width: 300,
|
187
|
-
// height: 250,
|
188
|
-
// crid: 123,
|
189
|
-
// adm: '<script src="notExistingScript.js"></script>'
|
190
|
-
// };
|
191
|
-
// requests[0].respond(200, {}, JSON.stringify(response));
|
192
|
-
|
193
|
-
// setTimeout(()=>{
|
194
|
-
// expect(consoleErrorSpy.callCount).to.equal(1);
|
195
|
-
// done();
|
196
|
-
// }, 10);
|
197
|
-
// });
|
198
|
-
});
|
199
|
-
|
200
|
-
describe('amp creative', function() {
|
201
|
-
let writeHtmlSpy;
|
202
|
-
let sendRequestSpy;
|
203
|
-
let triggerPixelSpy;
|
204
|
-
let mockWin;
|
205
|
-
|
206
|
-
before(function() {
|
207
|
-
writeHtmlSpy = sinon.spy(utils, 'writeAdHtml');
|
208
|
-
sendRequestSpy = sinon.spy(utils, 'sendRequest');
|
209
|
-
triggerPixelSpy = sinon.spy(utils, 'triggerPixel');
|
210
|
-
mockWin = merge(mocks.createFakeWindow('http://example.com'), renderingMocks().getWindowObject());
|
211
|
-
});
|
212
|
-
|
213
|
-
afterEach(function() {
|
214
|
-
writeHtmlSpy.resetHistory();
|
215
|
-
sendRequestSpy.resetHistory();
|
216
|
-
triggerPixelSpy.resetHistory();
|
217
|
-
});
|
218
|
-
|
219
|
-
after(function() {
|
220
|
-
writeHtmlSpy.restore();
|
221
|
-
sendRequestSpy.restore();
|
222
|
-
triggerPixelSpy.restore();
|
223
|
-
});
|
224
|
-
|
225
|
-
const env = {
|
226
|
-
isMobileApp: () => false,
|
227
|
-
isAmp: () => true,
|
228
|
-
isSafeFrame: () => true
|
229
|
-
};
|
230
|
-
|
231
|
-
it('should render amp creative', function() {
|
232
|
-
const renderObject = newRenderingManager(mockWin, env);
|
233
|
-
|
234
|
-
let ucTagData = {
|
235
|
-
cacheHost: 'example.com',
|
236
|
-
cachePath: '/path',
|
237
|
-
uuid: '123',
|
238
|
-
size: '300x250',
|
239
|
-
hbPb: '10.00'
|
240
|
-
};
|
241
|
-
|
242
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
243
|
-
|
244
|
-
let response = {
|
245
|
-
width: 300,
|
246
|
-
height: 250,
|
247
|
-
crid: 123,
|
248
|
-
adm: 'ad-markup${AUCTION_PRICE}',
|
249
|
-
wurl: 'https://test.prebidcache.wurl'
|
250
|
-
};
|
251
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
252
|
-
expect(writeHtmlSpy.args[0][0]).to.equal('<!--Creative 123 served by Prebid.js Header Bidding-->ad-markup10.00');
|
253
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/path?uuid=123');
|
254
|
-
expect(triggerPixelSpy.args[0][0]).to.equal('https://test.prebidcache.wurl');
|
255
|
-
});
|
256
|
-
|
257
|
-
it('should replace AUCTION_PRICE with response.price over hbPb', function() {
|
258
|
-
const renderObject = newRenderingManager(mockWin, env);
|
259
|
-
|
260
|
-
let ucTagData = {
|
261
|
-
cacheHost: 'example.com',
|
262
|
-
cachePath: '/path',
|
263
|
-
uuid: '123',
|
264
|
-
size: '300x250',
|
265
|
-
hbPb: '10.00'
|
266
|
-
};
|
267
|
-
|
268
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
269
|
-
|
270
|
-
let response = {
|
271
|
-
width: 300,
|
272
|
-
height: 250,
|
273
|
-
crid: 123,
|
274
|
-
price: 12.50,
|
275
|
-
adm: 'ad-markup${AUCTION_PRICE}',
|
276
|
-
wurl: 'https://test.prebidcache.wurl'
|
277
|
-
};
|
278
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
279
|
-
expect(writeHtmlSpy.args[0][0]).to.equal('<!--Creative 123 served by Prebid.js Header Bidding-->ad-markup12.5');
|
280
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/path?uuid=123');
|
281
|
-
expect(triggerPixelSpy.args[0][0]).to.equal('https://test.prebidcache.wurl');
|
282
|
-
});
|
283
|
-
|
284
|
-
it('should replace AUCTION_PRICE with with empty value when neither price nor hbPb exist', function() {
|
285
|
-
const renderObject = newRenderingManager(mockWin, env);
|
286
|
-
|
287
|
-
let ucTagData = {
|
288
|
-
cacheHost: 'example.com',
|
289
|
-
cachePath: '/path',
|
290
|
-
uuid: '123',
|
291
|
-
size: '300x250'
|
292
|
-
};
|
293
|
-
|
294
|
-
renderObject.renderAd(mockWin.document, ucTagData);
|
295
|
-
|
296
|
-
let response = {
|
297
|
-
width: 300,
|
298
|
-
height: 250,
|
299
|
-
crid: 123,
|
300
|
-
adm: 'ad-markup${AUCTION_PRICE}',
|
301
|
-
wurl: 'https://test.prebidcache.wurl'
|
302
|
-
};
|
303
|
-
requests[0].respond(200, {}, JSON.stringify(response));
|
304
|
-
expect(writeHtmlSpy.args[0][0]).to.equal('<!--Creative 123 served by Prebid.js Header Bidding-->ad-markup');
|
305
|
-
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/path?uuid=123');
|
306
|
-
expect(triggerPixelSpy.args[0][0]).to.equal('https://test.prebidcache.wurl');
|
307
|
-
});
|
308
|
-
});
|
309
|
-
|
310
73
|
describe('cross domain creative', function() {
|
311
74
|
const ORIGIN = 'http://example.com';
|
312
75
|
let parseStub;
|
313
76
|
let iframeStub;
|
314
77
|
let triggerPixelSpy;
|
315
78
|
let mockWin;
|
316
|
-
let env;
|
317
|
-
let renderObject;
|
318
79
|
let ucTagData;
|
319
80
|
let mockIframe;
|
320
81
|
let eventSource;
|
@@ -329,22 +90,18 @@ describe('renderingManager', function() {
|
|
329
90
|
host: 'example.com'
|
330
91
|
});
|
331
92
|
mockWin = merge(mocks.createFakeWindow(ORIGIN), renderingMocks().getWindowObject());
|
332
|
-
env = {
|
333
|
-
isMobileApp: () => false,
|
334
|
-
isAmp: () => false,
|
335
|
-
canLocatePrebid: () => false
|
336
|
-
};
|
337
|
-
renderObject = newRenderingManager(mockWin, env);
|
338
93
|
ucTagData = {
|
339
94
|
adId: '123',
|
340
95
|
adServerDomain: 'mypub.com',
|
341
96
|
pubUrl: ORIGIN,
|
342
97
|
};
|
343
|
-
|
98
|
+
eventSource = null;
|
99
|
+
|
100
|
+
renderCrossDomain(mockWin, ucTagData.adId, ucTagData.adServerDomain, ucTagData.pubUrl);
|
344
101
|
|
345
102
|
});
|
346
103
|
|
347
|
-
afterEach(function() {
|
104
|
+
afterEach(function () {
|
348
105
|
parseStub.restore();
|
349
106
|
iframeStub.restore();
|
350
107
|
triggerPixelSpy.restore();
|
@@ -353,17 +110,17 @@ describe('renderingManager', function() {
|
|
353
110
|
function mockPrebidResponse(msg) {
|
354
111
|
mockWin.postMessage({
|
355
112
|
origin: ORIGIN,
|
356
|
-
message: JSON.stringify(Object.assign({message: 'Prebid Response'}, msg))
|
113
|
+
message: JSON.stringify(Object.assign({ message: 'Prebid Response' }, msg))
|
357
114
|
});
|
358
115
|
}
|
359
116
|
|
360
|
-
it(
|
117
|
+
it("should render cross domain creative", function () {
|
361
118
|
mockPrebidResponse({
|
362
|
-
ad:
|
119
|
+
ad: "ad",
|
363
120
|
adUrl: ORIGIN,
|
364
|
-
adId:
|
121
|
+
adId: "123",
|
365
122
|
width: 300,
|
366
|
-
height: 250
|
123
|
+
height: 250,
|
367
124
|
});
|
368
125
|
expect(mockIframe.contentDocument.write.args[0][0]).to.equal("ad");
|
369
126
|
});
|
@@ -390,13 +147,13 @@ describe('renderingManager', function() {
|
|
390
147
|
info: {
|
391
148
|
reason: 'preventWritingOnMainDocument'
|
392
149
|
}
|
393
|
-
})
|
150
|
+
});
|
394
151
|
});
|
395
152
|
|
396
153
|
it('on ads that have no markup or adUrl', () => {
|
397
154
|
mockPrebidResponse({
|
398
155
|
adId: '123',
|
399
|
-
})
|
156
|
+
});
|
400
157
|
expectEventMessage({
|
401
158
|
adId: '123',
|
402
159
|
event: RENDER_FAILED,
|
@@ -408,7 +165,7 @@ describe('renderingManager', function() {
|
|
408
165
|
|
409
166
|
it('on exceptions', () => {
|
410
167
|
iframeStub.callsFake(() => {
|
411
|
-
throw new Error()
|
168
|
+
throw new Error();
|
412
169
|
});
|
413
170
|
mockPrebidResponse({
|
414
171
|
adId: '123',
|
@@ -422,7 +179,7 @@ describe('renderingManager', function() {
|
|
422
179
|
reason: 'exception'
|
423
180
|
}
|
424
181
|
});
|
425
|
-
})
|
182
|
+
});
|
426
183
|
});
|
427
184
|
describe('should post AD_RENDER_SUCCEEDED', () => {
|
428
185
|
it('on ad with markup', () => {
|
@@ -452,18 +209,12 @@ describe('renderingManager', function() {
|
|
452
209
|
describe('legacy creative', function() {
|
453
210
|
it('should render legacy creative', function() {
|
454
211
|
const mockWin = merge(mocks.createFakeWindow('http://example.com'), renderingMocks().getWindowObject());
|
455
|
-
const env = {
|
456
|
-
isMobileApp: () => false,
|
457
|
-
isAmp: () => false,
|
458
|
-
canLocatePrebid: () => true
|
459
|
-
};
|
460
|
-
const renderObject = newRenderingManager(mockWin, env);
|
461
|
-
|
462
212
|
let ucTagData = {
|
463
213
|
adId: '123'
|
464
214
|
};
|
215
|
+
window.parent = mockWin;
|
465
216
|
|
466
|
-
|
217
|
+
renderLegacy(mockWin.document, ucTagData.adId);
|
467
218
|
expect(mockWin.parent.$$PREBID_GLOBAL$$.renderAd.callCount).to.equal(1);
|
468
219
|
});
|
469
220
|
});
|
package/webpack.conf.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
var creative = require('./package.json');
|
2
2
|
var StringReplacePlugin = require('string-replace-webpack-plugin');
|
3
3
|
var path = require('path');
|
4
|
+
const ShakePlugin = require('webpack-common-shake').Plugin;
|
4
5
|
|
5
6
|
module.exports = {
|
6
7
|
devtool: 'source-map',
|
@@ -42,5 +43,6 @@ module.exports = {
|
|
42
43
|
})
|
43
44
|
}
|
44
45
|
]
|
45
|
-
}
|
46
|
+
},
|
47
|
+
plugins: [new ShakePlugin()],
|
46
48
|
};
|