Skip to content

Commit

Permalink
[NT-773] Additional Login Flow Events (#1031)
Browse files Browse the repository at this point in the history
* Adding additional login flow tracking events

* Add “Forgot Password Viewed” and “Two-Factor Confirmation Viewed” Events plus more tracking tests

* Formatting
  • Loading branch information
Isabel Barrera committed Jan 15, 2020
1 parent 7d0bb76 commit 276918a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Library/Tracking/Koala.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Koala {
case signupButtonClicked = "Signup Button Clicked"
case loginSubmitButtonClicked = "Log In Submit Button Clicked"
case signupSubmitButtonClicked = "Signup Submit Button Clicked"
case forgotPasswordViewed = "Forgot Password Viewed"
case twoFactorConfirmationViewed = "Two-Factor Confirmation Viewed"

static func allWhiteListedEvents() -> [String] {
return DataLakeWhiteListedEvent.allCases.map { $0.rawValue }
Expand Down Expand Up @@ -867,11 +869,16 @@ public final class Koala {
*/

public func trackSignupButtonClicked(
intent _: LoginIntent,
project _: Project? = nil,
reward _: Reward? = nil
intent: LoginIntent,
project: Project? = nil,
reward: Reward? = nil
) {
self.track(event: DataLakeWhiteListedEvent.signupButtonClicked.rawValue)
let props = self.loginEventProperties(for: intent, project: project, reward: reward)

self.track(
event: DataLakeWhiteListedEvent.signupButtonClicked.rawValue,
properties: props
)
}

public func trackSignupSubmitButtonClicked() {
Expand All @@ -882,6 +889,14 @@ public final class Koala {
self.track(event: DataLakeWhiteListedEvent.loginSubmitButtonClicked.rawValue)
}

public func trackForgotPasswordViewed() {
self.track(event: DataLakeWhiteListedEvent.forgotPasswordViewed.rawValue)
}

public func track2FAViewed() {
self.track(event: DataLakeWhiteListedEvent.twoFactorConfirmationViewed.rawValue)
}

private func loginEventProperties(for intent: LoginIntent, project: Project?, reward: Reward?)
-> [String: Any] {
var props: [String: Any] = [:]
Expand Down
38 changes: 38 additions & 0 deletions Library/ViewModels/LoginToutViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,55 @@ final class LoginToutViewModelTests: TestCase {
}

func testStartLogin() {
self.vm.inputs.configureWith(.activity, project: nil, reward: nil)
self.vm.inputs.viewWillAppear()
self.vm.inputs.loginButtonPressed()

self.startLogin.assertValueCount(1, "Start login emitted")

XCTAssertEqual(["Log In or Signup Page Viewed", "Log In Button Clicked"], self.trackingClient.events)
XCTAssertEqual(["activity", "activity"], self.trackingClient.properties(forKey: "login_intent"))
XCTAssertEqual([nil, nil], self.trackingClient.properties(forKey: "project_pid"))
XCTAssertEqual([nil, nil], self.trackingClient.properties(forKey: "pledge_backer_reward_id"))
}

func testStartLogin_PledgeIntent() {
self.vm.inputs.configureWith(.backProject, project: .template, reward: .template)
self.vm.inputs.viewWillAppear()
self.vm.inputs.loginButtonPressed()

self.startLogin.assertValueCount(1)

XCTAssertEqual(["Log In or Signup Page Viewed", "Log In Button Clicked"], self.trackingClient.events)
XCTAssertEqual(["pledge", "pledge"], self.trackingClient.properties(forKey: "login_intent"))
XCTAssertEqual([1, 1], self.trackingClient.properties(forKey: "project_pid", as: Int.self))
XCTAssertEqual([1, 1], self.trackingClient.properties(forKey: "pledge_backer_reward_id", as: Int.self))
}

func testStartSignup() {
self.vm.inputs.configureWith(.activity, project: nil, reward: nil)
self.vm.inputs.viewWillAppear()
self.vm.inputs.signupButtonPressed()

self.startSignup.assertValueCount(1, "Start sign up emitted")

XCTAssertEqual(["Log In or Signup Page Viewed", "Signup Button Clicked"], self.trackingClient.events)
XCTAssertEqual(["activity", "activity"], self.trackingClient.properties(forKey: "login_intent"))
XCTAssertEqual([nil, nil], self.trackingClient.properties(forKey: "project_pid"))
XCTAssertEqual([nil, nil], self.trackingClient.properties(forKey: "pledge_backer_reward_id"))
}

func testStartSignup_PledgeIntent() {
self.vm.inputs.configureWith(.backProject, project: .template, reward: .template)
self.vm.inputs.viewWillAppear()
self.vm.inputs.signupButtonPressed()

self.startSignup.assertValueCount(1)

XCTAssertEqual(["Log In or Signup Page Viewed", "Signup Button Clicked"], self.trackingClient.events)
XCTAssertEqual(["pledge", "pledge"], self.trackingClient.properties(forKey: "login_intent"))
XCTAssertEqual([1, 1], self.trackingClient.properties(forKey: "project_pid", as: Int.self))
XCTAssertEqual([1, 1], self.trackingClient.properties(forKey: "pledge_backer_reward_id", as: Int.self))
}

func testHeadlineLabelHidden() {
Expand Down
3 changes: 3 additions & 0 deletions Library/ViewModels/ResetPasswordViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public final class ResetPasswordViewModel: ResetPasswordViewModelType, ResetPass
}

self.returnToLogin = self.confirmResetButtonPressedProperty.signal

self.viewDidLoadProperty.signal
.observeValues { AppEnvironment.current.koala.trackForgotPasswordViewed() }
}

fileprivate let viewDidLoadProperty = MutableProperty(())
Expand Down
6 changes: 6 additions & 0 deletions Library/ViewModels/ResetPasswordViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@ final class ResetPasswordViewModelTests: TestCase {
self.showError.assertValues(["Something went wrong."], "Error alert is shown on bad request")
}
}

func testTracking() {
self.vm.inputs.viewDidLoad()

XCTAssertEqual(["Forgot Password Viewed"], self.trackingClient.events)
}
}
3 changes: 3 additions & 0 deletions Library/ViewModels/TwoFactorViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public final class TwoFactorViewModel: TwoFactorViewModelType, TwoFactorViewMode
userInfo: [UserInfoKeys.context: PushNotificationDialog.Context.login]
)
))

self.viewDidLoadProperty.signal
.observeValues { AppEnvironment.current.koala.track2FAViewed() }
}

fileprivate let codeProperty = MutableProperty<String?>(nil)
Expand Down
7 changes: 7 additions & 0 deletions Library/ViewModels/TwoFactorViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,11 @@ final class TwoFactorViewModelTests: TestCase {
resendSuccess.assertValueCount(0, "Code was not resent")
}
}

func testTracking() {
self.vm.inputs.viewDidLoad()
self.vm.inputs.viewWillAppear()

XCTAssertEqual(["Two-Factor Confirmation Viewed"], self.trackingClient.events)
}
}

0 comments on commit 276918a

Please sign in to comment.