Skip to content

Commit 5d07ac9

Browse files
Merge pull request #473 from PubMatic/UOE-8815
Uoe 8815: Custom Namespace
2 parents c8890db + e0b5bcf commit 5d07ac9

14 files changed

+434
-341
lines changed

build.sh

+4-10
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ if (task == CREATIVE_TASK) {
8383

8484
shell.cd("../OpenWrap/");
8585

86-
console.log("Executing update-namespace task if identityOnly = 1, => ", config.isIdentityOnly());
87-
88-
if(config.isIdentityOnly()) {
89-
console.log("Updating owpbjs namespace to use ihowpbjs for identity only profiles");
90-
if(shell.exec("time gulp update-namespace").code !== 0) {
91-
shell.echo('Error: Changing owpbjs namespace to use ihowpbjs failed');
92-
shell.exit(1);
93-
}
94-
}
95-
9686

9787
if (argv.mode == "test-build") {
9888
if(shell.exec("gulp testall" + " --mode=" + argv.mode + " --prebidpath=" + prebidRepoPath).code !== 0) {
@@ -115,6 +105,10 @@ if (task == CREATIVE_TASK) {
115105
shell.exit(1);
116106
}
117107

108+
if(shell.exec("time gulp update-namespace").code !== 0) {
109+
shell.echo('Error: Changing custom namespace failed');
110+
shell.exit(1);
111+
}
118112
}
119113

120114
console.timeEnd("--------- STARTED");

gulpfile.js

+40-16
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ gulp.task('devbundle', gulp.series('devpack', function () {
395395
var concat = require('gulp-concat');
396396
//var prebidFileName = isIdentityOnly ? '/build/dev/prebidIdhub.js' : '/build/dev/prebid.js';
397397
var prebidFileName = '/build/dev/prebid.js';
398-
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js'], { allowEmpty: true })
398+
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
399+
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js', footerFileName], { allowEmpty: true })
399400
.pipe(concat('owt.js'))
400401
.pipe(gulp.dest('build'));
401402
}));
@@ -405,26 +406,49 @@ gulp.task('bundle-prod', gulp.series('webpack', function () {
405406
var concat = require('gulp-concat');
406407
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
407408
var prebidFileName = '/build/dist/prebid.js';
408-
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js'], { allowEmpty: true })
409+
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
410+
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js', footerFileName], { allowEmpty: true })
409411
.pipe(concat('owt.min.js'))
410412
.pipe(gulp.dest('build'));
411413
}));
412414

413-
gulp.task('update-namespace', function(){
414-
console.log("In update-namespace isIdentityOnly = " + isIdentityOnly);
415+
416+
function addPattern(patterns, match, replacement) {
417+
if (replacement) {
418+
patterns.push({
419+
match: match,
420+
replacement: replacement
421+
});
422+
}
423+
}
424+
425+
function getPatternsToReplace() {
426+
const { COMMON, CONFIG } = require('./src_new/constants.js');
427+
var patterns = [];
428+
if (isIdentityOnly) {
429+
addPattern(patterns, /ihowpbjs|owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.IH_NAMESPACE, COMMON.IH_NAMESPACE));
430+
addPattern(patterns, /IHPWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.IH_OW_NAMESPACE, null));
431+
} else {
432+
// Passing null as we don't want to replace the used value(i.e. PWT) with default value(i.e. PWT) as both are same,
433+
addPattern(patterns, /owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.PREBID_NAMESPACE, null));
434+
addPattern(patterns, /PWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.OPENWRAP_NAMESPACE, null));
435+
}
436+
return patterns;
437+
}
438+
439+
gulp.task('update-namespace', async function () {
415440
console.log("Executing update-namespace - START => ");
416-
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
417-
var prebidFileName = '/build/dist/prebid.js';
418-
return gulp.src(prebidRepoPath + prebidFileName)
419-
.pipe(replace({
420-
patterns: [
421-
{
422-
match: /owpbjs/g,
423-
replacement: 'ihowpbjs'
424-
}
425-
]
426-
}))
427-
.pipe(gulp.dest(prebidRepoPath+'/build/dist/'));
441+
var patternsToReplace = getPatternsToReplace();
442+
console.log("Patterns to replace => ", patternsToReplace);
443+
if (patternsToReplace.length > 0) {
444+
return gulp.src('build/*.js')
445+
.pipe(replace({
446+
patterns: patternsToReplace
447+
}))
448+
.pipe(gulp.dest('build'));
449+
} else {
450+
console.log("default namespaces(owpbjs and PWT) are using.");
451+
}
428452
});
429453

