Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extension WooAnalyticsEvent {
private enum Key {
static let scenario = "scenario"
static let cause = "cause"
static let experimentVariant = "experiment_variant"
}

enum Scenario: String {
Expand All @@ -19,6 +20,13 @@ extension WooAnalyticsEvent {
case other = "other"
}

/// Tracks the REST API A/B test variation
///
static func restAPILoginExperiment(variation: String) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .trackRestAPILoginExperimentVariation,
properties: [Key.experimentVariant: variation])
}

/// Tracks when generating application password succeeds
///
static func applicationPasswordGeneratedSuccessfully(scenario: Scenario) -> WooAnalyticsEvent {
Expand Down
1 change: 1 addition & 0 deletions WooCommerce/Classes/Analytics/WooAnalyticsStat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ public enum WooAnalyticsStat: String {
// MARK: Application password Events
case applicationPasswordsNewPasswordCreated = "application_passwords_new_password_created"
case applicationPasswordsGenerationFailed = "application_passwords_generation_failed"
case trackRestAPILoginExperimentVariation = "rest_api_login_experiment"
}

public extension WooAnalyticsStat {
Expand Down
2 changes: 2 additions & 0 deletions WooCommerce/Classes/ViewRelated/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ private extension AppCoordinator {
} else {
configureAndDisplayAuthenticator()
}

analytics.track(event: .ApplicationPassword.restAPILoginExperiment(variation: ABTest.applicationPasswordAuthentication.variation.analyticsValue))
}

/// Configures the WPAuthenticator and sets the authenticator UI as the window's root view.
Expand Down
50 changes: 38 additions & 12 deletions WooCommerce/WooCommerceTests/AppCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,25 @@ final class AppCoordinatorTests: XCTestCase {
appCoordinator.start()

// Then
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginOnboardingShown.rawValue])
_ = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == WooAnalyticsStat.loginOnboardingShown.rawValue}))
}

func test_trackRestAPILoginExperimentVariation_is_tracked_after_presenting_onboarding() throws {
// Given
stores.deauthenticate()
let analytics = MockAnalyticsProvider()
let appCoordinator = makeCoordinator(window: window,
stores: stores,
authenticationManager: authenticationManager,
analytics: WooAnalytics(analyticsProvider: analytics))

// When
appCoordinator.start()

// Then
let indexOfEvent = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == "rest_api_login_experiment" }))
let eventProperties = try XCTUnwrap(analytics.receivedProperties[indexOfEvent])
XCTAssertNotNil(eventProperties["experiment_variant"] as? String)
}

// MARK: - Login reminder analytics
Expand All @@ -340,10 +358,12 @@ final class AppCoordinatorTests: XCTestCase {
pushNotesManager.sendLocalNotificationResponse(response)

// Then
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginLocalNotificationTapped.rawValue])
let actionPropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["action"] as? String)
let indexOfEvent = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == WooAnalyticsStat.loginLocalNotificationTapped.rawValue}))
let eventProperties = try XCTUnwrap(analytics.receivedProperties[indexOfEvent])

let actionPropertyValue = try XCTUnwrap(eventProperties["action"] as? String)
XCTAssertEqual(actionPropertyValue, "contact_support")
let typePropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["type"] as? String)
let typePropertyValue = try XCTUnwrap(eventProperties["type"] as? String)
XCTAssertEqual(typePropertyValue, "site_address_error")
}

Expand All @@ -364,10 +384,12 @@ final class AppCoordinatorTests: XCTestCase {
pushNotesManager.sendLocalNotificationResponse(response)

// Then
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginLocalNotificationTapped.rawValue])
let actionPropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["action"] as? String)
let indexOfEvent = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == WooAnalyticsStat.loginLocalNotificationTapped.rawValue}))
let eventProperties = try XCTUnwrap(analytics.receivedProperties[indexOfEvent])

let actionPropertyValue = try XCTUnwrap(eventProperties["action"] as? String)
XCTAssertEqual(actionPropertyValue, "login_with_wpcom")
let typePropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["type"] as? String)
let typePropertyValue = try XCTUnwrap(eventProperties["type"] as? String)
XCTAssertEqual(typePropertyValue, "site_address_error")
}

Expand All @@ -388,10 +410,12 @@ final class AppCoordinatorTests: XCTestCase {
pushNotesManager.sendLocalNotificationResponse(response)

// Then
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginLocalNotificationTapped.rawValue])
let actionPropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["action"] as? String)
let indexOfEvent = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == WooAnalyticsStat.loginLocalNotificationTapped.rawValue}))
let eventProperties = try XCTUnwrap(analytics.receivedProperties[indexOfEvent])

let actionPropertyValue = try XCTUnwrap(eventProperties["action"] as? String)
XCTAssertEqual(actionPropertyValue, "default")
let typePropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["type"] as? String)
let typePropertyValue = try XCTUnwrap(eventProperties["type"] as? String)
XCTAssertEqual(typePropertyValue, "site_address_error")
}

Expand All @@ -412,8 +436,10 @@ final class AppCoordinatorTests: XCTestCase {
pushNotesManager.sendLocalNotificationResponse(response)

// Then
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginLocalNotificationDismissed.rawValue])
let typePropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["type"] as? String)
let indexOfEvent = try XCTUnwrap(analytics.receivedEvents.firstIndex(where: { $0 == WooAnalyticsStat.loginLocalNotificationDismissed.rawValue}))
let eventProperties = try XCTUnwrap(analytics.receivedProperties[indexOfEvent])

let typePropertyValue = try XCTUnwrap(eventProperties["type"] as? String)
XCTAssertEqual(typePropertyValue, "site_address_error")
}
}
Expand Down