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

fix return user segmentation #3387

Merged
merged 1 commit into from
Sep 24, 2024
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
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
Loading