Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NT-484] Tracking event for Cancel Pledge #917

Merged
merged 6 commits into from
Oct 29, 2019
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
7 changes: 7 additions & 0 deletions Library/Koala/Koala.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,13 @@ public final class Koala {
}
}

public func trackCancelPledgeButtonClicked(project: Project, backing: Backing) {
let props = properties(project: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(["pledge_total": backing.amount])

self.track(event: "Cancel Pledge Button Clicked", properties: props)
}

public func trackSelectRewardButtonClicked(
project: Project,
reward: Reward?,
Expand Down
13 changes: 13 additions & 0 deletions Library/Koala/KoalaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,17 @@ final class KoalaTests: TestCase {
XCTAssertEqual(["Select Reward Button Clicked"], client.events)
XCTAssertEqual("Back this page", properties?["screen"] as? String)
}

func testTrackCancelPledgeButtonClicked() {
let client = MockTrackingClient()
let loggedInUser = User.template

let koala = Koala(client: client, loggedInUser: loggedInUser)

koala.trackCancelPledgeButtonClicked(
project: .template,
backing: .template
)
XCTAssertEqual(["Cancel Pledge Button Clicked"], client.events)
}
}
13 changes: 13 additions & 0 deletions Library/ViewModels/CancelPledgeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public final class CancelPledgeViewModel: CancelPledgeViewModelType, CancelPledg
)
.map(first)

let project = initialData
.map(first)
let backing = initialData
.map(second)

let projectAndBacking = Signal.combineLatest(project, backing)

self.cancellationDetailsAttributedText = Signal.merge(
initialData,
initialData.takeWhen(self.traitCollectionDidChangeProperty.signal)
Expand Down Expand Up @@ -93,6 +97,15 @@ public final class CancelPledgeViewModel: CancelPledgeViewModelType, CancelPledg
cancelPledgeEvent.map { $0.isTerminating }.mapConst(true)
)
.skipRepeats()

// Tracking
projectAndBacking
.takeWhen(self.cancelPledgeButtonTappedProperty.signal)
.observeValues { AppEnvironment.current.koala.trackCancelPledgeButtonClicked(
project: $0,
backing: $1
)
}
}

private let cancelPledgeButtonTappedProperty = MutableProperty(())
Expand Down
15 changes: 15 additions & 0 deletions Library/ViewModels/CancelPledgeViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,19 @@ final class CancelPledgeViewModelTests: TestCase {
self.cancelPledgeError.assertValues(["You can't cancel your pledge right now."])
}
}

func testTrackingEvents() {
let mockService = MockService(cancelBackingResult: .init(success: .init()))

withEnvironment(apiService: mockService) {
self.vm.inputs.configure(with: .template, backing: .template)
self.vm.inputs.viewDidLoad()

XCTAssertEqual([], self.trackingClient.events)

self.vm.inputs.cancelPledgeButtonTapped()

XCTAssertEqual(["Cancel Pledge Button Clicked"], self.trackingClient.events)
}
}
}