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

Fixes to satisfy new linter rules

  • Loading branch information
wlycdgr committed Jul 20, 2020
commit 61511e77d36250bd41142b8373899586f4677702
@@ -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();
});
}

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