Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo detection changes IDNT-589 #462

Open
wants to merge 29 commits into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5a2f0ec
GPP config set to prebid
pm-nitin-shirsat Apr 4, 2023
af4a99b
Set GPP related config to prebid via OW
pm-nitin-shirsat Apr 5, 2023
97438ea
Add code to set gpp config to IDHUB
pm-nitin-shirsat Apr 7, 2023
55ebda4
Setting this config to PBJS_NAMESPACE as prebid needs to read consent…
pm-nitin-shirsat Apr 7, 2023
be872ac
Add gpp config to OW namespace in case of IH profiles
pm-nitin-shirsat Apr 11, 2023
0fa61c1
Merge pull request #440 from PubMatic/nightly
pm-nitin-shirsat Apr 19, 2023
13039de
Call added to geo detection module
pm-priyanka-deshmane May 4, 2023
7cbdc83
Merge branch 'nightly' into RIC
pm-priyanka-deshmane May 8, 2023
3cb552b
Merge branch 'RIC' into UOE-9002
pm-priyanka-deshmane May 8, 2023
0a2e2db
Merge branch 'test_coverage_7_39' into RIC
pm-priyanka-deshmane May 8, 2023
5cf38e1
Merge branch 'gpp-phase-1' into RIC
pm-priyanka-deshmane May 8, 2023
ef8782e
UOE-9150
pm-priyanka-deshmane May 8, 2023
3cd6c81
Fixed test case
pm-priyanka-deshmane May 8, 2023
da89e6f
Reading & writing to local storage
kapil-tuptewar May 10, 2023
5d16aa8
UOE-9161
pm-priyanka-deshmane May 11, 2023
f2e4039
Merge branch 'RIC' into sa_changes
kapil-tuptewar May 11, 2023
05b13e7
Merge branch 'UOE-9129-RIC' into GeoDetection
pm-priyanka-deshmane May 16, 2023
812cf4a
Commented gdpr.js as it is not in use
kapil-tuptewar May 24, 2023
c97f432
Removed test cases related to GDPR file
kapil-tuptewar May 24, 2023
ad36455
Additional changes to execute after location is fetched
pm-priyanka-deshmane May 24, 2023
ce3f066
Commiting original conf.js file
pm-priyanka-deshmane May 24, 2023
4b2610f
Merge pull request #458 from PubMatic/UOE-8815
pm-nitin-shirsat May 29, 2023
7a03bc5
Merge pull request #459 from PubMatic/nightly_30May
pm-nitin-shirsat May 29, 2023
97362dd
Remove GPP changes from sa_changes branch
pm-nitin-shirsat May 29, 2023
f98ca2b
Merge pull request #460 from PubMatic/sa_changes
pm-nitin-shirsat May 29, 2023
137a0e1
REmove GPP changes
pm-nitin-shirsat May 29, 2023
feb4aba
Merge pull request #461 from PubMatic/nightly_1_june
pm-azhar-mulla May 30, 2023
f550ac0
Merge branch 'nightly' into GeoDetection
pm-priyanka-deshmane May 31, 2023
6105a9f
Local storage changes and expiry changes
pm-priyanka-deshmane Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ if (task == CREATIVE_TASK) {

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

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

if (argv.mode == "test-build") {
if(shell.exec("gulp testall" + " --mode=" + argv.mode + " --prebidpath=" + prebidRepoPath).code !== 0) {
Expand All @@ -112,6 +104,11 @@ if (task == CREATIVE_TASK) {
shell.echo('Error: wrapper build task failed');
shell.exit(1);
}

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

console.timeEnd("--------- STARTED");
56 changes: 39 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,37 +395,59 @@ gulp.task('devbundle', gulp.series('devpack', function () {
var concat = require('gulp-concat');
//var prebidFileName = isIdentityOnly ? '/build/dev/prebidIdhub.js' : '/build/dev/prebid.js';
var prebidFileName = '/build/dev/prebid.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js'], { allowEmpty: true })
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js', footerFileName], { allowEmpty: true })
.pipe(concat('owt.js'))
.pipe(gulp.dest('build'));
}));


gulp.task('bundle-prod', gulp.series('webpack', function () {
console.log("Executing bundling");
var concat = require('gulp-concat');
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
var prebidFileName = '/build/dist/prebid.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js'], { allowEmpty: true })
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js', footerFileName], { allowEmpty: true })
.pipe(concat('owt.min.js'))
.pipe(gulp.dest('build'));
}));

