Skip to content

Commit feb4aba

Browse files
Merge pull request #461 from PubMatic/nightly_1_june
Nightly for 1st June 2023 release
2 parents ef7e064 + 137a0e1 commit feb4aba

21 files changed

+3281
-417
lines changed

Diff for: build.sh

+5-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +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-
if(config.isIdentityOnly()) {
88-
console.log("Updating owpbjs namespace to use ihowpbjs for identity only profiles");
89-
if(shell.exec("time gulp update-namespace").code !== 0) {
90-
shell.echo('Error: Changing owpbjs namespace to use ihowpbjs failed');
91-
shell.exit(1);
92-
}
93-
}
9486

9587
if (argv.mode == "test-build") {
9688
if(shell.exec("gulp testall" + " --mode=" + argv.mode + " --prebidpath=" + prebidRepoPath).code !== 0) {
@@ -112,6 +104,11 @@ if (task == CREATIVE_TASK) {
112104
shell.echo('Error: wrapper build task failed');
113105
shell.exit(1);
114106
}
107+
108+
if(shell.exec("time gulp update-namespace").code !== 0) {
109+
shell.echo('Error: Changing custom namespace failed');
110+
shell.exit(1);
111+
}
115112
}
116113

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

Diff for: gulpfile.js

+39-17
Original file line numberDiff line numberDiff line change
@@ -395,37 +395,59 @@ 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
}));
402403

403-
404404
gulp.task('bundle-prod', gulp.series('webpack', function () {
405405
console.log("Executing bundling");
406406
var concat = require('gulp-concat');
407407
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
408408
var prebidFileName = '/build/dist/prebid.js';
409-
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 })
410411
.pipe(concat('owt.min.js'))
411412
.pipe(gulp.dest('build'));
412413
}));
413414

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

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

Diff for: src_new/bidManager.js

