forked from mirrors/gecko-dev
Bug 1852138 - [Survey] Add 24 hours time gap from opt-in before displaying survey r=omc-reviewers,aminomancer
Differential Revision: https://phabricator.services.mozilla.com/D188386
This commit is contained in:
parent
b83f530f68
commit
b67cc3be4f
3 changed files with 101 additions and 1 deletions
|
|
@ -629,6 +629,8 @@ const SHOPPING_MICROSURVEY = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const OPTED_IN_TIME_PREF = "browser.shopping.experience2023.survey.optedInTime";
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
lazy,
|
lazy,
|
||||||
"isSurveySeen",
|
"isSurveySeen",
|
||||||
|
|
@ -643,9 +645,18 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
|
lazy,
|
||||||
|
"optedInTime",
|
||||||
|
OPTED_IN_TIME_PREF,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
let optInDynamicContent;
|
let optInDynamicContent;
|
||||||
// Limit pref increase to 5 as we don't need to count any higher than that
|
// Limit pref increase to 5 as we don't need to count any higher than that
|
||||||
const MIN_VISITS_TO_SHOW_SURVEY = 5;
|
const MIN_VISITS_TO_SHOW_SURVEY = 5;
|
||||||
|
// Wait 24 hours after opt in to show survey
|
||||||
|
const MIN_TIME_AFTER_OPT_IN = 24 * 60 * 60;
|
||||||
|
|
||||||
class AboutWelcomeShoppingChild extends AboutWelcomeChild {
|
class AboutWelcomeShoppingChild extends AboutWelcomeChild {
|
||||||
// Static state used to track session in which user opted-in
|
// Static state used to track session in which user opted-in
|
||||||
|
|
@ -688,17 +699,35 @@ class AboutWelcomeShoppingChild extends AboutWelcomeChild {
|
||||||
evaluateAndShowSurvey() {
|
evaluateAndShowSurvey() {
|
||||||
// Re-evaluate if we should show the survey
|
// Re-evaluate if we should show the survey
|
||||||
// Render survey if user is opted-in and has met survey seen conditions
|
// Render survey if user is opted-in and has met survey seen conditions
|
||||||
|
const now = Date.now() / 1000;
|
||||||
|
const hasBeen24HrsSinceOptin =
|
||||||
|
lazy.optedInTime && now - lazy.optedInTime >= MIN_TIME_AFTER_OPT_IN;
|
||||||
|
|
||||||
this.showMicroSurvey =
|
this.showMicroSurvey =
|
||||||
this.surveyEnabled &&
|
this.surveyEnabled &&
|
||||||
!lazy.isSurveySeen &&
|
!lazy.isSurveySeen &&
|
||||||
!AboutWelcomeShoppingChild.optedInSession &&
|
!AboutWelcomeShoppingChild.optedInSession &&
|
||||||
lazy.pdpVisits >= MIN_VISITS_TO_SHOW_SURVEY;
|
lazy.pdpVisits >= MIN_VISITS_TO_SHOW_SURVEY &&
|
||||||
|
hasBeen24HrsSinceOptin;
|
||||||
|
|
||||||
if (this.showMicroSurvey) {
|
if (this.showMicroSurvey) {
|
||||||
this.renderMessage();
|
this.renderMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOptInTime() {
|
||||||
|
const now = Date.now() / 1000;
|
||||||
|
this.AWSendToParent("SPECIAL_ACTION", {
|
||||||
|
type: "SET_PREF",
|
||||||
|
data: {
|
||||||
|
pref: {
|
||||||
|
name: OPTED_IN_TIME_PREF,
|
||||||
|
value: now,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
handleEvent(event) {
|
handleEvent(event) {
|
||||||
// Decide when to show/hide onboarding and survey message
|
// Decide when to show/hide onboarding and survey message
|
||||||
const { productUrl, showOnboarding, data } = event.detail;
|
const { productUrl, showOnboarding, data } = event.detail;
|
||||||
|
|
@ -713,6 +742,14 @@ class AboutWelcomeShoppingChild extends AboutWelcomeChild {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Store timestamp if user opts in
|
||||||
|
if (
|
||||||
|
Object.hasOwn(event.detail, "showOnboarding") &&
|
||||||
|
!event.detail.showOnboarding &&
|
||||||
|
!lazy.optedInTime
|
||||||
|
) {
|
||||||
|
this.setOptInTime();
|
||||||
|
}
|
||||||
// Hide the container until the user is eligible to see the survey
|
// Hide the container until the user is eligible to see the survey
|
||||||
if (!lazy.isSurveySeen) {
|
if (!lazy.isSurveySeen) {
|
||||||
this.document.getElementById("multi-stage-message-root").hidden = true;
|
this.document.getElementById("multi-stage-message-root").hidden = true;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const currentTime = Date.now() / 1000;
|
||||||
|
const time25HrsAgo = currentTime - 25 * 60 * 60;
|
||||||
|
const time1HrAgo = currentTime - 1 * 60 * 60;
|
||||||
|
|
||||||
add_task(async function test_setup() {
|
add_task(async function test_setup() {
|
||||||
await BrowserTestUtils.withNewTab(
|
await BrowserTestUtils.withNewTab(
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +34,7 @@ add_task(async function test_showSurvey_Enabled() {
|
||||||
["browser.shopping.experience2023.survey.enabled", true],
|
["browser.shopping.experience2023.survey.enabled", true],
|
||||||
["browser.shopping.experience2023.survey.hasSeen", false],
|
["browser.shopping.experience2023.survey.hasSeen", false],
|
||||||
["browser.shopping.experience2023.survey.pdpVisits", 5],
|
["browser.shopping.experience2023.survey.pdpVisits", 5],
|
||||||
|
["browser.shopping.experience2023.survey.optedInTime", time25HrsAgo],
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
await BrowserTestUtils.withNewTab(
|
await BrowserTestUtils.withNewTab(
|
||||||
|
|
@ -121,6 +126,7 @@ add_task(async function test_showSurvey_Disabled() {
|
||||||
["browser.shopping.experience2023.survey.enabled", false],
|
["browser.shopping.experience2023.survey.enabled", false],
|
||||||
["browser.shopping.experience2023.survey.hasSeen", false],
|
["browser.shopping.experience2023.survey.hasSeen", false],
|
||||||
["browser.shopping.experience2023.survey.pdpVisits", 5],
|
["browser.shopping.experience2023.survey.pdpVisits", 5],
|
||||||
|
["browser.shopping.experience2023.survey.optedInTime", time25HrsAgo],
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
await BrowserTestUtils.withNewTab(
|
await BrowserTestUtils.withNewTab(
|
||||||
|
|
@ -180,3 +186,59 @@ add_task(async function test_showSurvey_Disabled() {
|
||||||
);
|
);
|
||||||
await SpecialPowers.popPrefEnv();
|
await SpecialPowers.popPrefEnv();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check survey display logic respects 24 hours after Opt-in rule
|
||||||
|
*/
|
||||||
|
add_task(async function test_24_hr_since_optin_rule() {
|
||||||
|
await SpecialPowers.pushPrefEnv({
|
||||||
|
set: [
|
||||||
|
["browser.shopping.experience2023.optedIn", 1],
|
||||||
|
["browser.shopping.experience2023.survey.enabled", true],
|
||||||
|
["browser.shopping.experience2023.survey.hasSeen", false],
|
||||||
|
["browser.shopping.experience2023.survey.pdpVisits", 5],
|
||||||
|
["browser.shopping.experience2023.survey.optedInTime", time1HrAgo],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
await BrowserTestUtils.withNewTab(
|
||||||
|
{
|
||||||
|
url: "about:shoppingsidebar",
|
||||||
|
gBrowser,
|
||||||
|
},
|
||||||
|
async browser => {
|
||||||
|
await SpecialPowers.spawn(
|
||||||
|
browser,
|
||||||
|
[MOCK_ANALYZED_PRODUCT_RESPONSE],
|
||||||
|
async mockData => {
|
||||||
|
let shoppingContainer =
|
||||||
|
content.document.querySelector(
|
||||||
|
"shopping-container"
|
||||||
|
).wrappedJSObject;
|
||||||
|
shoppingContainer.data = Cu.cloneInto(mockData, content);
|
||||||
|
await shoppingContainer.updateComplete;
|
||||||
|
|
||||||
|
let childActor = content.windowGlobalChild.getExistingActor(
|
||||||
|
"AboutWelcomeShopping"
|
||||||
|
);
|
||||||
|
|
||||||
|
let surveyScreen = content.document.querySelector(
|
||||||
|
"shopping-container .screen.SHOPPING_MICROSURVEY_SCREEN_1"
|
||||||
|
);
|
||||||
|
|
||||||
|
ok(!surveyScreen, "Survey screen is not rendered");
|
||||||
|
ok(
|
||||||
|
!childActor.showMicroSurvey,
|
||||||
|
"Show Survey 24 hours after opt in conditions are not met"
|
||||||
|
);
|
||||||
|
ok(
|
||||||
|
content.document.getElementById("multi-stage-message-root").hidden,
|
||||||
|
"Survey Message container is hidden"
|
||||||
|
);
|
||||||
|
|
||||||
|
childActor.resetChildStates();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
await SpecialPowers.popPrefEnv();
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,7 @@ export const SpecialMessageActions = {
|
||||||
"browser.migrate.preferences-entrypoint.enabled",
|
"browser.migrate.preferences-entrypoint.enabled",
|
||||||
"browser.shopping.experience2023.active",
|
"browser.shopping.experience2023.active",
|
||||||
"browser.shopping.experience2023.optedIn",
|
"browser.shopping.experience2023.optedIn",
|
||||||
|
"browser.shopping.experience2023.survey.optedInTime",
|
||||||
"browser.shopping.experience2023.survey.hasSeen",
|
"browser.shopping.experience2023.survey.hasSeen",
|
||||||
"browser.shopping.experience2023.survey.pdpVisits",
|
"browser.shopping.experience2023.survey.pdpVisits",
|
||||||
"browser.startup.homepage",
|
"browser.startup.homepage",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue