Skip to content

Commit

Permalink
Merge pull request #1632 from mozilla/1631-remove-opt-in-experiment
Browse files Browse the repository at this point in the history
DNM - Revert Opt-in FxA Experiment
  • Loading branch information
groovecoder committed Apr 13, 2020
2 parents 4bb6cc8 + bef5f37 commit 168a172
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 316 deletions.
38 changes: 0 additions & 38 deletions controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ async function home(req, res) {
csrfToken: req.csrfToken(),
};

const coinFlipNumber = Math.random() * 100;
const experimentBranch = getExperimentBranch(req, coinFlipNumber);

const isUserInExperiment = (experimentBranch === "vb");
const experimentBranchB = (experimentBranch === "vb" && isUserInExperiment);

let featuredBreach = null;
let scanFeaturedBreach = false;

Expand Down Expand Up @@ -47,8 +41,6 @@ async function home(req, res) {
scanFeaturedBreach,
pageToken: formTokens.pageToken,
csrfToken: formTokens.csrfToken,
experimentBranch,
experimentBranchB,
});
}

Expand All @@ -58,39 +50,9 @@ async function home(req, res) {
scanFeaturedBreach,
pageToken: formTokens.pageToken,
csrfToken: formTokens.csrfToken,
experimentBranch,
isUserInExperiment,
experimentBranchB,
});
}

function getExperimentBranch(req, sorterNum) {

if (req.headers && !req.headers["accept-language"].includes("en") ){
return false;
}

// If URL param has experimentBranch entry, use that branch;
if (req.query.experimentBranch) {
if (!["va", "vb"].includes(req.query.experimentBranch)) {
return false;
}
req.session.experimentBranch = req.query.experimentBranch;
return req.query.experimentBranch;
}

// If user was already assigned a branch, stay in that branch;
if (req.session.experimentBranch) { return req.session.experimentBranch; }

// Split into two categories
if (sorterNum <= 50) {
req.session.experimentBranch = "vb";
return "vb";
}

return "va";
}

