Skip to content

Commit

Permalink
fix return usage segment
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Sep 24, 2024
1 parent 691d8af commit e60259f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Core/ReturnUserMeasurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
import Foundation
import BrowserServicesKit

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

/// Based on the value in the keychain, so if you use this after the install process it will return true.
/// If you really want to know if the user is "returning" then look at the variant in the `StatisticsStore`
/// which will be set to `ru`.
var isReturningUser: Bool { get }
func installCompletedWithATB(_ atb: Atb)
func updateStoredATB(_ atb: Atb)
Expand Down
7 changes: 4 additions & 3 deletions Core/StatisticsLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ public class StatisticsLoader {

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

self.usageSegmentation.processATB(usageAtb, withInstallAtb: installAtb, andActivityType: activityType)
}

private func updateUsageSegmentationWithAtb(_ atb: Atb, activityType: UsageActivityType) {
Expand Down
28 changes: 28 additions & 0 deletions DuckDuckGoTests/StatisticsLoaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ class StatisticsLoaderTests: XCTestCase {
super.tearDown()
}

func testWhenAppRefreshHappensButNotInstalledAndReturningUser_ThenRetentionSegmentationNotified() {
mockStatisticsStore.variant = "ru"
mockStatisticsStore.atb = "v101-1"

loadSuccessfulExiStub()

let testExpectation = expectation(description: "refresh complete")
testee.refreshAppRetentionAtb {
testExpectation.fulfill()
}
wait(for: [testExpectation], timeout: 5.0)
XCTAssertTrue(mockUsageSegmentation.atbs[0].installAtb.isReturningUser)
}

func testWhenReturnUser_ThenSegmentationIncludesCorrectVariant() {
mockStatisticsStore.variant = "ru"
mockStatisticsStore.atb = "v101-1"
mockStatisticsStore.searchRetentionAtb = "v101-2"
loadSuccessfulAtbStub()

let testExpectation = expectation(description: "refresh complete")
testee.refreshSearchRetentionAtb {
testExpectation.fulfill()
}
wait(for: [testExpectation], timeout: 5.0)
XCTAssertTrue(mockUsageSegmentation.atbs[0].installAtb.isReturningUser)
}

func testWhenSearchRefreshHappensButNotInstalled_ThenRetentionSegmentationNotified() {
loadSuccessfulExiStub()

Expand Down

0 comments on commit e60259f

Please sign in to comment.