Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created August 25, 2016 18:27
Show Gist options
  • Save gregglind/a07dfe397405252ad36dc260d92098e7 to your computer and use it in GitHub Desktop.
Save gregglind/a07dfe397405252ad36dc260d92098e7 to your computer and use it in GitHub Desktop.
// studyInfo.js
"use strict";
const prefSvc = require("sdk/preferences/service");
const OURPREF = 'some.newfeature.design';
const name = require("sdk/self").id;
const duration = 7;
const surveyUrl = "https://qsurvey.mozilla.com/s3/Shield-Study-Example-Survey";
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);
}
const aStudyConfig = {
name: name,
duration: duration,
surveyUrl: surveyUrl,
isEligible: isEligible,
cleanup: cleanup,
variations: variations,
};
module.exports = aStudyConfig;
// index.js
"use strict";
const self = require("sdk/self");
const { when: unload } = require("sdk/system/unload");
const shield = require("shield-studies-addon-utils");
const studyConfig = require("./studyConfig");
const thisStudy = new shield.Study(studyConfig);
shield.Reporter.on("report",(d)=>console.info("telemetry", d));
thisStudy.on("change",(newState)=>console.info("newState:", newState));
function orientationMsg () {
require("sdk/panel").Panel({
width: 400, height: 400,
contentURL: "data:text/html,Some orientation content"
}).show()
shield.report({action: "orientation-showed"})
}
function ineligibleMsg () {
require("sdk/tabs").open("data:text/html,You are ineligible, sorry! Next time?")
}
thisStudy.once("installed", orientationMsg)
thisStudy.once("ineligible-die", ineligibleMsg)
thisStudy.startup(self.loadReason);
unload((reason) => {
thisStudy.shutdown(reason);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment