Skip to content

Instantly share code, notes, and snippets.

@gregglind
Last active August 24, 2016 13:51
Show Gist options
  • Save gregglind/b33e28daa80cbd7e996981096dc4a876 to your computer and use it in GitHub Desktop.
Save gregglind/b33e28daa80cbd7e996981096dc4a876 to your computer and use it in GitHub Desktop.
Shield Study Example: Simple Pref Flipping Study
"use strict";
const self = require("sdk/self");
const { when: unload } = require("sdk/system/unload");
const shield = require("shield-studies-addon-utils");
const prefSvc = require("sdk/preferences/service");
/* shield info */
const OURPREF = 'some.newfeature.design';
const variations = {
'strong': () => {prefSvc.set(OURPREF, 'strong')},
'subtle': () => {prefSvc.set(OURPREF, 'subtle')},
'observe-only': () => {prefSvc.set(OURPREF, 'observe-only')},
'ut': () => {}
}
function isEligible () {
return !prefSvc.isSet('some.pref.that.if.set.excludes.user');
}
function cleanup () {
prefSvc.reset(OURPREF);
}
let shieldInfo = {
name: require("sdk/self").id,
duration: 7,
surveyUrl: "https://qsurvey.mozilla.com/s3/Shield-Study-Example-Survey",
isEligible: isEligible,
cleanup: cleanup,
variations: variations,
};
/* run the study, debug logging, unload */
let thisStudy = new shield.Study(studyInfo);
shield.Reporter.on("report",(d)=>console.info("telemetry", d));
thisStudy.on("change",(newState)=>console.info("newState:", newState));
thisStudy.startup(self.loadReason);
unload((reason) => {
console.debug(`special addon unloading code: ${reason}`)
thisStudy.shutdown(reason);
})
// needs:
// npm install shield-studies-addon-utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment