Skip to content

Commit

Permalink
Merge pull request #18125 from wordpress-mobile/issue/17873-ab-test-d…
Browse files Browse the repository at this point in the history
…ashboard-site-creation-flow

My Site Dashboard: add AB test after site creation and option to change the default in Settings
  • Loading branch information
leandroalonso authored Mar 14, 2022
2 parents 9705ece + 9297cea commit 1406b80
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
3 changes: 3 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ import Foundation

// App Settings
case settingsDidChange
case initialScreenChanged

// Account Close
case accountCloseTapped
Expand Down Expand Up @@ -744,6 +745,8 @@ import Foundation
// App Settings
case .settingsDidChange:
return "settings_did_change"
case .initialScreenChanged:
return "app_settings_initial_screen_changed"
case .appSettingsClearMediaCacheTapped:
return "app_settings_clear_media_cache_tapped"
case .appSettingsClearSpotlightIndexTapped:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Foundation

class BlogDashboardAB {
static let shared = BlogDashboardAB()

enum Variant {
case control
case treatment
}

private let accountService: AccountService

public var variant: Variant {
calculateVariant()
}

private init(accountService: AccountService = AccountService(managedObjectContext: ContextManager.sharedInstance().mainContext)) {
self.accountService = accountService
}

private func calculateVariant() -> Variant {
let defaultAccount = accountService.defaultWordPressComAccount()
let token: String? = defaultAccount?.authToken

if let token = token {
return token.hashCode() % 2 == 0 ? .control : .treatment
} else {
return .control
}
}
}

private extension String {
var asciiArray: [UInt32] {
return unicodeScalars
.filter { $0.isASCII }
.map { $0.value }
}

func hashCode() -> Int32 {
var h: Int32 = 0
for i in self.asciiArray {
h = 31 &* h &+ Int32(i)
}
return h
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,37 @@ class AppSettingsViewController: UITableViewController {
WPTabBarController.sharedInstance().presentWhatIsNew(on: self)
}
}

func pushInitialScreenSettings() -> ImmuTableAction {
return { [weak self] row in
let values = MySiteViewController.Section.allCases

let rawValues = values.map({ $0.rawValue })
let titles = values.map({ $0.title })

let currentStyle = MySiteSettings().defaultSection

let settingsSelectionConfiguration = [SettingsSelectionDefaultValueKey: AppAppearance.default.rawValue,
SettingsSelectionCurrentValueKey: currentStyle.rawValue,
SettingsSelectionTitleKey: NSLocalizedString("Initial Screen", comment: "The title of the app initial screen settings screen"),
SettingsSelectionTitlesKey: titles,
SettingsSelectionValuesKey: rawValues] as [String: Any]

let viewController = SettingsSelectionViewController(dictionary: settingsSelectionConfiguration)

viewController?.onItemSelected = { (section: Any!) -> () in
guard let section = section as? Int,
let defaultSection = MySiteViewController.Section(rawValue: section) else {
return
}

WPAnalytics.track(.initialScreenChanged, properties: ["selected": defaultSection.analyticsDescription])
MySiteSettings().setDefaultSection(defaultSection)
}

self?.navigationController?.pushViewController(viewController!, animated: true)
}
}
}

// MARK: - SearchableActivity Conformance
Expand Down Expand Up @@ -497,6 +528,12 @@ private extension AppSettingsViewController {
rows.insert(iconRow, at: 0)
}

if FeatureFlag.mySiteDashboard.enabled {
let initialScreen = NavigationItemRow(title: NSLocalizedString("Initial Screen", comment: "Title of the option to change the default initial screen"), detail: MySiteSettings().defaultSection.title, action: pushInitialScreenSettings())

rows.append(initialScreen)
}

if FeatureFlag.debugMenu.enabled {
rows.append(debugRow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ final class SiteAssemblyWizardContent: UIViewController {
gutenbergSettings.postSettingsToRemote(for: createdBlog)
}

if FeatureFlag.mySiteDashboard.enabled {
// TODO: A/B test default section
if FeatureFlag.mySiteDashboard.enabled,
BlogDashboardAB.shared.variant == .treatment {
MySiteSettings().setDefaultSection(.dashboard)
}

Expand Down
6 changes: 6 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,8 @@
8BDC4C39249BA5CA00DE0A2D /* ReaderCSS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BDC4C38249BA5CA00DE0A2D /* ReaderCSS.swift */; };
8BE69512243E674300FF492F /* PrepublishingHeaderViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BE69511243E674300FF492F /* PrepublishingHeaderViewTests.swift */; };
8BE7C84123466927006EDE70 /* I18n.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BE7C84023466927006EDE70 /* I18n.swift */; };
8BE8545D27DBAFED00E4C69A /* BlogDashboardAB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BE8545C27DBAFED00E4C69A /* BlogDashboardAB.swift */; };
8BE8545E27DBAFED00E4C69A /* BlogDashboardAB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BE8545C27DBAFED00E4C69A /* BlogDashboardAB.swift */; };
8BE9AB8827B6B5A300708E45 /* BlogDashboardPersistenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BE9AB8727B6B5A300708E45 /* BlogDashboardPersistenceTests.swift */; };
8BEE845A27B1DC9D0001A93C /* dashboard-200-with-drafts-and-scheduled.json in Resources */ = {isa = PBXBuildFile; fileRef = 8BEE845927B1DC9D0001A93C /* dashboard-200-with-drafts-and-scheduled.json */; };
8BEE846227B1E0540001A93C /* DashboardCardSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BEE845E27B1DE040001A93C /* DashboardCardSection.swift */; };
Expand Down Expand Up @@ -6190,6 +6192,7 @@
8BDC4C38249BA5CA00DE0A2D /* ReaderCSS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderCSS.swift; sourceTree = "<group>"; };
8BE69511243E674300FF492F /* PrepublishingHeaderViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PrepublishingHeaderViewTests.swift; path = WordPressTest/PrepublishingHeaderViewTests.swift; sourceTree = SOURCE_ROOT; };
8BE7C84023466927006EDE70 /* I18n.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = I18n.swift; sourceTree = "<group>"; };
8BE8545C27DBAFED00E4C69A /* BlogDashboardAB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDashboardAB.swift; sourceTree = "<group>"; };
8BE9AB8727B6B5A300708E45 /* BlogDashboardPersistenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDashboardPersistenceTests.swift; sourceTree = "<group>"; };
8BEE845927B1DC9D0001A93C /* dashboard-200-with-drafts-and-scheduled.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "dashboard-200-with-drafts-and-scheduled.json"; sourceTree = "<group>"; };
8BEE845E27B1DE040001A93C /* DashboardCardSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardCardSection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11536,6 +11539,7 @@
isa = PBXGroup;
children = (
8BC81D6427CFC0DA0057F790 /* BlogDashboardState.swift */,
8BE8545C27DBAFED00E4C69A /* BlogDashboardAB.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -18668,6 +18672,7 @@
822876F11E929CFD00696BF7 /* ReachabilityUtils+OnlineActions.swift in Sources */,
E15632CC1EB9ECF40035A099 /* TableViewKeyboardObserver.swift in Sources */,
E1A03F48174283E10085D192 /* BlogToJetpackAccount.m in Sources */,
8BE8545D27DBAFED00E4C69A /* BlogDashboardAB.swift in Sources */,
B522C4F81B3DA79B00E47B59 /* NotificationSettingsViewController.swift in Sources */,
93E63369272AC532009DACF8 /* LoginEpilogueChooseSiteTableViewCell.swift in Sources */,
9A51DA1522E9E8C7005CC335 /* ChangeUsernameViewController.swift in Sources */,
Expand Down Expand Up @@ -20604,6 +20609,7 @@
8BAC9D9F27BAB97E008EA44C /* BlogDashboardRemoteEntity.swift in Sources */,
FABB24612602FC2C00C8785C /* KeyringAccountHelper.swift in Sources */,
FABB24622602FC2C00C8785C /* ManagedAccountSettings+CoreDataProperties.swift in Sources */,
8BE8545E27DBAFED00E4C69A /* BlogDashboardAB.swift in Sources */,
FABB24632602FC2C00C8785C /* PushAuthenticationService.swift in Sources */,
FABB24642602FC2C00C8785C /* AlertView.swift in Sources */,
FABB24652602FC2C00C8785C /* WPTabBarController.m in Sources */,
Expand Down

0 comments on commit 1406b80

Please sign in to comment.