prebid-universal-creative 1.14.2 → 1.16.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 +31 -16
- package/README.md +21 -3
- package/dist/amp.js +3 -0
- package/dist/banner.js +3 -0
- package/dist/creative.js +4 -3
- package/dist/creative.max.js +546 -593
- 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 -45
- package/karma.conf.maker.js +4 -6
- 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 +91 -57
- package/src/nativeORTBTrackerManager.js +2 -2
- package/src/nativeRender.js +2 -2
- package/src/nativeRenderManager.js +46 -69
- package/src/postscribeRender.js +10 -0
- package/src/renderingManager.js +106 -358
- package/src/utils.js +1 -11
- 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 +316 -0
- package/test/spec/nativeAssetManager_spec.js +227 -79
- package/test/spec/nativeORTBTrackerManager_spec.js +3 -19
- package/test/spec/nativeRenderManager_spec.js +77 -55
- package/test/spec/nativeRender_spec.js +23 -0
- package/test/spec/renderingManager_spec.js +16 -265
- package/webpack.conf.js +3 -1
package/gulpfile.js
CHANGED
@@ -30,28 +30,48 @@ function clean() {
|
|
30
30
|
.pipe(gulpClean());
|
31
31
|
}
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
/**
|
34
|
+
* This generic function will compile the file specified as inputFile and will
|
35
|
+
* generate an output file in the build directory.
|
36
|
+
*/
|
37
|
+
function buildDev({ inputFile, outputFile }) {
|
38
|
+
var cloned = _.cloneDeep(webpackConfig);
|
39
|
+
cloned.output.filename = outputFile;
|
40
|
+
return gulp.src([inputFile])
|
41
|
+
.pipe(webpackStream(cloned))
|
36
42
|
.pipe(gulp.dest('build'));
|
37
43
|
}
|
38
44
|
|
39
|
-
function
|
40
|
-
|
41
|
-
|
45
|
+
function buildLegacyDev() {
|
46
|
+
return buildDev({ inputFile: 'src/legacy.js', outputFile: 'creative.js' });
|
47
|
+
}
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
function buildBannerDev() {
|
50
|
+
return buildDev({ inputFile: 'src/creative.js', outputFile: 'banner.js' });
|
51
|
+
}
|
52
|
+
|
53
|
+
function buildVideoDev() {
|
54
|
+
return buildDev({ inputFile: 'src/creative.js', outputFile: 'video.js' });
|
55
|
+
}
|
56
|
+
|
57
|
+
function buildAmpDev() {
|
58
|
+
return buildDev({ inputFile: 'src/ampOrMobile.js', outputFile: 'amp.js' });
|
59
|
+
}
|
60
|
+
|
61
|
+
function buildMobileDev() {
|
62
|
+
return buildDev({ inputFile: 'src/ampOrMobile.js', outputFile: 'mobile.js' });
|
63
|
+
}
|
64
|
+
|
65
|
+
function buildNativeDev() {
|
66
|
+
return buildDev({ inputFile: 'src/nativeTrackers.js', outputFile: 'native-trk.js' });
|
46
67
|
}
|
47
68
|
|
48
69
|
function buildNativeRenderDev() {
|
49
|
-
|
50
|
-
|
70
|
+
return buildDev({ inputFile: 'src/nativeRender.js', outputFile: 'native.js' });
|
71
|
+
}
|
51
72
|
|
52
|
-
|
53
|
-
|
54
|
-
.pipe(gulp.dest('build'));
|
73
|
+
function buildNativeRenderLegacyDev() {
|
74
|
+
return buildDev({ inputFile: 'src/legacyNativeRender.js', outputFile: 'native-render.js' });
|
55
75
|
}
|
56
76
|
|
57
77
|
function buildCookieSync() {
|
@@ -93,25 +113,19 @@ function buildCookieSyncWithConsent() {
|
|
93
113
|
}
|
94
114
|
|
95
115
|
function buildUidDev() {
|
96
|
-
|
97
|
-
delete cloned.devtool;
|
98
|
-
cloned.output.filename = 'uid.js';
|
99
|
-
|
100
|
-
return gulp.src(['src/ssp-userids/uid.js'])
|
101
|
-
.pipe(webpackStream(cloned))
|
102
|
-
.pipe(gulp.dest('build'));
|
116
|
+
return buildDev({ inputFile: 'src/ssp-userids/uid.js', outputFile: 'uid.js' });
|
103
117
|
}
|
104
118
|
|
105
|
-
function
|
119
|
+
function buildProdLegacy() {
|
106
120
|
let cloned = _.cloneDeep(webpackConfig);
|
107
121
|
delete cloned.devtool;
|
108
122
|
|
109
|
-
return gulp.src(['src/
|
123
|
+
return gulp.src(['src/legacy.js'])
|
110
124
|
.pipe(webpackStream(cloned))
|
111
125
|
.pipe(rename({ extname: '.max.js' }))
|
112
126
|
.pipe(gulp.dest('dist'))
|
113
127
|
.pipe(uglify())
|
114
|
-
.pipe(header(
|
128
|
+
.pipe(header('/* v<%= creative.version %>\n' + dateString + '\nDEPRECATED, please use creative based on hb_format targeting */\n', { creative: creative }))
|
115
129
|
.pipe(rename({
|
116
130
|
basename: 'creative',
|
117
131
|
extname: '.js'
|
@@ -119,28 +133,53 @@ function buildProd() {
|
|
119
133
|
.pipe(gulp.dest('dist'));
|
120
134
|
}
|
121
135
|
|
122
|
-
function
|
123
|
-
|
136
|
+
function includeStaticVastXmlFile() {
|
137
|
+
let target = gulp.src('static/prebid-mobile-rewarded-vast.xml');
|
138
|
+
return target.pipe(gulp.dest('dist'));
|
139
|
+
}
|
140
|
+
|
141
|
+
function buildProd({ inputFile, outputFile }) {
|
142
|
+
let cloned = _.cloneDeep(webpackConfig);
|
124
143
|
delete cloned.devtool;
|
125
|
-
cloned.output.filename = 'native-trk.js';
|
126
144
|
|
127
|
-
return gulp.src([
|
145
|
+
return gulp.src([inputFile])
|
128
146
|
.pipe(webpackStream(cloned))
|
147
|
+
.pipe(gulp.dest('dist'))
|
129
148
|
.pipe(uglify())
|
130
|
-
.pipe(header(
|
149
|
+
.pipe(header(banner, { creative: creative }))
|
150
|
+
.pipe(rename({
|
151
|
+
basename: outputFile.split('.')[0],
|
152
|
+
extname: `.${outputFile.split('.')[1]}`
|
153
|
+
}))
|
131
154
|
.pipe(gulp.dest('dist'));
|
132
155
|
}
|
133
156
|
|
157
|
+
function buildBanner() {
|
158
|
+
return buildProd({ inputFile: 'src/creative.js', outputFile: 'banner.js' });
|
159
|
+
}
|
160
|
+
|
161
|
+
function buildVideo() {
|
162
|
+
return buildProd({ inputFile: 'src/creative.js', outputFile: 'video.js' });
|
163
|
+
}
|
164
|
+
|
165
|
+
function buildAmp() {
|
166
|
+
return buildProd({ inputFile: 'src/ampOrMobile.js', outputFile: 'amp.js' });
|
167
|
+
}
|
168
|
+
|
169
|
+
function buildMobile() {
|
170
|
+
return buildProd({ inputFile: 'src/ampOrMobile.js', outputFile: 'mobile.js' });
|
171
|
+
}
|
172
|
+
|
173
|
+
function buildNative() {
|
174
|
+
return buildProd({ inputFile: 'src/nativeTrackers.js', outputFile: 'native-trk.js' });
|
175
|
+
}
|
176
|
+
|
134
177
|
function buildNativeRender() {
|
135
|
-
|
136
|
-
|
137
|
-
cloned.output.filename = 'native-render.js';
|
178
|
+
return buildProd({ inputFile: 'src/nativeRender.js', outputFile: 'native.js' });
|
179
|
+
}
|
138
180
|
|
139
|
-
|
140
|
-
|
141
|
-
.pipe(uglify())
|
142
|
-
.pipe(header('/* v<%= creative.version %>\n' + dateString + ' */\n', { creative: creative }))
|
143
|
-
.pipe(gulp.dest('dist'));
|
181
|
+
function buildLegacyNativeRender() {
|
182
|
+
return buildProd({ inputFile: 'src/legacyNativeRender.js', outputFile: 'native-render.js' });
|
144
183
|
}
|
145
184
|
|
146
185
|
function buildUid() {
|
@@ -195,7 +234,7 @@ function newKarmaCallback(done) {
|
|
195
234
|
process.exit(exitCode);
|
196
235
|
}
|
197
236
|
}
|
198
|
-
}
|
237
|
+
}
|
199
238
|
}
|
200
239
|
|
201
240
|
function setupE2E(done) {
|
@@ -205,7 +244,9 @@ function setupE2E(done) {
|
|
205
244
|
|
206
245
|
gulp.task('test', gulp.series(clean, test));
|
207
246
|
|
208
|
-
|
247
|
+
const buildDevFunctions = [buildLegacyDev, buildBannerDev, buildVideoDev, buildAmpDev, buildMobileDev, buildNativeRenderLegacyDev, buildNativeDev, buildNativeRenderDev, buildCookieSync, buildCookieSyncWithConsent, buildUidDev, includeStaticVastXmlFile];
|
248
|
+
|
249
|
+
gulp.task('e2e-test', gulp.series(clean, setupE2E, gulp.parallel(...buildDevFunctions, watch), test));
|
209
250
|
|
210
251
|
function watch(done) {
|
211
252
|
const mainWatcher = gulp.watch([
|
@@ -220,17 +261,15 @@ function watch(done) {
|
|
220
261
|
root: './'
|
221
262
|
});
|
222
263
|
|
223
|
-
mainWatcher.on('all', gulp.series(clean, gulp.parallel(
|
264
|
+
mainWatcher.on('all', gulp.series(clean, gulp.parallel(...buildDevFunctions), test));
|
224
265
|
done();
|
225
266
|
}
|
226
267
|
|
227
|
-
|
228
|
-
return opens(`${(argv.https) ? 'https' : 'http'}://localhost:${port}`);
|
229
|
-
}
|
268
|
+
gulp.task('serve', gulp.series(clean, gulp.parallel(...buildDevFunctions, watch, test)));
|
230
269
|
|
231
|
-
gulp.task('
|
270
|
+
gulp.task('build-dev', gulp.parallel(...buildDevFunctions));
|
232
271
|
|
233
|
-
gulp.task('build', gulp.parallel(
|
272
|
+
gulp.task('build', gulp.parallel(buildProdLegacy, buildLegacyNativeRender, buildBanner, buildVideo, buildCookieSync, buildCookieSyncWithConsent, buildNative, buildNativeRender, buildUid, buildAmp, buildMobile, includeStaticVastXmlFile));
|
234
273
|
|
235
274
|
gulp.task('test-coverage', (done) => {
|
236
275
|
new KarmaServer(karmaConfMaker(true, false, false), newKarmaCallback(done)).start();
|
package/karma.conf.maker.js
CHANGED
@@ -3,7 +3,7 @@ const webpackConf = require('./webpack.conf');
|
|
3
3
|
const karmaConstants = require('karma').constants;
|
4
4
|
const path = require('path');
|
5
5
|
|
6
|
-
function setBrowsers(karmaConf, browserstack
|
6
|
+
function setBrowsers(karmaConf, browserstack) {
|
7
7
|
if (browserstack) {
|
8
8
|
karmaConf.browserStack = {
|
9
9
|
username: process.env.BROWSERSTACK_USERNAME,
|
@@ -12,8 +12,6 @@ function setBrowsers(karmaConf, browserstack, watchMode) {
|
|
12
12
|
}
|
13
13
|
karmaConf.customLaunchers = require('./browsers.json')
|
14
14
|
karmaConf.browsers = Object.keys(karmaConf.customLaunchers);
|
15
|
-
} else if (watchMode) {
|
16
|
-
karmaConf.browsers = ['Chrome'];
|
17
15
|
}
|
18
16
|
}
|
19
17
|
|
@@ -29,7 +27,7 @@ function setReporters(karmaConf, codeCoverage, browserstack) {
|
|
29
27
|
suppressPassed: true
|
30
28
|
};
|
31
29
|
}
|
32
|
-
|
30
|
+
|
33
31
|
if (codeCoverage) {
|
34
32
|
karmaConf.reporters.push('coverage-istanbul');
|
35
33
|
karmaConf.coverageIstanbulReporter = {
|
@@ -41,7 +39,7 @@ function setReporters(karmaConf, codeCoverage, browserstack) {
|
|
41
39
|
urlFriendlyName: true, // simply replaces spaces with _ for files/dirs
|
42
40
|
}
|
43
41
|
}
|
44
|
-
}
|
42
|
+
}
|
45
43
|
}
|
46
44
|
}
|
47
45
|
|
@@ -149,6 +147,6 @@ module.exports = function(codeCoverage, browserstack, watchMode) {
|
|
149
147
|
captureTimeout: 4 * 60 * 1000, // default 60000
|
150
148
|
}
|
151
149
|
setReporters(config, codeCoverage, browserstack);
|
152
|
-
setBrowsers(config, browserstack
|
150
|
+
setBrowsers(config, browserstack);
|
153
151
|
return config;
|
154
152
|
}
|
package/package.json
CHANGED
@@ -1,84 +1,82 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"Prebid.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
"
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
"postscribe": "^2.0.8"
|
83
|
-
}
|
2
|
+
"name": "prebid-universal-creative",
|
3
|
+
"version": "1.16.0",
|
4
|
+
"description": "Universal creative for Prebid apps",
|
5
|
+
"main": "dist/creative.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "gulp test",
|
8
|
+
"prepublish": "gulp build"
|
9
|
+
},
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "git+https://github.com/prebid/prebid-universal-creative.git"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"Prebid.js"
|
16
|
+
],
|
17
|
+
"globalVarName": "pbjs",
|
18
|
+
"author": "Prebid.org Contributors",
|
19
|
+
"license": "Apache-2.0",
|
20
|
+
"bugs": {
|
21
|
+
"url": "https://github.com/prebid/prebid-universal-creative/issues"
|
22
|
+
},
|
23
|
+
"homepage": "https://github.com/prebid/prebid-universal-creative#readme",
|
24
|
+
"devDependencies": {
|
25
|
+
"@babel/core": "^7.2.2",
|
26
|
+
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
|
27
|
+
"@babel/preset-env": "^7.2.3",
|
28
|
+
"@babel/register": "^7.6.2",
|
29
|
+
"@wdio/browserstack-service": "^7.25.4",
|
30
|
+
"@wdio/cli": "^7.25.4",
|
31
|
+
"@wdio/concise-reporter": "^7.25.4",
|
32
|
+
"@wdio/local-runner": "^7.25.4",
|
33
|
+
"@wdio/mocha-framework": "^7.25.4",
|
34
|
+
"@wdio/spec-reporter": "^7.25.4",
|
35
|
+
"@wdio/sync": "^7.25.4",
|
36
|
+
"babel-loader": "^8.0.5",
|
37
|
+
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
|
38
|
+
"babel-plugin-transform-es3-property-literals": "^6.22.0",
|
39
|
+
"chai": "^4.1.2",
|
40
|
+
"core-js": "^3.13.0",
|
41
|
+
"core-js-pure": "^3.13.0",
|
42
|
+
"del": "^5.0.0",
|
43
|
+
"execa": "^1.0.0",
|
44
|
+
"gulp": "^4.0.2",
|
45
|
+
"gulp-clean": "^0.4.0",
|
46
|
+
"gulp-connect": "^5.7.0",
|
47
|
+
"gulp-eslint": "^4.0.2",
|
48
|
+
"gulp-header": "^2.0.1",
|
49
|
+
"gulp-inject": "^5.0.2",
|
50
|
+
"gulp-rename": "^1.2.2",
|
51
|
+
"gulp-replace": "^0.6.1",
|
52
|
+
"gulp-uglify": "^3.0.0",
|
53
|
+
"istanbul": "^0.4.5",
|
54
|
+
"istanbul-instrumenter-loader": "^3.0.0",
|
55
|
+
"karma": "^6.4.0",
|
56
|
+
"karma-browserstack-launcher": "^1.3.0",
|
57
|
+
"karma-chai": "^0.1.0",
|
58
|
+
"karma-chrome-launcher": "^2.2.0",
|
59
|
+
"karma-coverage": "^1.1.2",
|
60
|
+
"karma-coverage-istanbul-reporter": "^1.4.3",
|
61
|
+
"karma-mocha": "^2.0.1",
|
62
|
+
"karma-mocha-reporter": "^2.2.5",
|
63
|
+
"karma-sinon": "^1.0.5",
|
64
|
+
"karma-sourcemap-loader": "^0.3.7",
|
65
|
+
"karma-spec-reporter": "^0.0.31",
|
66
|
+
"karma-webpack": "^3.0.5",
|
67
|
+
"lodash": "^4.17.14",
|
68
|
+
"mocha": "^10.2.0",
|
69
|
+
"opn": "^6.0.0",
|
70
|
+
"sinon": "^6.3.4",
|
71
|
+
"string-replace-webpack-plugin": "^0.1.3",
|
72
|
+
"webdriverio": "^7.25.2",
|
73
|
+
"webpack": "^3.12.0",
|
74
|
+
"webpack-stream": "^4.0.0",
|
75
|
+
"yargs": "^11.0.0",
|
76
|
+
"webpack-common-shake": "^1.0.0"
|
77
|
+
},
|
78
|
+
"dependencies": {
|
79
|
+
"babel-plugin-transform-object-assign": "^6.22.0",
|
80
|
+
"postscribe": "^2.0.8"
|
81
|
+
}
|
84
82
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* creative.js
|
3
|
+
*
|
4
|
+
* This file is inserted into the prebid creative as a placeholder for the winning prebid creative. It should support the following format:
|
5
|
+
* - AMP creatives
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { renderAmpOrMobileAd } from './mobileAndAmpRender';
|
9
|
+
|
10
|
+
window.ucTag = (window.ucTag || {});
|
11
|
+
|
12
|
+
window.ucTag.renderAd = (doc, dataObject) => {
|
13
|
+
renderAmpOrMobileAd(dataObject);
|
14
|
+
}
|
package/src/creative.js
CHANGED
@@ -4,18 +4,11 @@
|
|
4
4
|
* This file is inserted into the prebid creative as a placeholder for the winning prebid creative. It should support the following formats:
|
5
5
|
* - Banner
|
6
6
|
* - Outstream Video
|
7
|
-
* - Mobile
|
8
|
-
* - AMP creatives
|
9
7
|
* - All safeFrame creatives
|
10
8
|
*/
|
11
9
|
|
12
|
-
import {
|
13
|
-
import { newEnvironment } from './environment';
|
10
|
+
import { renderBannerOrDisplayAd } from './renderingManager';
|
14
11
|
|
15
12
|
window.ucTag = (window.ucTag || {});
|
16
13
|
|
17
|
-
|
18
|
-
const renderCreative = newRenderingManager(window, environment);
|
19
|
-
|
20
|
-
|
21
|
-
window.ucTag.renderAd = renderCreative.renderAd;
|
14
|
+
window.ucTag.renderAd = renderBannerOrDisplayAd;
|
package/src/environment.js
CHANGED
@@ -10,88 +10,75 @@
|
|
10
10
|
* Mobile App: function to detect mobile app environment
|
11
11
|
*/
|
12
12
|
|
13
|
+
/**
|
14
|
+
* @param {String} uuid key value from auction, contains the cache id of the winning bid stored in prebid cache
|
15
|
+
* @returns true if there is an AMP context object
|
16
|
+
*/
|
17
|
+
export function isAmp(uuid, win) {
|
18
|
+
// TODO Use amp context once it is available in cross domain
|
19
|
+
// https://github.com/ampproject/amphtml/issues/6829
|
20
|
+
return typeof uuid === 'string' && uuid !== "" && isCrossDomain(win);
|
21
|
+
}
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
// TODO Use amp context once it is available in cross domain
|
21
|
-
// https://github.com/ampproject/amphtml/issues/6829
|
22
|
-
return typeof uuid === 'string' && uuid !== "" && isCrossDomain();
|
23
|
-
}
|
24
|
-
|
25
|
-
/**
|
26
|
-
* @returns true if the environment is a SafeFrame.
|
27
|
-
*/
|
28
|
-
function isSafeFrame() {
|
29
|
-
return !!(win.$sf && win.$sf.ext);
|
30
|
-
}
|
23
|
+
/**
|
24
|
+
* @returns true if the environment is a SafeFrame.
|
25
|
+
*/
|
26
|
+
export function isSafeFrame(win) {
|
27
|
+
return !!(win.$sf && win.$sf.ext);
|
28
|
+
}
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
/**
|
31
|
+
* Return true if we are in an iframe and can't access the top window.
|
32
|
+
* @returns true if the environment is a Cross Domain
|
33
|
+
*/
|
34
|
+
export function isCrossDomain(win) {
|
35
|
+
return win.top !== win && !canInspectWindow(win);
|
36
|
+
}
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
38
|
+
/**
|
39
|
+
* Returns true if win's properties can be accessed and win is defined.
|
40
|
+
* This functioned is used to determine if a window is cross-domained
|
41
|
+
* from the perspective of the current window.
|
42
|
+
* @param {!Window} win
|
43
|
+
* @return {boolean}
|
44
|
+
*/
|
45
|
+
export function canInspectWindow(win) {
|
46
|
+
try {
|
47
|
+
// force an exception in x-domain environments. #1509
|
48
|
+
win.top.location.toString();
|
49
|
+
return true;
|
50
|
+
} catch (e) {
|
51
|
+
return false;
|
55
52
|
}
|
53
|
+
}
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
while (!result) {
|
67
|
-
try {
|
68
|
-
if (currentWindow.$$PREBID_GLOBAL$$) {
|
69
|
-
result = true;
|
70
|
-
break;
|
71
|
-
}
|
72
|
-
} catch (e) { }
|
73
|
-
if (currentWindow === window.top) break;
|
74
|
-
|
75
|
-
currentWindow = currentWindow.parent;
|
76
|
-
}
|
77
|
-
return result;
|
78
|
-
}
|
55
|
+
/**
|
56
|
+
* Returns true if we can find the prebid global object (eg pbjs) as we
|
57
|
+
* climb the accessible windows. Return false if it's not found.
|
58
|
+
* @returns {boolean}
|
59
|
+
*/
|
60
|
+
export function canLocatePrebid(win) {
|
61
|
+
let result = false;
|
62
|
+
let currentWindow = win;
|
79
63
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
64
|
+
while (!result) {
|
65
|
+
try {
|
66
|
+
if (currentWindow.$$PREBID_GLOBAL$$) {
|
67
|
+
result = true;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
} catch (e) { }
|
71
|
+
if (currentWindow === window.top) break;
|
87
72
|
|
88
|
-
|
89
|
-
isMobileApp,
|
90
|
-
isCrossDomain,
|
91
|
-
isSafeFrame,
|
92
|
-
isAmp,
|
93
|
-
canLocatePrebid
|
73
|
+
currentWindow = currentWindow.parent;
|
94
74
|
}
|
75
|
+
return result;
|
95
76
|
}
|
96
77
|
|
97
|
-
|
78
|
+
/**
|
79
|
+
* @param {String} env key value from auction, indicates the environment where tag is served
|
80
|
+
* @returns true if env exists and is equal to the string 'mobile-app'
|
81
|
+
*/
|
82
|
+
export function isMobileApp(env) {
|
83
|
+
return env && env === 'mobile-app';
|
84
|
+
}
|
package/src/legacy.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* legacy.js
|
3
|
+
* This is deprecated code, publishers should not use one .js creative to handle all different types of creative.
|
4
|
+
* To reduce bytes transfered for each ad, publishers should use specific .js based on hb_format targeting key-value.
|
5
|
+
*
|
6
|
+
* This file is inserted into the prebid creative as a placeholder for the winning prebid creative. It should support the following formats:
|
7
|
+
* - Banner
|
8
|
+
* - AMP
|
9
|
+
* - Mobile
|
10
|
+
* - Outstream Video
|
11
|
+
* - All safeFrame creatives
|
12
|
+
*/
|
13
|
+
|
14
|
+
import { transformAuctionTargetingData } from './utils';
|
15
|
+
import { renderBannerOrDisplayAd } from './renderingManager';
|
16
|
+
import { renderAmpOrMobileAd } from './mobileAndAmpRender';
|
17
|
+
import { isMobileApp, isAmp } from './environment';
|
18
|
+
|
19
|
+
window.ucTag = (window.ucTag || {});
|
20
|
+
|
21
|
+
window.ucTag.renderAd = (doc, dataObject) => {
|
22
|
+
const targetingData = transformAuctionTargetingData(dataObject);
|
23
|
+
|
24
|
+
if (isMobileApp(targetingData.env) || isAmp(targetingData.uuid, window)) {
|
25
|
+
renderAmpOrMobileAd(dataObject);
|
26
|
+
} else {
|
27
|
+
renderBannerOrDisplayAd(doc, dataObject);
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { newNativeRenderManager } from './nativeRenderManager';
|
2
|
+
|
3
|
+
window.pbNativeTag = (window.pbNativeTag || {});
|
4
|
+
window.nativeRenderManager = newNativeRenderManager(window);
|
5
|
+
|
6
|
+
window.pbNativeTag.renderNativeAd = (args) => nativeRenderManager.renderNativeAd.call(null, document, args);
|