Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit e60259f

Browse files
committed
fix return usage segment
1 parent 691d8af commit e60259f

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

Core/ReturnUserMeasurement.swift

+4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
import Foundation
2121
import BrowserServicesKit
2222

23+
/// This is only intended to be used during the install (first run after downloading from the app store).
2324
protocol ReturnUserMeasurement {
2425

26+
/// Based on the value in the keychain, so if you use this after the install process it will return true.
27+
/// If you really want to know if the user is "returning" then look at the variant in the `StatisticsStore`
28+
/// which will be set to `ru`.
2529
var isReturningUser: Bool { get }
2630
func installCompletedWithATB(_ atb: Atb)
2731
func updateStoredATB(_ atb: Atb)

Core/StatisticsLoader.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ public class StatisticsLoader {
155155

156156
private func processUsageSegmentation(atb: Atb?, activityType: UsageActivityType) {
157157
guard let installAtbValue = statisticsStore.atb else { return }
158-
let installAtb = Atb(version: installAtbValue, updateVersion: nil)
159-
let actualAtb = atb ?? installAtb
160-
self.usageSegmentation.processATB(actualAtb, withInstallAtb: installAtb, andActivityType: activityType)
158+
let installAtb = Atb(version: installAtbValue + (statisticsStore.variant ?? ""), updateVersion: nil)
159+
let usageAtb = atb ?? installAtb
160+
161+
self.usageSegmentation.processATB(usageAtb, withInstallAtb: installAtb, andActivityType: activityType)
161162
}
162163

163164
private func updateUsageSegmentationWithAtb(_ atb: Atb, activityType: UsageActivityType) {

DuckDuckGoTests/StatisticsLoaderTests.swift

+28
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ class StatisticsLoaderTests: XCTestCase {
4242
super.tearDown()
4343
}
4444

45+
func testWhenAppRefreshHappensButNotInstalledAndReturningUser_ThenRetentionSegmentationNotified() {
46+
mockStatisticsStore.variant = "ru"
47+
mockStatisticsStore.atb = "v101-1"
48+
49+
loadSuccessfulExiStub()
50+
51+
let testExpectation = expectation(description: "refresh complete")
52+
testee.refreshAppRetentionAtb {
53+
testExpectation.fulfill()
54+
}
55+
wait(for: [testExpectation], timeout: 5.0)
56+
XCTAssertTrue(mockUsageSegmentation.atbs[0].installAtb.isReturningUser)
57+
}
58+
59+
func testWhenReturnUser_ThenSegmentationIncludesCorrectVariant() {
60+
mockStatisticsStore.variant = "ru"
61+
mockStatisticsStore.atb = "v101-1"
62+
mockStatisticsStore.searchRetentionAtb = "v101-2"
63+
loadSuccessfulAtbStub()
64+
65+
let testExpectation = expectation(description: "refresh complete")
66+
testee.refreshSearchRetentionAtb {
67+
testExpectation.fulfill()
68+
}
69+
wait(for: [testExpectation], timeout: 5.0)
70+
XCTAssertTrue(mockUsageSegmentation.atbs[0].installAtb.isReturningUser)
71+
}
72+
4573
func testWhenSearchRefreshHappensButNotInstalled_ThenRetentionSegmentationNotified() {
4674
loadSuccessfulExiStub()
4775

0 commit comments

Comments
 (0)