From 4fb0c4ad2bcdef0e692c6342c65b4870cec1cc7d Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Wed, 3 Jun 2020 13:44:23 -0400 Subject: [PATCH 1/7] Fetch hub promo ab test before opening hub on install. Add hub promo variant utm param. Add hub promo variant conf prop. --- manifest.json | 4 ++- src/background.js | 68 ++++++++++++++++++++++++++++++----------- src/classes/ABTest.js | 2 ++ src/classes/ConfData.js | 1 + src/classes/Metrics.js | 26 +++++++++++++++- 5 files changed, 82 insertions(+), 19 deletions(-) diff --git a/manifest.json b/manifest.json index 271ef52db..88e2c710e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,7 @@ { "manifest_version": 2, + "debug": true, + "log": true, "author": "Ghostery", "name": "__MSG_name__", "short_name": "Ghostery", @@ -103,4 +105,4 @@ "cliqz/offers-templates/checkout.html", "cliqz/offers-templates/control-center.html" ] -} \ No newline at end of file +} diff --git a/src/background.js b/src/background.js index ae5b3a17b..3c7b43c7a 100644 --- a/src/background.js +++ b/src/background.js @@ -1107,6 +1107,25 @@ function getAntitrackingTestConfig() { }; } +/** + * Set option for Hub promo A/B/C test based + * on the results returned from the abtest endpoint. + * @memberOf Background + * + * @return {Object} Hub promotion configuration parameters + */ +function setupHubPromoABTest() { + if (abtest.hasTest('hub_plain')) { + conf.hub_promo_variant = 'plain'; + } else if (abtest.hasTest('hub_midnight')) { + conf.hub_promo_variant = 'midnight'; + } else { + conf.hub_promo_variant = 'upgrade'; + } + + console.error(`conf.hub_promo_version in setupHubPromoABTest: ${conf.hub_promo_variant}`); +} + /** * Adjust antitracking parameters based on the current state * of ABTest and availability of Human Web. @@ -1135,6 +1154,8 @@ function setupABTest() { // cliqz.disableModule('search'); // cliqz.disableModule('overlay'); // } + + setupHubPromoABTest(); } /** @@ -1546,12 +1567,6 @@ function initializeGhosteryModules() { setTimeout(() => { metrics.ping('install_complete'); }, 300000); - - // open the Ghostery Hub on install with justInstalled query parameter set to true - chrome.tabs.create({ - url: chrome.runtime.getURL('./app/templates/hub.html?justInstalled=true'), - active: true - }); } else { // Record install if the user previously closed the browser before the install ping fired metrics.ping('install'); @@ -1616,17 +1631,25 @@ function initializeGhosteryModules() { // Set these tasks to run every hour function scheduledTasks() { - // auto-fetch from CMP - cmp.fetchCMPData(); + return new Promise((resolve) => { + // auto-fetch from CMP + cmp.fetchCMPData(); - if (!IS_CLIQZ) { - // auto-fetch human web offer - abtest.fetch().then(() => { - setupABTest(); - }).catch(() => { - log('Unable to reach abtest server'); - }); - } + if (!IS_CLIQZ) { + // auto-fetch human web offer + return (abtest.fetch() + .then(() => { + setupABTest(); + }) + .catch(() => { + log('Unable to reach abtest server'); + }) + .finally(() => resolve()) + ); + } + + resolve(); + }); } // Check CMP and ABTest every hour. @@ -1660,7 +1683,18 @@ function initializeGhosteryModules() { cliqzStartup, ]).then(() => { // run scheduledTasks on init - scheduledTasks(); + scheduledTasks().then(() => { + console.error('In scheduledTasks .then callback'); + // open the Ghostery Hub on install with justInstalled query parameter set to true + // we need to do this after running scheduledTasks for the first time + // because of an A/B test that determines which promo variant is shown in the Hub on install + if (globals.JUST_INSTALLED) { + chrome.tabs.create({ + url: chrome.runtime.getURL(`./app/templates/hub.html?justInstalled=true&promoVariant=${conf.hub_promo_variant}`), + active: true + }); + } + }); }); } diff --git a/src/classes/ABTest.js b/src/classes/ABTest.js index df7a235fb..8e4d8fdcb 100644 --- a/src/classes/ABTest.js +++ b/src/classes/ABTest.js @@ -69,6 +69,8 @@ class ABTest { // update conf globals.SESSION.abtests = this.tests; + console.error('A/B Tests found!'); + console.error(`ir: ${conf.install_random_number}`); log('A/B Tests: tests updated to', JSON.stringify(this.tests)); }).catch(() => { log('A/B Tests: error fetching.'); diff --git a/src/classes/ConfData.js b/src/classes/ConfData.js index cd62556e2..9f74e674c 100644 --- a/src/classes/ConfData.js +++ b/src/classes/ConfData.js @@ -116,6 +116,7 @@ class ConfData { _initProperty('enable_smart_block', true); _initProperty('expand_all_trackers', true); _initProperty('hide_alert_trusted', false); + _initProperty('hub_promo_variant', 'not_yet_set'); _initProperty('ignore_first_party', true); _initProperty('import_callout_dismissed', true); _initProperty('insights_promo_modal_last_seen', 0); diff --git a/src/classes/Metrics.js b/src/classes/Metrics.js index 1ef073f08..acfaccac6 100644 --- a/src/classes/Metrics.js +++ b/src/classes/Metrics.js @@ -360,7 +360,11 @@ class Metrics { // Engaged Velocity `&ve=${encodeURIComponent(this._getVelocityEngaged(type).toString())}` + // Theme - `&th=${encodeURIComponent(this._getThemeValue().toString())}`; + `&th=${encodeURIComponent(this._getThemeValue().toString())}` + + + // New parameter for Ghostery 8.5.2 + // Hub Promo variant + `&hp=${encodeURIComponent(this._getHubPromoVariant().toString())}`; if (CAMPAIGN_METRICS.includes(type)) { // only send campaign attribution when necessary @@ -522,6 +526,26 @@ class Metrics { } } + /** + * Get the Int associated with the Hub promo variant shown on install + * @private + * @return {number} Int associated with the Hub promo variant + */ + _getHubPromoVariant() { + const { hub_promo_variant } = conf; + + switch (hub_promo_variant) { + case 'upgrade': + return 1; + case 'plain': + return 2; + case 'midnight': + return 3; + default: + return 0; + } + } + /** * Calculate remaining scheduled time for a ping * From ce3230c1ee7c30706766919dc34ce246e3f0b395 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Tue, 9 Jun 2020 00:51:29 -0400 Subject: [PATCH 2/7] Opportunistic refactor of message handling in background.js --- src/background.js | 502 ++++++++++++++++++++++++++-------------------- 1 file changed, 290 insertions(+), 212 deletions(-) diff --git a/src/background.js b/src/background.js index 3c7b43c7a..a9a775d8f 100644 --- a/src/background.js +++ b/src/background.js @@ -129,7 +129,7 @@ function setGhosteryDefaultBlocking() { if (bugDb.db.apps.hasOwnProperty(app_id)) { const category = bugDb.db.apps[app_id].cat; if (categoriesBlock.indexOf(category) >= 0 && - !selected_app_ids.hasOwnProperty(app_id)) { + !selected_app_ids.hasOwnProperty(app_id)) { selected_app_ids[app_id] = 1; } } @@ -317,6 +317,40 @@ function handleAccountPages(name, callback) { } } +/** + * Handle messages sent from app/js/checkout_pages.js content script. + * @memberOf Background + * + * @param {string} name message name + */ +function handleCheckoutPages(name) { + switch (name) { + case 'checkoutPage.buyInsights': + case 'checkoutPage.buyPlus': + case 'checkoutPage.buyPremium': + account.getUser() + .then(account.getUserSubscriptionData) + .catch((err) => { + log('handleCheckoutPages error', err); + }); + return true; + case 'checkoutPage.login': + account.getUser() + .then(account.getUserSettings) + // account.getUserSettings will reject if user email is not validated + .catch(err => log('handleCheckoutPages error', err)) + .then(account.getUserSubscriptionData) + // The user may not be a subscriber + .catch(err => log('handleCheckoutPages error', err)); + return true; + case 'checkoutPage.register': + account.getUser(); + return true; + default: + break; + } +} + /** * Handle messages sent from dist/ghostery_dot_com.js content script. * @memberOf Background @@ -672,6 +706,10 @@ function onMessageHandler(request, sender, callback) { // Account pages return handleAccountPages(name, callback); } + if (origin === 'checkout_pages') { + // Checkout pages + return handleCheckoutPages(name, callback); + } if (origin === 'purplebox') { // Purplebox script events return handlePurplebox(name, message, tab_id, callback); @@ -743,16 +781,6 @@ function onMessageHandler(request, sender, callback) { callback(); return false; } - if (name === 'account.getTheme') { - if (conf.current_theme !== 'default') { - account.getTheme(conf.current_theme).then(() => { - callback(conf.account.themeData[conf.current_theme]); - }); - return true; - } - callback(); - return false; - } if (name === 'getCliqzModuleData') { // panel-android only utils.getActiveTab((tab) => { sendCliqzModuleCounts(tab.id, tab.pageHost, callback); @@ -766,144 +794,6 @@ function onMessageHandler(request, sender, callback) { }); return true; } - if (name === 'account.login') { - metrics.ping('sign_in'); - const { email, password } = message; - account.login(email, password) - .then((response) => { - if (!response.hasOwnProperty('errors')) { - metrics.ping('sign_in_success'); - } - callback(response); - }) - .catch((err) => { - log('LOGIN ERROR', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - return true; - } - if (name === 'account.register') { - const { - email, confirmEmail, password, firstName, lastName - } = message; - account.register(email, confirmEmail, password, firstName, lastName) - .then((response) => { - if (!response.hasOwnProperty('errors')) { - metrics.ping('create_account_success'); - } - callback(response); - }) - .catch((err) => { - callback({ errors: [err] }); - log('REGISTER ERROR', err); - }); - return true; - } - if (name === 'account.logout') { - account.logout() - .then((response) => { - callback(response); - }) - .catch((err) => { - log('LOGOUT ERROR', err); - callback(err); - }); - return true; - } - if (name === 'account.getUserSettings') { - account.getUserSettings() - .then((settings) => { - callback(settings); - }) - .catch((err) => { - log('Error getting user settings:', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - return true; - } - if (name === 'account.getUserSubscriptionData') { - account.getUserSubscriptionData() - .then((subscriptions) => { - // Return highest tier subscription from array - const premiumSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Premium')); - if (premiumSubscription) { - callback({ subscriptionData: premiumSubscription }); - return; - } - - const plusSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Plus')); - if (plusSubscription) { - callback({ subscriptionData: plusSubscription }); - return; - } - - callback({}); - }) - .catch((err) => { - log('Error getting user subscription data:', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - return true; - } - if (name === 'account.openSubscriptionPage') { - utils.openNewTab({ url: `${globals.ACCOUNT_BASE_URL}/subscription`, become_active: true }); - return false; - } - if (name === 'account.openCheckoutPage') { - let url = `${globals.CHECKOUT_BASE_URL}/plus`; - const { utm } = message || null; - if (utm) { - url += `?utm_source=${utm.utm_source}&utm_campaign=${utm.utm_campaign}`; - } - utils.openNewTab({ url, become_active: true }); - return false; - } - if (name === 'account.openSupportPage') { - metrics.ping('priority_support_submit'); - const subscriber = account.hasScopesUnverified(['subscriptions:plus']); - const tabUrl = subscriber ? `${globals.ACCOUNT_BASE_URL}/support` : 'https://www.ghostery.com/support/'; - utils.openNewTab({ url: tabUrl, become_active: true }); - return false; - } - if (name === 'account.resetPassword') { - const { email } = message; - account.resetPassword(email) - .then((success) => { - callback(success); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('RESET PASSWORD ERROR', err); - }); - return true; - } - if (name === 'account.getUser') { - account.getUser(message) - .then((user) => { - if (user) { - user.plusAccess = account.hasScopesUnverified(['subscriptions:plus']) - || account.hasScopesUnverified(['subscriptions:premium']); - user.premiumAccess = account.hasScopesUnverified(['subscriptions:premium']); - } - callback({ user }); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('FETCH USER ERROR', err); - }); - return true; - } - if (name === 'account.sendValidateAccountEmail') { - account.sendValidateAccountEmail() - .then((success) => { - callback(success); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('sendValidateAccountEmail error', err); - }); - return true; - } if (name === 'update_database') { checkLibraryVersion().then((result) => { callback(result); @@ -980,22 +870,244 @@ function onMessageHandler(request, sender, callback) { }); return true; } - if (name === 'promoModals.sawPremiumPromo') { - promoModals.recordPremiumPromoSighting(); - return false; + + if (name && name.startsWith('account.')) { + return handleAccountMessage(name.split('.')[1], message, callback); } - if (name === 'promoModals.sawInsightsPromo') { - promoModals.recordInsightsPromoSighting(); - return false; + + if (name && name.startsWith('promoModals.')) { + return handlePromoModalMessage(name.split('.')[1]); } - if (name === 'promoModals.sawPlusPromo') { - promoModals.recordPlusPromoSighting(); - return false; +} + +// TODO add function description +function hamGetTheme(callback) { + if (conf.current_theme !== 'default') { + account.getTheme(conf.current_theme) + .then(() => { + callback(conf.account.themeData[conf.current_theme]); + }); + return true; } - if (name === 'promoModals.turnOffPromos') { - promoModals.turnOffPromos(); - return false; + callback(); + return false; +} + +// TODO add function description +function hamGetUser(payload, callback) { + account.getUser(payload) + .then((user) => { + if (user) { + user.plusAccess = ( + account.hasScopesUnverified(['subscriptions:plus']) + || account.hasScopesUnverified(['subscriptions:premium']) + ); + user.premiumAccess = account.hasScopesUnverified(['subscriptions:premium']); + } + callback({ user }); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('FETCH USER ERROR', err); + }); + return true; +} + +// TODO add function description +function hamGetUserSettings(callback) { + account.getUserSettings() + .then((settings) => { + callback(settings); + }) + .catch((err) => { + log('Error getting user settings:', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + return true; +} + +// TODO add function description +function hamGetUserSubscriptionData(callback) { + account.getUserSubscriptionData() + .then((subscriptions) => { + // Return highest tier subscription from array + const premiumSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Premium')); + if (premiumSubscription) { + callback({ subscriptionData: premiumSubscription }); + return; + } + + const plusSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Plus')); + if (plusSubscription) { + callback({ subscriptionData: plusSubscription }); + return; + } + + callback({}); + }) + .catch((err) => { + log('Error getting user subscription data:', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + return true; +} + +// TODO add function description +function hamLogin(msgData, callback) { + const { email, password } = msgData; + + account.login(email, password) + .then((response) => { + if (!response.hasOwnProperty('errors')) { + metrics.ping('sign_in_success'); + } + callback(response); + }) + .catch((err) => { + log('LOGIN ERROR', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + + metrics.ping('sign_in'); + + return true; +} + +// TODO add function description +function hamLogout(callback) { + account.logout() + .then((response) => { + callback(response); + }) + .catch((err) => { + log('LOGOUT ERROR', err); + callback(err); + }); + return true; +} + +// TODO add function description +function hamOpenCheckoutPage(utm) { + let url = `${globals.CHECKOUT_BASE_URL}/plus`; + if (utm) { + const { utm_source, utm_campaign } = utm; + url += `?utm_source=${utm_source}&utm_campaign=${utm_campaign}`; } + utils.openNewTab({ url, become_active: true }); + return false; +} + +// TODO add function description +function hamOpenSubscriptionPage() { + utils.openNewTab({ url: `${globals.ACCOUNT_BASE_URL}/subscription`, become_active: true }); + return false; +} + +// TODO add function description +function hamOpenSupportPage() { + const subscriber = account.hasScopesUnverified(['subscriptions:plus']); + const tabUrl = subscriber ? `${globals.ACCOUNT_BASE_URL}/support` : 'https://www.ghostery.com/support/'; + utils.openNewTab({ url: tabUrl, become_active: true }); + + metrics.ping('priority_support_submit'); + + return false; +} + +// TODO add function description +function hamRegister(userDetails, callback) { + const { + email, + confirmEmail, + password, + firstName, + lastName, + } = userDetails; + + account.register(email, confirmEmail, password, firstName, lastName) + .then((response) => { + if (!response.hasOwnProperty('errors')) { + metrics.ping('create_account_success'); + } + callback(response); + }) + .catch((err) => { + callback({ errors: [err] }); + log('REGISTER ERROR', err); + }); + + return true; +} + +// TODO add function description +function hamResetPassword(email, callback) { + // TODO check args + account.resetPassword(email) + .then((success) => { + callback(success); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('RESET PASSWORD ERROR', err); + }); + return true; +} + +// TODO add function description +function hamValidateAccountEmail(callback) { + account.sendValidateAccountEmail() + .then((success) => { + callback(success); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('sendValidateAccountEmail error', err); + }); + + return true; +} + +/** + * Handle messages related to user accounts + * @memberOf Background + * + * @param {string} name the name of the message sent by the calling script + * @param {Object} payload the data of the message sent by the calling script + * @param {function} callback function to call (at most once) when you have a response + * @return {boolean} denotes async (true) or sync (false) + */ +function handleAccountMessage(name, payload, callback) { + // TODO improve arg names : ? msgName, msgBody ? + switch (name) { + case 'getTheme': return hamGetTheme(callback); + case 'getUser': return hamGetUser(payload, callback); + case 'getUserSettings': return hamGetUserSettings(callback); + case 'getUserSubscriptionData': return hamGetUserSubscriptionData(callback); + case 'login': return hamLogin(payload, callback); + case 'logout': return hamLogout(callback); + case 'openCheckoutPage': return hamOpenCheckoutPage(payload.utm || null); + case 'openSubscriptionPage': return hamOpenSubscriptionPage(); + case 'openSupportPage': return hamOpenSupportPage(); + case 'register': return hamRegister(payload, callback); + case 'resetPassword': return hamResetPassword(payload.email, callback); + case 'sendValidateAccountEmail': return hamValidateAccountEmail(callback); + default: return false; + } +} + +/** + * Handle messages related to promo modals + * @memberOf Background + * + * @param {string} name the message name + * @return {boolean} denotes async (true) or sync (false) + */ +function handlePromoModalMessage(name) { + if (name === 'sawPremiumPromo') promoModals.recordPremiumPromoSighting(); + else if (name === 'sawInsightsPromo') promoModals.recordInsightsPromoSighting(); + else if (name === 'sawPlusPromos') promoModals.recordPlusPromoSighting(); + else if (name === 'turnOffPromos') promoModals.turnOffPromos(); + return false; } /** @@ -1107,25 +1219,6 @@ function getAntitrackingTestConfig() { }; } -/** - * Set option for Hub promo A/B/C test based - * on the results returned from the abtest endpoint. - * @memberOf Background - * - * @return {Object} Hub promotion configuration parameters - */ -function setupHubPromoABTest() { - if (abtest.hasTest('hub_plain')) { - conf.hub_promo_variant = 'plain'; - } else if (abtest.hasTest('hub_midnight')) { - conf.hub_promo_variant = 'midnight'; - } else { - conf.hub_promo_variant = 'upgrade'; - } - - console.error(`conf.hub_promo_version in setupHubPromoABTest: ${conf.hub_promo_variant}`); -} - /** * Adjust antitracking parameters based on the current state * of ABTest and availability of Human Web. @@ -1154,8 +1247,6 @@ function setupABTest() { // cliqz.disableModule('search'); // cliqz.disableModule('overlay'); // } - - setupHubPromoABTest(); } /** @@ -1567,6 +1658,12 @@ function initializeGhosteryModules() { setTimeout(() => { metrics.ping('install_complete'); }, 300000); + + // open the Ghostery Hub on install with justInstalled query parameter set to true + chrome.tabs.create({ + url: chrome.runtime.getURL('./app/templates/hub.html?justInstalled=true'), + active: true + }); } else { // Record install if the user previously closed the browser before the install ping fired metrics.ping('install'); @@ -1631,25 +1728,17 @@ function initializeGhosteryModules() { // Set these tasks to run every hour function scheduledTasks() { - return new Promise((resolve) => { - // auto-fetch from CMP - cmp.fetchCMPData(); - - if (!IS_CLIQZ) { - // auto-fetch human web offer - return (abtest.fetch() - .then(() => { - setupABTest(); - }) - .catch(() => { - log('Unable to reach abtest server'); - }) - .finally(() => resolve()) - ); - } + // auto-fetch from CMP + cmp.fetchCMPData(); - resolve(); - }); + if (!IS_CLIQZ) { + // auto-fetch human web offer + abtest.fetch().then(() => { + setupABTest(); + }).catch(() => { + log('Unable to reach abtest server'); + }); + } } // Check CMP and ABTest every hour. @@ -1683,18 +1772,7 @@ function initializeGhosteryModules() { cliqzStartup, ]).then(() => { // run scheduledTasks on init - scheduledTasks().then(() => { - console.error('In scheduledTasks .then callback'); - // open the Ghostery Hub on install with justInstalled query parameter set to true - // we need to do this after running scheduledTasks for the first time - // because of an A/B test that determines which promo variant is shown in the Hub on install - if (globals.JUST_INSTALLED) { - chrome.tabs.create({ - url: chrome.runtime.getURL(`./app/templates/hub.html?justInstalled=true&promoVariant=${conf.hub_promo_variant}`), - active: true - }); - } - }); + scheduledTasks(); }); } From b23bc6c18fed13f6fdc44dc93b5e18ce38819e67 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Tue, 9 Jun 2020 01:01:19 -0400 Subject: [PATCH 3/7] Revert "Opportunistic refactor of message handling in background.js" This reverts commit ce3230c1ee7c30706766919dc34ce246e3f0b395. --- src/background.js | 502 ++++++++++++++++++++-------------------------- 1 file changed, 212 insertions(+), 290 deletions(-) diff --git a/src/background.js b/src/background.js index a9a775d8f..3c7b43c7a 100644 --- a/src/background.js +++ b/src/background.js @@ -129,7 +129,7 @@ function setGhosteryDefaultBlocking() { if (bugDb.db.apps.hasOwnProperty(app_id)) { const category = bugDb.db.apps[app_id].cat; if (categoriesBlock.indexOf(category) >= 0 && - !selected_app_ids.hasOwnProperty(app_id)) { + !selected_app_ids.hasOwnProperty(app_id)) { selected_app_ids[app_id] = 1; } } @@ -317,40 +317,6 @@ function handleAccountPages(name, callback) { } } -/** - * Handle messages sent from app/js/checkout_pages.js content script. - * @memberOf Background - * - * @param {string} name message name - */ -function handleCheckoutPages(name) { - switch (name) { - case 'checkoutPage.buyInsights': - case 'checkoutPage.buyPlus': - case 'checkoutPage.buyPremium': - account.getUser() - .then(account.getUserSubscriptionData) - .catch((err) => { - log('handleCheckoutPages error', err); - }); - return true; - case 'checkoutPage.login': - account.getUser() - .then(account.getUserSettings) - // account.getUserSettings will reject if user email is not validated - .catch(err => log('handleCheckoutPages error', err)) - .then(account.getUserSubscriptionData) - // The user may not be a subscriber - .catch(err => log('handleCheckoutPages error', err)); - return true; - case 'checkoutPage.register': - account.getUser(); - return true; - default: - break; - } -} - /** * Handle messages sent from dist/ghostery_dot_com.js content script. * @memberOf Background @@ -706,10 +672,6 @@ function onMessageHandler(request, sender, callback) { // Account pages return handleAccountPages(name, callback); } - if (origin === 'checkout_pages') { - // Checkout pages - return handleCheckoutPages(name, callback); - } if (origin === 'purplebox') { // Purplebox script events return handlePurplebox(name, message, tab_id, callback); @@ -781,6 +743,16 @@ function onMessageHandler(request, sender, callback) { callback(); return false; } + if (name === 'account.getTheme') { + if (conf.current_theme !== 'default') { + account.getTheme(conf.current_theme).then(() => { + callback(conf.account.themeData[conf.current_theme]); + }); + return true; + } + callback(); + return false; + } if (name === 'getCliqzModuleData') { // panel-android only utils.getActiveTab((tab) => { sendCliqzModuleCounts(tab.id, tab.pageHost, callback); @@ -794,6 +766,144 @@ function onMessageHandler(request, sender, callback) { }); return true; } + if (name === 'account.login') { + metrics.ping('sign_in'); + const { email, password } = message; + account.login(email, password) + .then((response) => { + if (!response.hasOwnProperty('errors')) { + metrics.ping('sign_in_success'); + } + callback(response); + }) + .catch((err) => { + log('LOGIN ERROR', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + return true; + } + if (name === 'account.register') { + const { + email, confirmEmail, password, firstName, lastName + } = message; + account.register(email, confirmEmail, password, firstName, lastName) + .then((response) => { + if (!response.hasOwnProperty('errors')) { + metrics.ping('create_account_success'); + } + callback(response); + }) + .catch((err) => { + callback({ errors: [err] }); + log('REGISTER ERROR', err); + }); + return true; + } + if (name === 'account.logout') { + account.logout() + .then((response) => { + callback(response); + }) + .catch((err) => { + log('LOGOUT ERROR', err); + callback(err); + }); + return true; + } + if (name === 'account.getUserSettings') { + account.getUserSettings() + .then((settings) => { + callback(settings); + }) + .catch((err) => { + log('Error getting user settings:', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + return true; + } + if (name === 'account.getUserSubscriptionData') { + account.getUserSubscriptionData() + .then((subscriptions) => { + // Return highest tier subscription from array + const premiumSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Premium')); + if (premiumSubscription) { + callback({ subscriptionData: premiumSubscription }); + return; + } + + const plusSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Plus')); + if (plusSubscription) { + callback({ subscriptionData: plusSubscription }); + return; + } + + callback({}); + }) + .catch((err) => { + log('Error getting user subscription data:', err); + callback({ errors: _getJSONAPIErrorsObject(err) }); + }); + return true; + } + if (name === 'account.openSubscriptionPage') { + utils.openNewTab({ url: `${globals.ACCOUNT_BASE_URL}/subscription`, become_active: true }); + return false; + } + if (name === 'account.openCheckoutPage') { + let url = `${globals.CHECKOUT_BASE_URL}/plus`; + const { utm } = message || null; + if (utm) { + url += `?utm_source=${utm.utm_source}&utm_campaign=${utm.utm_campaign}`; + } + utils.openNewTab({ url, become_active: true }); + return false; + } + if (name === 'account.openSupportPage') { + metrics.ping('priority_support_submit'); + const subscriber = account.hasScopesUnverified(['subscriptions:plus']); + const tabUrl = subscriber ? `${globals.ACCOUNT_BASE_URL}/support` : 'https://www.ghostery.com/support/'; + utils.openNewTab({ url: tabUrl, become_active: true }); + return false; + } + if (name === 'account.resetPassword') { + const { email } = message; + account.resetPassword(email) + .then((success) => { + callback(success); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('RESET PASSWORD ERROR', err); + }); + return true; + } + if (name === 'account.getUser') { + account.getUser(message) + .then((user) => { + if (user) { + user.plusAccess = account.hasScopesUnverified(['subscriptions:plus']) + || account.hasScopesUnverified(['subscriptions:premium']); + user.premiumAccess = account.hasScopesUnverified(['subscriptions:premium']); + } + callback({ user }); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('FETCH USER ERROR', err); + }); + return true; + } + if (name === 'account.sendValidateAccountEmail') { + account.sendValidateAccountEmail() + .then((success) => { + callback(success); + }) + .catch((err) => { + callback({ errors: _getJSONAPIErrorsObject(err) }); + log('sendValidateAccountEmail error', err); + }); + return true; + } if (name === 'update_database') { checkLibraryVersion().then((result) => { callback(result); @@ -870,246 +980,24 @@ function onMessageHandler(request, sender, callback) { }); return true; } - - if (name && name.startsWith('account.')) { - return handleAccountMessage(name.split('.')[1], message, callback); - } - - if (name && name.startsWith('promoModals.')) { - return handlePromoModalMessage(name.split('.')[1]); + if (name === 'promoModals.sawPremiumPromo') { + promoModals.recordPremiumPromoSighting(); + return false; } -} - -// TODO add function description -function hamGetTheme(callback) { - if (conf.current_theme !== 'default') { - account.getTheme(conf.current_theme) - .then(() => { - callback(conf.account.themeData[conf.current_theme]); - }); - return true; + if (name === 'promoModals.sawInsightsPromo') { + promoModals.recordInsightsPromoSighting(); + return false; } - callback(); - return false; -} - -// TODO add function description -function hamGetUser(payload, callback) { - account.getUser(payload) - .then((user) => { - if (user) { - user.plusAccess = ( - account.hasScopesUnverified(['subscriptions:plus']) - || account.hasScopesUnverified(['subscriptions:premium']) - ); - user.premiumAccess = account.hasScopesUnverified(['subscriptions:premium']); - } - callback({ user }); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('FETCH USER ERROR', err); - }); - return true; -} - -// TODO add function description -function hamGetUserSettings(callback) { - account.getUserSettings() - .then((settings) => { - callback(settings); - }) - .catch((err) => { - log('Error getting user settings:', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - return true; -} - -// TODO add function description -function hamGetUserSubscriptionData(callback) { - account.getUserSubscriptionData() - .then((subscriptions) => { - // Return highest tier subscription from array - const premiumSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Premium')); - if (premiumSubscription) { - callback({ subscriptionData: premiumSubscription }); - return; - } - - const plusSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Plus')); - if (plusSubscription) { - callback({ subscriptionData: plusSubscription }); - return; - } - - callback({}); - }) - .catch((err) => { - log('Error getting user subscription data:', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - return true; -} - -// TODO add function description -function hamLogin(msgData, callback) { - const { email, password } = msgData; - - account.login(email, password) - .then((response) => { - if (!response.hasOwnProperty('errors')) { - metrics.ping('sign_in_success'); - } - callback(response); - }) - .catch((err) => { - log('LOGIN ERROR', err); - callback({ errors: _getJSONAPIErrorsObject(err) }); - }); - - metrics.ping('sign_in'); - - return true; -} - -// TODO add function description -function hamLogout(callback) { - account.logout() - .then((response) => { - callback(response); - }) - .catch((err) => { - log('LOGOUT ERROR', err); - callback(err); - }); - return true; -} - -// TODO add function description -function hamOpenCheckoutPage(utm) { - let url = `${globals.CHECKOUT_BASE_URL}/plus`; - if (utm) { - const { utm_source, utm_campaign } = utm; - url += `?utm_source=${utm_source}&utm_campaign=${utm_campaign}`; + if (name === 'promoModals.sawPlusPromo') { + promoModals.recordPlusPromoSighting(); + return false; } - utils.openNewTab({ url, become_active: true }); - return false; -} - -// TODO add function description -function hamOpenSubscriptionPage() { - utils.openNewTab({ url: `${globals.ACCOUNT_BASE_URL}/subscription`, become_active: true }); - return false; -} - -// TODO add function description -function hamOpenSupportPage() { - const subscriber = account.hasScopesUnverified(['subscriptions:plus']); - const tabUrl = subscriber ? `${globals.ACCOUNT_BASE_URL}/support` : 'https://www.ghostery.com/support/'; - utils.openNewTab({ url: tabUrl, become_active: true }); - - metrics.ping('priority_support_submit'); - - return false; -} - -// TODO add function description -function hamRegister(userDetails, callback) { - const { - email, - confirmEmail, - password, - firstName, - lastName, - } = userDetails; - - account.register(email, confirmEmail, password, firstName, lastName) - .then((response) => { - if (!response.hasOwnProperty('errors')) { - metrics.ping('create_account_success'); - } - callback(response); - }) - .catch((err) => { - callback({ errors: [err] }); - log('REGISTER ERROR', err); - }); - - return true; -} - -// TODO add function description -function hamResetPassword(email, callback) { - // TODO check args - account.resetPassword(email) - .then((success) => { - callback(success); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('RESET PASSWORD ERROR', err); - }); - return true; -} - -// TODO add function description -function hamValidateAccountEmail(callback) { - account.sendValidateAccountEmail() - .then((success) => { - callback(success); - }) - .catch((err) => { - callback({ errors: _getJSONAPIErrorsObject(err) }); - log('sendValidateAccountEmail error', err); - }); - - return true; -} - -/** - * Handle messages related to user accounts - * @memberOf Background - * - * @param {string} name the name of the message sent by the calling script - * @param {Object} payload the data of the message sent by the calling script - * @param {function} callback function to call (at most once) when you have a response - * @return {boolean} denotes async (true) or sync (false) - */ -function handleAccountMessage(name, payload, callback) { - // TODO improve arg names : ? msgName, msgBody ? - switch (name) { - case 'getTheme': return hamGetTheme(callback); - case 'getUser': return hamGetUser(payload, callback); - case 'getUserSettings': return hamGetUserSettings(callback); - case 'getUserSubscriptionData': return hamGetUserSubscriptionData(callback); - case 'login': return hamLogin(payload, callback); - case 'logout': return hamLogout(callback); - case 'openCheckoutPage': return hamOpenCheckoutPage(payload.utm || null); - case 'openSubscriptionPage': return hamOpenSubscriptionPage(); - case 'openSupportPage': return hamOpenSupportPage(); - case 'register': return hamRegister(payload, callback); - case 'resetPassword': return hamResetPassword(payload.email, callback); - case 'sendValidateAccountEmail': return hamValidateAccountEmail(callback); - default: return false; + if (name === 'promoModals.turnOffPromos') { + promoModals.turnOffPromos(); + return false; } } -/** - * Handle messages related to promo modals - * @memberOf Background - * - * @param {string} name the message name - * @return {boolean} denotes async (true) or sync (false) - */ -function handlePromoModalMessage(name) { - if (name === 'sawPremiumPromo') promoModals.recordPremiumPromoSighting(); - else if (name === 'sawInsightsPromo') promoModals.recordInsightsPromoSighting(); - else if (name === 'sawPlusPromos') promoModals.recordPlusPromoSighting(); - else if (name === 'turnOffPromos') promoModals.turnOffPromos(); - return false; -} - /** * Initialize Dispatcher Events. * All Conf properties trigger a dispatcher pub event @@ -1219,6 +1107,25 @@ function getAntitrackingTestConfig() { }; } +/** + * Set option for Hub promo A/B/C test based + * on the results returned from the abtest endpoint. + * @memberOf Background + * + * @return {Object} Hub promotion configuration parameters + */ +function setupHubPromoABTest() { + if (abtest.hasTest('hub_plain')) { + conf.hub_promo_variant = 'plain'; + } else if (abtest.hasTest('hub_midnight')) { + conf.hub_promo_variant = 'midnight'; + } else { + conf.hub_promo_variant = 'upgrade'; + } + + console.error(`conf.hub_promo_version in setupHubPromoABTest: ${conf.hub_promo_variant}`); +} + /** * Adjust antitracking parameters based on the current state * of ABTest and availability of Human Web. @@ -1247,6 +1154,8 @@ function setupABTest() { // cliqz.disableModule('search'); // cliqz.disableModule('overlay'); // } + + setupHubPromoABTest(); } /** @@ -1658,12 +1567,6 @@ function initializeGhosteryModules() { setTimeout(() => { metrics.ping('install_complete'); }, 300000); - - // open the Ghostery Hub on install with justInstalled query parameter set to true - chrome.tabs.create({ - url: chrome.runtime.getURL('./app/templates/hub.html?justInstalled=true'), - active: true - }); } else { // Record install if the user previously closed the browser before the install ping fired metrics.ping('install'); @@ -1728,17 +1631,25 @@ function initializeGhosteryModules() { // Set these tasks to run every hour function scheduledTasks() { - // auto-fetch from CMP - cmp.fetchCMPData(); + return new Promise((resolve) => { + // auto-fetch from CMP + cmp.fetchCMPData(); - if (!IS_CLIQZ) { - // auto-fetch human web offer - abtest.fetch().then(() => { - setupABTest(); - }).catch(() => { - log('Unable to reach abtest server'); - }); - } + if (!IS_CLIQZ) { + // auto-fetch human web offer + return (abtest.fetch() + .then(() => { + setupABTest(); + }) + .catch(() => { + log('Unable to reach abtest server'); + }) + .finally(() => resolve()) + ); + } + + resolve(); + }); } // Check CMP and ABTest every hour. @@ -1772,7 +1683,18 @@ function initializeGhosteryModules() { cliqzStartup, ]).then(() => { // run scheduledTasks on init - scheduledTasks(); + scheduledTasks().then(() => { + console.error('In scheduledTasks .then callback'); + // open the Ghostery Hub on install with justInstalled query parameter set to true + // we need to do this after running scheduledTasks for the first time + // because of an A/B test that determines which promo variant is shown in the Hub on install + if (globals.JUST_INSTALLED) { + chrome.tabs.create({ + url: chrome.runtime.getURL(`./app/templates/hub.html?justInstalled=true&promoVariant=${conf.hub_promo_variant}`), + active: true + }); + } + }); }); } From 33d4d206711bdcc889deb79af8351cdb6c3fbf34 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Tue, 9 Jun 2020 20:28:15 -0400 Subject: [PATCH 4/7] Do not overwrite hub_promo_variant prop after it is first set --- src/background.js | 2 ++ src/classes/Metrics.js | 1 + 2 files changed, 3 insertions(+) diff --git a/src/background.js b/src/background.js index 3c7b43c7a..fa92a94a7 100644 --- a/src/background.js +++ b/src/background.js @@ -1115,6 +1115,8 @@ function getAntitrackingTestConfig() { * @return {Object} Hub promotion configuration parameters */ function setupHubPromoABTest() { + if (conf.hub_promo_variant !== 'not_yet_set') return; + if (abtest.hasTest('hub_plain')) { conf.hub_promo_variant = 'plain'; } else if (abtest.hasTest('hub_midnight')) { diff --git a/src/classes/Metrics.js b/src/classes/Metrics.js index acfaccac6..9f9652152 100644 --- a/src/classes/Metrics.js +++ b/src/classes/Metrics.js @@ -541,6 +541,7 @@ class Metrics { return 2; case 'midnight': return 3; + case 'not_yet_set': default: return 0; } From 61511e77d36250bd41142b8373899586f4677702 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Sun, 19 Jul 2020 23:32:19 -0400 Subject: [PATCH 5/7] Fixes to satisfy new linter rules --- src/background.js | 169 ++++++++++++++++++++--------------------- src/classes/Metrics.js | 6 +- 2 files changed, 87 insertions(+), 88 deletions(-) diff --git a/src/background.js b/src/background.js index a4d59b0a2..06387278d 100644 --- a/src/background.js +++ b/src/background.js @@ -1050,86 +1050,6 @@ function onMessageHandler(request, sender, callback) { return false; } -/** - * Initialize Dispatcher Events. - * All Conf properties trigger a dispatcher pub event - * whenever the value is set/updated. - * @memberOf Background - */ -function initializeDispatcher() { - dispatcher.on('conf.save.selected_app_ids', (appIds) => { - const num_selected = size(appIds); - const { db } = bugDb; - db.noneSelected = (num_selected === 0); - // can't simply compare num_selected and size(db.apps) since apps get removed sometimes - db.allSelected = (!!num_selected && every(db.apps, (app, app_id) => appIds.hasOwnProperty(app_id))); - }); - dispatcher.on('conf.save.site_whitelist', () => { - // TODO debounce with below - button.update(); - utils.flushChromeMemoryCache(); - cliqz.modules.core.action('refreshAppState'); - }); - dispatcher.on('conf.save.site_blacklist', () => { - button.update(); - }); - dispatcher.on('conf.save.enable_human_web', (enableHumanWeb) => { - if (!IS_CLIQZ) { - setCliqzModuleEnabled(humanweb, enableHumanWeb).then(() => { - setupABTest(); - }); - } else { - setCliqzModuleEnabled(humanweb, false); - } - }); - dispatcher.on('conf.save.enable_offers', (enableOffersIn) => { - button.update(); - const firstStep = Promise.resolve(); - let enableOffers = enableOffersIn; - if (IS_CLIQZ) { - enableOffers = false; - } else if (!enableOffers && cliqz.modules['offers-v2'].isEnabled) { - cliqz.modules['offers-v2'].action('flushSignals'); - } - - const toggleModule = () => setCliqzModuleEnabled(offers, enableOffers); - const toggleConnection = () => registerWithOffers(offers, enableOffers); - if (enableOffers) { - firstStep.then(toggleModule).then(toggleConnection); - } else { - firstStep.then(toggleConnection).then(toggleModule); - } - }); - dispatcher.on('conf.save.enable_anti_tracking', (enableAntitracking) => { - if (!IS_CLIQZ) { - setCliqzModuleEnabled(antitracking, enableAntitracking); - } else { - setCliqzModuleEnabled(antitracking, false); - } - }); - dispatcher.on('conf.save.enable_ad_block', (enableAdBlock) => { - if (!IS_CLIQZ) { - setCliqzModuleEnabled(adblocker, enableAdBlock); - } else { - setCliqzModuleEnabled(adblocker, false); - } - }); - dispatcher.on('conf.save.cliqz_adb_mode', (val) => { - if (!IS_CLIQZ) { - cliqz.prefs.set('cliqz_adb_mode', val); - } - }); - dispatcher.on('conf.changed.settings', debounce((key) => { - log('Conf value changed for a watched user setting:', key); - }, 200)); - dispatcher.on('globals.save.paused_blocking', () => { - // if user has paused Ghostery, suspect broken page - if (globals.SESSION.paused_blocking) { metrics.handleBrokenPageTrigger(globals.BROKEN_PAGE_PAUSE); } - // update content script state when blocking is paused/unpaused - cliqz.modules.core.action('refreshAppState'); - }); -} - /** * Determine Antitracking configuration parameters based * on the results returned from the abtest endpoint. @@ -1215,6 +1135,86 @@ function setupABTest() { setupHubPromoABTest(); } +/** + * Initialize Dispatcher Events. + * All Conf properties trigger a dispatcher pub event + * whenever the value is set/updated. + * @memberOf Background + */ +function initializeDispatcher() { + dispatcher.on('conf.save.selected_app_ids', (appIds) => { + const num_selected = size(appIds); + const { db } = bugDb; + db.noneSelected = (num_selected === 0); + // can't simply compare num_selected and size(db.apps) since apps get removed sometimes + db.allSelected = (!!num_selected && every(db.apps, (app, app_id) => appIds.hasOwnProperty(app_id))); + }); + dispatcher.on('conf.save.site_whitelist', () => { + // TODO debounce with below + button.update(); + utils.flushChromeMemoryCache(); + cliqz.modules.core.action('refreshAppState'); + }); + dispatcher.on('conf.save.site_blacklist', () => { + button.update(); + }); + dispatcher.on('conf.save.enable_human_web', (enableHumanWeb) => { + if (!IS_CLIQZ) { + setCliqzModuleEnabled(humanweb, enableHumanWeb).then(() => { + setupABTest(); + }); + } else { + setCliqzModuleEnabled(humanweb, false); + } + }); + dispatcher.on('conf.save.enable_offers', (enableOffersIn) => { + button.update(); + const firstStep = Promise.resolve(); + let enableOffers = enableOffersIn; + if (IS_CLIQZ) { + enableOffers = false; + } else if (!enableOffers && cliqz.modules['offers-v2'].isEnabled) { + cliqz.modules['offers-v2'].action('flushSignals'); + } + + const toggleModule = () => setCliqzModuleEnabled(offers, enableOffers); + const toggleConnection = () => registerWithOffers(offers, enableOffers); + if (enableOffers) { + firstStep.then(toggleModule).then(toggleConnection); + } else { + firstStep.then(toggleConnection).then(toggleModule); + } + }); + dispatcher.on('conf.save.enable_anti_tracking', (enableAntitracking) => { + if (!IS_CLIQZ) { + setCliqzModuleEnabled(antitracking, enableAntitracking); + } else { + setCliqzModuleEnabled(antitracking, false); + } + }); + dispatcher.on('conf.save.enable_ad_block', (enableAdBlock) => { + if (!IS_CLIQZ) { + setCliqzModuleEnabled(adblocker, enableAdBlock); + } else { + setCliqzModuleEnabled(adblocker, false); + } + }); + dispatcher.on('conf.save.cliqz_adb_mode', (val) => { + if (!IS_CLIQZ) { + cliqz.prefs.set('cliqz_adb_mode', val); + } + }); + dispatcher.on('conf.changed.settings', debounce((key) => { + log('Conf value changed for a watched user setting:', key); + }, 200)); + dispatcher.on('globals.save.paused_blocking', () => { + // if user has paused Ghostery, suspect broken page + if (globals.SESSION.paused_blocking) { metrics.handleBrokenPageTrigger(globals.BROKEN_PAGE_PAUSE); } + // update content script state when blocking is paused/unpaused + cliqz.modules.core.action('refreshAppState'); + }); +} + /** * WebRequest pipeline initialisation: find which Cliqz modules are enabled, * add their handlers, then put Ghostery event handlers before them all. @@ -1691,18 +1691,17 @@ function initializeGhosteryModules() { if (!IS_CLIQZ) { // auto-fetch human web offer - return (abtest.fetch() + abtest.fetch() .then(() => { setupABTest(); }) .catch(() => { log('Unable to reach abtest server'); }) - .finally(() => resolve()) - ); + .finally(() => resolve()); + } else { + resolve(); } - - resolve(); }); } diff --git a/src/classes/Metrics.js b/src/classes/Metrics.js index a20c0b902..13a1efa62 100644 --- a/src/classes/Metrics.js +++ b/src/classes/Metrics.js @@ -366,11 +366,11 @@ class Metrics { // Engaged Velocity `&ve=${encodeURIComponent(Metrics._getVelocityEngaged(type).toString())}` + // Theme - `&th=${encodeURIComponent(this._getThemeValue().toString())}` + + `&th=${encodeURIComponent(Metrics._getThemeValue().toString())}` + // New parameter for Ghostery 8.5.2 // Hub Promo variant - `&hp=${encodeURIComponent(this._getHubPromoVariant().toString())}`; + `&hp=${encodeURIComponent(Metrics._getHubPromoVariant().toString())}`; if (CAMPAIGN_METRICS.includes(type)) { // only send campaign attribution when necessary @@ -534,7 +534,7 @@ class Metrics { * @private * @return {number} Int associated with the Hub promo variant */ - _getHubPromoVariant() { + static _getHubPromoVariant() { const { hub_promo_variant } = conf; switch (hub_promo_variant) { From 75508b3b2226693e09081eb963885c654b683e61 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Mon, 20 Jul 2020 00:49:07 -0400 Subject: [PATCH 6/7] Display plain home view, home view with Premium modal, or new Upgrade Plan view in Hub depending on A/B/C/ test bucket --- app/hub/Views/HomeView/HomeViewContainer.jsx | 4 ++-- src/background.js | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/hub/Views/HomeView/HomeViewContainer.jsx b/app/hub/Views/HomeView/HomeViewContainer.jsx index 380d9e3cd..b1d43fced 100644 --- a/app/hub/Views/HomeView/HomeViewContainer.jsx +++ b/app/hub/Views/HomeView/HomeViewContainer.jsx @@ -119,9 +119,9 @@ class HomeViewContainer extends Component { } = home; // Flag to display promo modal (used in A/B testing) - const shouldShowPromoModal = false; + const { pm } = QueryString.parse(window.location.search); // Logic to display premium modal if it is the case that it is being shown once per hub refresh to non-premium users - const showPromoModal = shouldShowPromoModal && !premium_promo_modal_shown && !isPremium; + const showPromoModal = pm && pm === 'true' && !premium_promo_modal_shown && !isPremium; return (
diff --git a/src/background.js b/src/background.js index 06387278d..3acd6b4c0 100644 --- a/src/background.js +++ b/src/background.js @@ -1099,8 +1099,6 @@ function setupHubPromoABTest() { } else { conf.hub_promo_variant = 'upgrade'; } - - console.error(`conf.hub_promo_version in setupHubPromoABTest: ${conf.hub_promo_variant}`); } /** @@ -1737,13 +1735,14 @@ function initializeGhosteryModules() { ]).then(() => { // run scheduledTasks on init scheduledTasks().then(() => { - console.error('In scheduledTasks .then callback'); // open the Ghostery Hub on install with justInstalled query parameter set to true // we need to do this after running scheduledTasks for the first time // because of an A/B test that determines which promo variant is shown in the Hub on install if (globals.JUST_INSTALLED) { + const route = (conf.hub_promo_variant === 'upgrade' || conf.hub_promo_variant === 'not_yet_set') ? '' : '#home'; + const showPremiumPromoModal = conf.hub_promo_variant === 'midnight'; chrome.tabs.create({ - url: chrome.runtime.getURL(`./app/templates/hub.html?justInstalled=true&promoVariant=${conf.hub_promo_variant}`), + url: chrome.runtime.getURL(`./app/templates/hub.html?$justInstalled=true&pm=${showPremiumPromoModal}${route}`), active: true }); } From f607966c4fba83b0055a601958164806440586c9 Mon Sep 17 00:00:00 2001 From: wlycdgr Date: Mon, 20 Jul 2020 00:51:54 -0400 Subject: [PATCH 7/7] Remove console statements --- src/classes/ABTest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/classes/ABTest.js b/src/classes/ABTest.js index 8e4d8fdcb..df7a235fb 100644 --- a/src/classes/ABTest.js +++ b/src/classes/ABTest.js @@ -69,8 +69,6 @@ class ABTest { // update conf globals.SESSION.abtests = this.tests; - console.error('A/B Tests found!'); - console.error(`ir: ${conf.install_random_number}`); log('A/B Tests: tests updated to', JSON.stringify(this.tests)); }).catch(() => { log('A/B Tests: error fetching.');