This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start #2081, implement an A/B test of badging the Page Shot button un…
…til it is first clicked
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { getAbTests } = require("./user"); | ||
const { storage } = require("sdk/simple-storage"); | ||
const req = require("./req"); | ||
|
||
const storageKey = "ab-highlight-button-on-install"; | ||
|
||
const SHOW_BADGE_LIMIT = 1000 * 60 * 60 * 24; // 1 day | ||
|
||
function shouldShowBadge() { | ||
let abTests = getAbTests(); | ||
return abTests.highlightButtonOnInstall && abTests.highlightButtonOnInstall.value == "badge"; | ||
} | ||
|
||
exports.mainCalled = function (loadReason) { | ||
console.log("mainCalled", loadReason, shouldShowBadge()); | ||
let timestamp, hasCreatedShot; | ||
if (shouldShowBadge()) { | ||
if (loadReason == "install") { | ||
timestamp = storage[storageKey + "-timestamp"] = Date.now(); | ||
hasCreatedShot = storage[storageKey + "-has-created-shot"] = false; | ||
} else if (storage[storageKey + "-timestamp"] === undefined) { | ||
// Someone who is not a new user got opted in to this test | ||
timestamp = 0; | ||
hasCreatedShot = true; | ||
} else { | ||
timestamp = storage[storageKey + "-timestamp"]; | ||
hasCreatedShot = storage[storageKey + "-has-created-shot"]; | ||
} | ||
refreshBadge(timestamp, hasCreatedShot); | ||
} | ||
}; | ||
|
||
exports.buttonClicked = function () { | ||
if (shouldShowBadge()) { | ||
storage[storageKey + "-has-created-shot"] = true; | ||
refreshBadge(0, true); | ||
} | ||
}; | ||
|
||
function refreshBadge(timestamp, hasCreatedShot) { | ||
console.log("refreshBadge", timestamp, hasCreatedShot); | ||
if ((! hasCreatedShot) && (Date.now() - timestamp < SHOW_BADGE_LIMIT)) { | ||
req.sendEvent("ab-highlight-button-shown", {ni: true}); | ||
require("./main").shootButton.badge = " ! "; | ||
} else { | ||
require("./main").shootButton.badge = ""; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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