gulp.task('update-namespace', function(){
console.log("In update-namespace isIdentityOnly = " + isIdentityOnly);
function addPattern(patterns, match, replacement) {
if (replacement) {
patterns.push({
match: match,
replacement: replacement
});
}
}

function getPatternsToReplace() {
const { COMMON, CONFIG } = require('./src_new/constants.js');
var patterns = [];
if (isIdentityOnly) {
addPattern(patterns, /ihowpbjs|owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.IH_NAMESPACE, COMMON.IH_NAMESPACE));
addPattern(patterns, /IHPWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.IH_OW_NAMESPACE, null));
} else {
// 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,
addPattern(patterns, /owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.PREBID_NAMESPACE, null));
addPattern(patterns, /PWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.OPENWRAP_NAMESPACE, null));
}
return patterns;
}

gulp.task('update-namespace', async function () {
console.log("Executing update-namespace - START => ");
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
var prebidFileName = '/build/dist/prebid.js';
return gulp.src(prebidRepoPath + prebidFileName)
.pipe(replace({
patterns: [
{
match: /owpbjs/g,
replacement: 'ihowpbjs'
}
]
}))
.pipe(gulp.dest(prebidRepoPath+'/build/dist/'));
var patternsToReplace = getPatternsToReplace();
console.log("Patterns to replace => ", patternsToReplace);
if (patternsToReplace.length > 0) {
return gulp.src('build/*.js')
.pipe(replace({
patterns: patternsToReplace
}))
.pipe(gulp.dest('build/'));
} else {
console.log("default namespaces(owpbjs and PWT) are using.");
}
});

gulp.task('build-gpt-prod');
Expand Down
52 changes: 44 additions & 8 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ var BID = require("../bid.js");
var util = require("../util.js");
var bidManager = require("../bidManager.js");
var CONF = require("../conf.js");

var parentAdapterID = CONSTANTS.COMMON.PARENT_ADAPTER_PREBID;

var pbNameSpace = /*CONFIG.isIdentityOnly() ? CONSTANTS.COMMON.IH_NAMESPACE : */ CONSTANTS.COMMON.PREBID_NAMESPACE;
var geoDetectionURL = 'https://www.ebay.com/defaultLocation.json'; //TODO update this
var HOSTNAME = window.location.host;
var PREFIX = 'UINFO';

/* start-test-block */
exports.parentAdapterID = parentAdapterID;
Expand Down Expand Up @@ -820,7 +822,18 @@ function assignUserSyncConfig(prebidConfig){
exports.assignUserSyncConfig = assignUserSyncConfig;

function assignGdprConfigIfRequired(prebidConfig){
if (CONFIG.getGdpr()) {
var isInGDPRRegion = CONFIG.isInGDPRRegion();
util.log("User isInGDPRRegion: " + isInGDPRRegion + ", GDPR enabled: " + CONFIG.getGdpr());

/*
If GEO detection is NOT enabled AND GDPR is enabled
OR
If GEO detection is enabled AND GDPR is enabled AND location is EU(or error)
THEN ENFORCE GDPR
*/
if(CONFIG.getGdpr() && (!CONFIG.isGeoDetectionEnabled() ||
(CONFIG.isGeoDetectionEnabled() && isInGDPRRegion)
)) {
if(!prebidConfig["consentManagement"]){
prebidConfig["consentManagement"] = {};
}
Expand All @@ -831,6 +844,8 @@ function assignGdprConfigIfRequired(prebidConfig){
defaultGdprScope: true
};
}
isInGDPRRegion && !CONFIG.getGdpr() &&
util.logWarning("User is from EU region but GDPR is not enabled");
}

exports.assignGdprConfigIfRequired = assignGdprConfigIfRequired;
Expand Down Expand Up @@ -1338,19 +1353,40 @@ function pbjsBidsBackHandler(bidResponses, activeSlots) {

exports.pbjsBidsBackHandler = pbjsBidsBackHandler;

function initConfig() {
window[pbNameSpace].logging = util.isDebugLogEnabled();
refThis.realignPubmaticAdapters();
refThis.setPrebidConfig();
refThis.configureBidderAliasesIfAvailable();
refThis.enablePrebidPubMaticAnalyticIfRequired();
refThis.setPbjsBidderSettingsIfRequired();
}

// this function will be called by controllers,
// will take care of setting the config as it is configured thru UI
function initPbjsConfig(){
var LOCATION_INFO_VALIDITY = 2 * 24 * 60 * 60 * 1000;
if(! window[pbNameSpace]){ // todo: move this code owt.js
util.logError("PreBid js is not loaded");
return;
}
window[pbNameSpace].logging = util.isDebugLogEnabled();
refThis.realignPubmaticAdapters();
refThis.setPrebidConfig();
refThis.configureBidderAliasesIfAvailable();
refThis.enablePrebidPubMaticAnalyticIfRequired();
refThis.setPbjsBidderSettingsIfRequired();

var info = window[pbNameSpace].getDataFromLocalStorage(PREFIX + HOSTNAME, LOCATION_INFO_VALIDITY);
if(info) { // Got valid data
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.LOCATION] = info;
initConfig();
} else {
window[pbNameSpace].detectLocation(geoDetectionURL + "?pubid=" + CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.PUBLISHER_ID],
function(loc) {
window[pbNameSpace].setAndStringifyToLocalStorage(PREFIX + HOSTNAME, loc);
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.LOCATION] = loc;
CONFIG.isGeoDetectionEnabled() && initConfig(); // to execute this synchronously
});

if(!CONFIG.isGeoDetectionEnabled()) {
initConfig(); // to execute this without waiting for geo
}
}
}
exports.initPbjsConfig = initPbjsConfig;

Expand Down
2 changes: 1 addition & 1 deletion src_new/bidManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ exports.displayCreative = function(theDocument, bidID){ // TDD, i/o : done
if (frequencyDepth !== null && frequencyDepth.slotLevelFrquencyDepth) {
frequencyDepth.slotLevelFrquencyDepth[frequencyDepth.codeAdUnitMap[divID]].impressionServed = frequencyDepth.slotLevelFrquencyDepth[frequencyDepth.codeAdUnitMap[divID]].impressionServed + 1;
frequencyDepth.impressionServed = frequencyDepth.impressionServed + 1;
localStorage.setItem(PREFIX + window.location.hostname, JSON.stringify(frequencyDepth));
}
localStorage.setItem(PREFIX + window.location.hostname, JSON.stringify(frequencyDepth));
}
};
// endRemoveIf(removeLegacyAnalyticsRelatedCode)
Expand Down
4 changes: 3 additions & 1 deletion src_new/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ exports.pwt = {
owv:"v21.4.0",
abTestEnabled:"0",
pubAnalyticsAdapter: "0",
reduceCodeSize:1
reduceCodeSize:1,
pbGlobalVarNamespace: "custPbNamespace",
owGlobalVarNamespace: "NIT"
};

// singleImpression is used to enable feature of sending single impression for multiple size ad slot earlier there were multiple impression for multiple sizes
Expand Down
11 changes: 10 additions & 1 deletion src_new/config.idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ exports.getIHAnalyticsAdapterExpiry = function() {
return parseInt(config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.IH_ANALYTICS_ADAPTER_EXPIRY]) || CONSTANTS.COMMON.IH_ANALYTICS_ADAPTER_DEFAULT_EXPIRY;
};

exports.PBJS_NAMESPACE = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PBJS_NAMESPACE] || "pbjs";
exports.PBJS_NAMESPACE = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PBJS_NAMESPACE] || "pbjs";

exports.isInGDPRRegion = function() {
var loc = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.LOCATION];
return loc && loc.apply_gdpr;
}

exports.isGeoDetectionEnabled = function() {
return config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.GEO_DETECTION_ENABLED];
}
20 changes: 19 additions & 1 deletion src_new/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ exports.getAwc = function () {
return awc === "1";
};

