Last active
August 24, 2016 13:51
-
-
Save gregglind/b33e28daa80cbd7e996981096dc4a876 to your computer and use it in GitHub Desktop.
Shield Study Example: Simple Pref Flipping Study
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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