Skip to content

Commit

Permalink
Fix #6216 - AA Leanplum show onboarding intro test setup (#6257)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhasin2 committed Mar 11, 2020
1 parent 25efa28 commit bacc7b5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Client.xcodeproj/project.pbxproj
Expand Up @@ -258,6 +258,7 @@
43446CEA2412066500F5C643 /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43446CE92412066500F5C643 /* UIViewControllerExtension.swift */; };
43446CF02412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43446CEF2412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift */; };
43446CF32412F9FF00F5C643 /* ETPCoverSheetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43446CF22412F9FF00F5C643 /* ETPCoverSheetTests.swift */; };
434F97F424196B4300812FDF /* OnboardingUserResearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 434F97F224196B4200812FDF /* OnboardingUserResearch.swift */; };
435D660323D793DF0046EFA2 /* UpdateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435D660223D793DF0046EFA2 /* UpdateModel.swift */; };
435D660523D794B90046EFA2 /* UpdateViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435D660423D794B90046EFA2 /* UpdateViewModel.swift */; };
435D660723D7962C0046EFA2 /* UpdateCoverSheetTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435D660623D7962C0046EFA2 /* UpdateCoverSheetTableViewCell.swift */; };
Expand Down Expand Up @@ -1404,6 +1405,7 @@
43446CE92412066500F5C643 /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIViewControllerExtension.swift; path = Extensions/UIViewControllerExtension.swift; sourceTree = "<group>"; };
43446CEF2412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateCoverSheetViewModelTests.swift; sourceTree = "<group>"; };
43446CF22412F9FF00F5C643 /* ETPCoverSheetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ETPCoverSheetTests.swift; sourceTree = "<group>"; };
434F97F224196B4200812FDF /* OnboardingUserResearch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingUserResearch.swift; sourceTree = "<group>"; };
435D660223D793DF0046EFA2 /* UpdateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateModel.swift; sourceTree = "<group>"; };
435D660423D794B90046EFA2 /* UpdateViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateViewModel.swift; sourceTree = "<group>"; };
435D660623D7962C0046EFA2 /* UpdateCoverSheetTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateCoverSheetTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2623,6 +2625,14 @@
path = ETPCoverSheet;
sourceTree = "<group>";
};
434F97F124196B4200812FDF /* UserResearch */ = {
isa = PBXGroup;
children = (
434F97F224196B4200812FDF /* OnboardingUserResearch.swift */,
);
path = UserResearch;
sourceTree = "<group>";
};
43A5643423CD1E1B00B6857D /* Update */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3451,6 +3461,7 @@
28EADE5C1AFC3A6D007FB2FB /* Extensions */,
F84B21F11A0910F600AAB793 /* Frontend */,
39A359BD1BFCCE7B006B9E87 /* Helpers */,
434F97F124196B4200812FDF /* UserResearch */,
E69DB0B91E97E301008A67E6 /* Telemetry */,
E65075551E37F714006961AC /* Utils */,
74821FFD1DB6D3AC00EEEA72 /* MailSchemes.plist */,
Expand Down Expand Up @@ -5085,6 +5096,7 @@
43446CEA2412066500F5C643 /* UIViewControllerExtension.swift in Sources */,
D301AAEE1A3A55B70078DD1D /* TabTrayController.swift in Sources */,
EB9A179B20E69A7F00B12184 /* ThemeManager.swift in Sources */,
434F97F424196B4300812FDF /* OnboardingUserResearch.swift in Sources */,
EBFDB790211C83A5005CCA2F /* BrowserViewController+FindInPage.swift in Sources */,
EBB89509219398E500EB91A0 /* TabContentBlocker+ContentScript.swift in Sources */,
D3BE7B461B054F8600641031 /* TestAppDelegate.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion Client/Application/AppDelegate.swift
Expand Up @@ -225,7 +225,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
// button will be in the incorrect position and overlap with the input text. Not clear if
// that is an iOS bug or not.
AutocompleteTextField.appearance().semanticContentAttribute = .forceLeftToRight

// Leanplum usersearch variable setup for onboarding research
_ = OnboardingUserResearch()
// Leanplum setup
if let profile = self.profile, LeanPlumClient.shouldEnable(profile: profile) {
LeanPlumClient.shared.setup(profile: profile)
LeanPlumClient.shared.set(enabled: true)
Expand Down
15 changes: 13 additions & 2 deletions Client/Frontend/Browser/BrowserViewController.swift
Expand Up @@ -51,7 +51,7 @@ class BrowserViewController: UIViewController {
fileprivate var searchLoader: SearchLoader?
let alertStackView = UIStackView() // All content that appears above the footer should be added to this view. (Find In Page/SnackBars)
var findInPageBar: FindInPageBar?

private var onboardingUserResearch: OnboardingUserResearch?
lazy var mailtoLinkHandler = MailtoLinkHandler()

fileprivate var customSearchBarButton: UIBarButtonItem?
Expand Down Expand Up @@ -452,6 +452,10 @@ class BrowserViewController: UIViewController {
}

NotificationCenter.default.addObserver(self, selector: #selector(self.appMenuBadgeUpdate), name: .FirefoxAccountStateChange, object: nil)

// Setup onboarding user research for A/A testing
onboardingUserResearch = OnboardingUserResearch()
onboardingUserResearch?.lpVariableObserver()
}

fileprivate func setupConstraints() {
Expand Down Expand Up @@ -1898,6 +1902,7 @@ extension BrowserViewController: UIAdaptivePresentationControllerDelegate {

extension BrowserViewController: IntroViewControllerDelegate {
@discardableResult func presentIntroViewController(_ force: Bool = false, animated: Bool = true) -> Bool {
onboardingUserResearchHelper()
if let deeplink = self.profile.prefs.stringForKey("AdjustDeeplinkKey"), let url = URL(string: deeplink) {
self.launchFxAFromDeeplinkURL(url)
return true
Expand Down Expand Up @@ -1996,6 +2001,13 @@ extension BrowserViewController: IntroViewControllerDelegate {

return false
}

func onboardingUserResearchHelper() {
print("lp initial value \(String(describing: onboardingUserResearch?.lpVariable?.boolValue()))")
onboardingUserResearch?.updatedLPVariables = {(lpVariable) -> () in
print("lpVariable \(String(describing: lpVariable?.boolValue()))")
}
}

func launchFxAFromDeeplinkURL(_ url: URL) {
self.profile.prefs.removeObjectForKey("AdjustDeeplinkKey")
Expand All @@ -2008,7 +2020,6 @@ extension BrowserViewController: IntroViewControllerDelegate {

func introViewControllerDidFinish(_ introViewController: IntroViewController, showLoginFlow: FxALoginFlow?) {
self.profile.prefs.setInt(1, forKey: PrefsKeys.IntroSeen)

introViewController.dismiss(animated: true) {
if self.navigationController?.viewControllers.count ?? 0 > 1 {
_ = self.navigationController?.popToRootViewController(animated: true)
Expand Down
28 changes: 28 additions & 0 deletions Client/UserResearch/OnboardingUserResearch.swift
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import Leanplum

struct LPVariables {
static var showOnboardingScreen = LPVar.define("showOnboardingScreen", with: true)
}

class OnboardingUserResearch {
// Delegate closure
var updatedLPVariables: ((LPVar?) -> Void)?
// variable
var lpVariable: LPVar?

// Initializer
init(lpVariable: LPVar? = LPVariables.showOnboardingScreen) {
self.lpVariable = lpVariable
}

func lpVariableObserver() {
Leanplum.onVariablesChanged {
self.updatedLPVariables?(self.lpVariable)
}
}
}

0 comments on commit bacc7b5

Please sign in to comment.