function getAllBreaches(req, res) {
return res.render("top-level-page", {
title: "Firefox Monitor",
Expand Down
25 changes: 2 additions & 23 deletions controllers/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ const sha1 = require("../sha1-utils");

const log = mozlog("controllers.oauth");

const utmArray = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];

function getUTMNames() {
return utmArray;
}

function init(req, res, next, client = FxAOAuthClient) {
// Set a random state string in a cookie so that we can verify
// the user when they're redirected back to us after auth.
Expand All @@ -28,15 +22,10 @@ function init(req, res, next, client = FxAOAuthClient) {
const url = new URL(client.code.getUri({state}));
const fxaParams = new URL(req.url, AppConstants.SERVER_URL);

req.session.utmContents = {};

url.searchParams.append("access_type", "offline");
url.searchParams.append("action", "email");

for (const param of fxaParams.searchParams.keys()) {
if (utmArray.includes(param)) {
req.session.utmContents[param] = fxaParams.searchParams.get(param);
}
url.searchParams.append(param, fxaParams.searchParams.get(param));
}

Expand Down Expand Up @@ -64,16 +53,6 @@ async function confirmed(req, res, next, client = FxAOAuthClient) {
const existingUser = await DB.getSubscriberByEmail(email);
req.session.user = existingUser;

const returnURL = new URL("/user/dashboard", AppConstants.SERVER_URL);

if (req.session.utmContents) {
getUTMNames().forEach(param => {
if (req.session.utmContents[param]) {
returnURL.searchParams.append(param, req.session.utmContents[param]);
}
});
}

// Check if user is signing up or signing in,
// then add new users to db and send email.
if (!existingUser || existingUser.fxa_refresh_token === null) {
Expand Down Expand Up @@ -112,11 +91,11 @@ async function confirmed(req, res, next, client = FxAOAuthClient) {
);
req.session.user = verifiedSubscriber;

return res.redirect(returnURL.pathname + returnURL.search);
return res.redirect("/user/dashboard");
}
// Update existing user's FxA data
await DB._updateFxAData(existingUser, fxaUser.accessToken, fxaUser.refreshToken, fxaProfileData);
res.redirect(returnURL.pathname + returnURL.search);
return res.redirect("/user/dashboard");
}

module.exports = {
Expand Down
12 changes: 2 additions & 10 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,19 +548,11 @@ async function getBreachStats(req, res) {
numBreaches: breachStats.numBreaches.count,
passwords: breachStats.passwords.count,
});
}
}


function logout(req, res) {
if (req.session.experimentBranch) {
// Persist experimentBranch across session reset
const experimentBranch = req.session.experimentBranch;
req.session.reset();
req.session.experimentBranch = experimentBranch;
} else {
req.session.reset();
}

req.session.reset();
res.redirect("/");
}

Expand Down
72 changes: 0 additions & 72 deletions public/css/experiment.css

This file was deleted.

1 change: 0 additions & 1 deletion public/img/svg/purple-check.svg

This file was deleted.

2 changes: 1 addition & 1 deletion public/js/fxa-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function sendRecommendationPings(ctaSelector) {
});


document.querySelectorAll(".open-oauth, .add-metrics-flow-values").forEach( async(el) => {
document.querySelectorAll(".open-oauth").forEach( async(el) => {
const fxaUrl = new URL("/metrics-flow?", document.body.dataset.fxaAddress);

try {
Expand Down
145 changes: 5 additions & 140 deletions public/js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@ function isValidEmail(val) {


function doOauth(el, {emailWatch = false} = {}) {
// Growth Experiment: To sidestep the breach scans form, we have to check if
// there is an email address entered into #scan-user-email form.
// If so, we set it similiar to what would happen on form submit.
//
// Options was added to limit how the watched email input field is injected
// in this function. It only moves it if options.emailWatch is set to TRUE;

let url = new URL("/oauth/init", document.body.dataset.serverUrl);
url = getFxaUtms(url);

["flowId", "flowBeginTime", "entrypoint", "entrypoint_experiment", "entrypoint_variation", "form_type"].forEach(key => {
["flowId", "flowBeginTime", "entrypoint"].forEach(key => {
if (el.dataset[key]) {
url.searchParams.append(key, encodeURIComponent(el.dataset[key]));
}
Expand All @@ -58,76 +51,15 @@ function doOauth(el, {emailWatch = false} = {}) {
return;
}

const scannedEmailId = document.querySelector("#scan-user-email input[name=scannedEmailId]");

// Preserve entire control function
if (!emailWatch) {
if (sessionStorage && sessionStorage.length > 0) {

const lastScannedEmail = sessionStorage.getItem("lastScannedEmail");
if (lastScannedEmail) {
url.searchParams.append("email", lastScannedEmail);
}
}
window.location.assign(url);
return;
}

// Growth Experiment: This logic is complex to handle the different scenarios of users logging into FxA.
let email = false;

if (document.querySelector("#scan-user-email input[type=email]")) {
email = document.querySelector("#scan-user-email input[type=email]").value;

if (!isValidEmail(email)) {
email = false;
}
}

// Growth Experiment: Reset UTMs from in-line body tag data elements.
["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content" ].forEach(key => {
if (document.body.dataset[key]) {
url.searchParams.delete(key);
url.searchParams.append(key, document.body.dataset[key]);
}
});

if (sessionStorage && sessionStorage.length > 0) {

const lastScannedEmail = sessionStorage.getItem("lastScannedEmail");

if (email && lastScannedEmail) {
switch (email) {
case lastScannedEmail:
// The last saved email address and the current entry match, so route it to FxA
email = lastScannedEmail;
break;
case !lastScannedEmail:
// The last saved email address and the current entry DIFFER, so create
// a new entry, launch a new FxA login session with new email prefilled.
sessionStorage.removeItem("lastScannedEmail");
sessionStorage.setItem("lastScannedEmail", email);
scannedEmailId.value = sessionStorage.length;
break;
}
} else {
if (lastScannedEmail) {
// Control method. User set this by checking breach results
email = lastScannedEmail;
}
const lastScannedEmail = sessionStorage.getItem(`scanned_${sessionStorage.length}`);
if (lastScannedEmail) {
url.searchParams.append("email", lastScannedEmail);
}
} else if (email && sessionStorage) {
// Applies to first time user in experiment has no previous FxA ties.
sessionStorage.removeItem("lastScannedEmail");
sessionStorage.setItem("lastScannedEmail", email);
scannedEmailId.value = sessionStorage.length;
}

// Append whichever email was set, and start OAuth flow!
if (email) {
url.searchParams.append("email", email);
}
window.location.assign(url);
return;
}


Expand Down Expand Up @@ -449,71 +381,4 @@ function addBentoObserver(){
const dropDownMenu = document.querySelector(".mobile-nav.show-mobile");
dropDownMenu.addEventListener("click", () => toggleDropDownMenu(dropDownMenu));

if (document.body.dataset.experiment) {
const submitBtn = document.querySelector("#scan-user-email input[type='submit']");
const createFxaCheckbox = document.getElementById("createFxaCheckbox");

if (createFxaCheckbox) {
createFxaCheckbox.addEventListener("change", (e)=> {
document.body.dataset.utm_content = "opt-out";
if (event.target.checked) {
document.body.dataset.utm_content = "opt-in";
}
});
}

submitBtn.addEventListener("click", (e)=> {
document.body.dataset.utm_content = "opt-out";

// Email Validation
const scanForm = document.getElementById("scan-user-email");
const scanFormEmailValue = document.querySelector("#scan-user-email input[type='email']").value;

if (scanFormEmailValue.length < 1 || !isValidEmail(scanFormEmailValue)) {
scanForm.classList.add("invalid");
return;
}

if (createFxaCheckbox && createFxaCheckbox.checked) {
// Applies only to Branches VB and VC, if the checkbox is CHECKED.
e.preventDefault();

// Analytics
document.body.dataset.utm_content = "opt-in";
e.target.dataset.entrypoint = "fx-monitor-alert-me-blue-link";
if (typeof(ga) !== "undefined") {
ga("send", {
hitType: "event",
eventCategory: "growthuserflow1",
eventAction: "opt-in",
eventLabel: "fx-monitor-alert-me-blue-link",
});
}

doOauth(e.target, {emailWatch: true});
return;
}

const scanFormActionURL = new URL(scanForm.action);

["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content" ].forEach(key => {
if (document.body.dataset[key]) {
scanFormActionURL.searchParams.append(key, document.body.dataset[key]);
}
});

const revisedActionURL = scanFormActionURL.pathname + scanFormActionURL.search;

scanForm.action = revisedActionURL;

if (typeof(ga) !== "undefined") {
ga("send", {
hitType: "event",
eventCategory: "growthuserflow1",
eventAction: "opt-out",
eventLabel: "fx-monitor-alert-me-blue-link",
});
}
});
}
})();
Loading

0 comments on commit 168a172

Please sign in to comment.