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

GH-2071/Hub-promo-abc-test #583

Merged
merged 9 commits into from Jul 20, 2020
Next

Fetch hub promo ab test before opening hub on install. Add hub promo …

…variant utm param. Add hub promo variant conf prop.
  • Loading branch information
wlycdgr committed Jun 3, 2020
commit 4fb0c4ad2bcdef0e692c6342c65b4870cec1cc7d
@@ -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"
]
}
}
@@ -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
});
}
});
});
}

@@ -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.');
@@ -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);
@@ -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
*
ProTip! Use n and p to navigate between commits in a pull request.