+45-42
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ var refThis = this;
88
var storedObject;
99
var frequencyDepth;
1010
const PREFIX = 'PROFILE_AUCTION_INFO_';
11+
12+
const TRACKER_METHODS = {
13+
img: 1,
14+
js: 2,
15+
1: 'img',
16+
2: 'js'
17+
}
18+
19+
const TRACKER_EVENTS = {
20+
impression: 1,
21+
'viewable-mrc50': 2,
22+
'viewable-mrc100': 3,
23+
'viewable-video50': 4,
24+
}
25+
1126
function createBidEntry(divID){ // TDD, i/o : done
1227
/* istanbul ignore else */
1328
if(! util.isOwnProperty(window.PWT.bidMap, divID) ){
@@ -374,8 +389,8 @@ exports.displayCreative = function(theDocument, bidID){ // TDD, i/o : done
374389
if (frequencyDepth !== null && frequencyDepth.slotLevelFrquencyDepth) {
375390
frequencyDepth.slotLevelFrquencyDepth[frequencyDepth.codeAdUnitMap[divID]].impressionServed = frequencyDepth.slotLevelFrquencyDepth[frequencyDepth.codeAdUnitMap[divID]].impressionServed + 1;
376391
frequencyDepth.impressionServed = frequencyDepth.impressionServed + 1;
392+
localStorage.setItem(PREFIX + window.location.hostname, JSON.stringify(frequencyDepth));
377393
}
378-
localStorage.setItem(PREFIX + window.location.hostname, JSON.stringify(frequencyDepth));
379394
}
380395
};
381396
// endRemoveIf(removeLegacyAnalyticsRelatedCode)
@@ -409,13 +424,7 @@ exports.executeAnalyticsPixel = function(){ // TDD, i/o : done
409424
outputObj[CONSTANTS.CONFIG.PROFILE_VERSION_ID] = CONFIG.getProfileDisplayVersionID();
410425
outputObj['ih'] = CONFIG.isUserIdModuleEnabled() ? 1 : 0;
411426
outputObj["bm"] = refThis.getBrowser();
412-
outputObj["tgid"] = (function() {
413-
var testGroupId = parseInt(PWT.testGroupId || 0);
414-
if (testGroupId <= 15 && testGroupId >= 0) {
415-
return testGroupId;
416-
}
417-
return 0;
418-
})();
427+
outputObj["tgid"] = util.getTgid();
419428

420429
if(Object.keys(frequencyDepth).length) {
421430
outputObj["tpv"] = frequencyDepth.pageView;
@@ -521,24 +530,6 @@ exports.getAdUnitAdFormats = getAdUnitAdFormats;
521530
/* end-test-block */
522531
// endRemoveIf(removeLegacyAnalyticsRelatedCode)
523532

524-
// removeIf(removeLegacyAnalyticsRelatedCode)
525-
function getAdDomain(bidResponse) {
526-
if (bidResponse.meta && bidResponse.meta.advertiserDomains && bidResponse.meta.advertiserDomains.length > 0) {
527-
var adomain = bidResponse.meta.advertiserDomains[0];
528-
529-
if (adomain) {
530-
try {
531-
var hostname = new URL(adomain);
532-
return hostname.hostname.replace('www.', '');
533-
} catch (e) {
534-
util.log("Adomain URL (Not a proper URL):"+ adomain);
535-
return adomain.split('/')[0].replace('www.', '');
536-
}
537-
}
538-
}
539-
}
540-
// endRemoveIf(removeLegacyAnalyticsRelatedCode)
541-
542533
// Returns property from localstorages slotlevel object
543534
exports.getSlotLevelFrequencyDepth = function (frequencyDepth, prop, adUnit) {
544535
var freqencyValue;
@@ -692,7 +683,7 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
692683
"dc": theBid.getDealChannel(),
693684
"l1": theBid.getServerSideStatus() ? theBid.getServerSideResponseTime() : (endTime - startTime),
694685
"l2": 0,
695-
"adv": pbbid ? getAdDomain(pbbid) || undefined : undefined,
686+
"adv": pbbid ? util.getAdDomain(pbbid) || undefined : undefined,
696687
"ss": theBid.getServerSideStatus(),
697688
"t": theBid.getPostTimeoutStatus() === false ? 0 : 1,
698689
"wb": theBid.getWinningBidStatus() === true ? 1 : 0,
@@ -821,25 +812,37 @@ exports.fireTracker = function(bidDetails, action) {
821812
var trackers;
822813

823814
if (action === "click") {
824-
trackers = bidDetails["native"] && bidDetails["native"].clickTrackers;
815+
trackers = bidDetails["native"] && bidDetails["native"].ortb &&
816+
bidDetails["native"].ortb.link && bidDetails["native"].ortb.link.clickTrackers;
825817
} else if(action === "imptrackers") {
826-
trackers = bidDetails["native"] && bidDetails["native"].impressionTrackers;
827-
if (bidDetails['native'] && bidDetails['native'].javascriptTrackers) {
828-
var iframe = util.createInvisibleIframe();
829-
/* istanbul ignore else */
830-
if(!iframe){
831-
throw {message: 'Failed to create invisible frame for native javascript trackers'};
832-
}
833-
/* istanbul ignore else */
834-
if(!iframe.contentWindow){
835-
throw {message: 'Unable to access frame window for native javascript trackers'};
818+
const nativeResponse = bidDetails.native.ortb || bidDetails.native;
819+
820+
const impTrackers = (nativeResponse.eventtrackers || [])
821+
.filter(function(tracker) {
822+
tracker.event === TRACKER_EVENTS.impression
823+
});
824+
825+
const tally = {img: [], js: []};
826+
impTrackers.forEach(function(tracker) {
827+
if (TRACKER_METHODS.hasOwnProperty(tracker.method)) {
828+
tally[TRACKER_METHODS[tracker.method]].push(tracker.url);
836829
}
837-
window.document.body.appendChild(iframe);
838-
iframe.contentWindow.document.open();
839-
iframe.contentWindow.document.write(bidDetails['native'].javascriptTrackers);
840-
iframe.contentWindow.document.close();
830+
});
831+
832+
if (tally.img.length == 0 && nativeResponse.imptrackers) {
833+
tally.img = tally.img.concat(nativeResponse.imptrackers);
834+
}
835+
trackers = tally.img;
836+
837+
if (tally.js.length == 0 && nativeResponse.jstracker) {
838+
// jstracker is already HTML markup
839+
tally.js = tally.js.concat([nativeResponse.jstracker]);
840+
}
841+
if (tally.js.length) {
842+
util.insertHtmlIntoIframe(tally.js.join('\n'));
841843
}
842844
}
845+
843846
(trackers || []).forEach(function(url){refThis.setImageSrcToPixelURL(url,false);});
844847
};
845848
// endRemoveIf(removeNativeRelatedCode)

Diff for: src_new/conf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ 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"
2830
};
2931

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

Diff for: 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 */

Diff for: src_new/constants.js

+4
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,6 +111,8 @@ exports.CONFIG = {
109111
"AB_TEST_ENABLED": "abTestEnabled",
110112
"TIMEOUT_ADJUSTMENT": 50,
111113
"SSO_ENABLED": "ssoEnabled",
114+
"PB_GLOBAL_VAR_NAMESPACE": "pbGlobalVarNamespace",
115+
"OW_GLOBAL_VAR_NAMESPACE": "owGlobalVarNamespace",
112116
"FLOOR_SOURCE": "floorSource"
113117
};
114118

Diff for: src_new/controllers/idhub.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ refThis.setConfig = function(){
5858
timeout: CONFIG.getCCPATimeout(),
5959
};
6060
}
61+
6162
window.IHPWT.ssoEnabled = CONFIG.isSSOEnabled() || false;
6263
if(CONFIG.isUserIdModuleEnabled()){
6364
prebidConfig["userSync"]["userIds"] = util.getUserIdConfiguration();

0 commit comments

Comments
 (0)