430454
gulp.task('build-gpt-prod');

src_new/adapters/prebid.js

+2
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ function setPbjsBidderSettingsIfRequired(){
12871287
window[pbNameSpace].bidderSettings = {
12881288
'standard': {
12891289
'suppressEmptyKeys': true, // this boolean flag can be used to avoid sending those empty values to the ad server.
1290+
'storageAllowed': CONF.pwt.localStorageAccess
12901291
}
12911292
};
12921293

@@ -1413,6 +1414,7 @@ function fetchBids(activeSlots){
14131414
},
14141415
timeout: CONFIG.getTimeout() - CONSTANTS.CONFIG.TIMEOUT_ADJUSTMENT
14151416
});
1417+
util.getGeoInfo();
14161418
} else {
14171419
util.log("PreBid js requestBids function is not available");
14181420
return;

src_new/conf.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ exports.pwt = {
2424
owv:"v21.4.0",
2525
abTestEnabled:"0",
2626
pubAnalyticsAdapter: "0",
27-
reduceCodeSize:1
27+
reduceCodeSize:1,
28+
pbGlobalVarNamespace: "custPbNamespace",
29+
owGlobalVarNamespace: "NIT",
30+
localStorageAccess: true // Added new field for allow local storage feature
2831
};
2932

3033
// singleImpression is used to enable feature of sending single impression for multiple size ad slot earlier there were multiple impression for multiple sizes

src_new/config.js

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ exports.getAwc = function () {
144144
return awc === "1";
145145
};
146146

147+
exports.getOverrideNamespace = function(configKey, defaultName, returnValueInCaseMissingNamespace) {
148+
var pbNamespace = config[CONSTANTS.CONFIG.COMMON][configKey];
149+
if (pbNamespace) {
150+
return pbNamespace === defaultName ? returnValueInCaseMissingNamespace : pbNamespace;
151+
} else {
152+
return returnValueInCaseMissingNamespace;
153+
}
154+
}
155+
147156
/* start-test-block */
148157
exports.addPrebidAdapter = addPrebidAdapter;
149158
/* end-test-block */

src_new/constants.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ exports.COMMON = {
2424
"BID_ID": "owbidid",
2525
"AD_SERVER_CURRENCY": "adServerCurrency",
2626
"SINGLE_IMPRESSION": "singleImpression",
27+
"OPENWRAP_NAMESPACE": "PWT",
28+
"IH_OW_NAMESPACE": "IHPWT",
2729
"PREBID_NAMESPACE": "owpbjs",
2830
"IH_NAMESPACE": "ihowpbjs",
2931
"ENABLE_USER_ID": "identityEnabled",
@@ -109,7 +111,9 @@ exports.CONFIG = {
109111
"AB_TEST_ENABLED": "abTestEnabled",
110112
"TIMEOUT_ADJUSTMENT": 50,
111113
"SSO_ENABLED": "ssoEnabled",
112-
"FLOOR_SOURCE": "floorSource"
114+
"FLOOR_SOURCE": "floorSource",
115+
"PB_GLOBAL_VAR_NAMESPACE": "pbGlobalVarNamespace",
116+
"OW_GLOBAL_VAR_NAMESPACE": "owGlobalVarNamespace"
113117
};
114118

115119
exports.METADATA_MACROS = {

0 commit comments

Comments
 (0)