exports.getOverrideNamespace = function(configKey, defaultName, returnValueInCaseMissingNamespace) {
var pbNamespace = config[CONSTANTS.CONFIG.COMMON][configKey];
if (pbNamespace) {
return pbNamespace === defaultName ? returnValueInCaseMissingNamespace : pbNamespace;
} else {
return returnValueInCaseMissingNamespace;
}
}

/* start-test-block */
exports.addPrebidAdapter = addPrebidAdapter;
/* end-test-block */
Expand Down Expand Up @@ -447,4 +456,13 @@ exports.createMacros = function() {

exports.getMarketplaceBidders = function(){
return config.pwt.marketplaceBidders ? config.pwt.marketplaceBidders.split(',') : false;
}
}

exports.isInGDPRRegion = function() {
var loc = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.LOCATION];
return loc && loc.apply_gdpr;
}

exports.isGeoDetectionEnabled = function() {
return config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.GEO_DETECTION_ENABLED];
}
8 changes: 7 additions & 1 deletion src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ exports.COMMON = {
"BID_ID": "owbidid",
"AD_SERVER_CURRENCY": "adServerCurrency",
"SINGLE_IMPRESSION": "singleImpression",
"OPENWRAP_NAMESPACE": "PWT",
"IH_OW_NAMESPACE": "IHPWT",
"PREBID_NAMESPACE": "owpbjs",
"IH_NAMESPACE": "ihowpbjs",
"ENABLE_USER_ID": "identityEnabled",
Expand Down Expand Up @@ -51,7 +53,9 @@ exports.COMMON = {
"IH_ANALYTICS_ADAPTER_EXPIRY": "ihAnalyticsAdapterExpiry",
"IH_ANALYTICS_ADAPTER_DEFAULT_EXPIRY": 7,
"EXTERNAL_FLOOR_WO_CONFIG": "External Floor w/o Config",
"HARD_FLOOR": "hard"
"HARD_FLOOR": "hard",
"LOCATION": "location",
"GEO_DETECTION_ENABLED": "gdEnabled"
};

exports.CONFIG = {
Expand Down Expand Up @@ -109,6 +113,8 @@ exports.CONFIG = {
"AB_TEST_ENABLED": "abTestEnabled",
"TIMEOUT_ADJUSTMENT": 50,
"SSO_ENABLED": "ssoEnabled",
"PB_GLOBAL_VAR_NAMESPACE": "pbGlobalVarNamespace",
"OW_GLOBAL_VAR_NAMESPACE": "owGlobalVarNamespace",
"FLOOR_SOURCE": "floorSource"
};

Expand Down
18 changes: 16 additions & 2 deletions src_new/controllers/idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ refThis.setConfig = function(){
}
};

if (CONFIG.getGdpr()) {
var isInGDPRRegion = CONFIG.isInGDPRRegion();
util.log("User isInGDPRRegion: " + isInGDPRRegion + ", GDPR enabled: " + CONFIG.getGdpr());

/*
If GEO detection is NOT enabled AND GDPR is enabled
OR
If GEO detection is enabled AND GDPR is enabled AND location is EU(or error)
THEN ENFORCE GDPR
*/
if(CONFIG.getGdpr() && (!CONFIG.isGeoDetectionEnabled() ||
(CONFIG.isGeoDetectionEnabled() && isInGDPRRegion)
)) {
if(!prebidConfig["consentManagement"]){
prebidConfig["consentManagement"] = {};
}
Expand All @@ -48,7 +59,9 @@ refThis.setConfig = function(){
defaultGdprScope: true
};
}

isInGDPRRegion && !CONFIG.getGdpr() &&
util.logWarning("User is from EU region but GDPR is not enabled");

if (CONFIG.getCCPA()) {
if(!prebidConfig["consentManagement"]){
prebidConfig["consentManagement"] = {};
Expand All @@ -58,6 +71,7 @@ refThis.setConfig = function(){
timeout: CONFIG.getCCPATimeout(),
};
}

window.IHPWT.ssoEnabled = CONFIG.isSSOEnabled() || false;
if(CONFIG.isUserIdModuleEnabled()){
prebidConfig["userSync"]["userIds"] = util.getUserIdConfiguration();
Expand Down
Loading