Files
purchases-ios/Sources/Checkpoints/CheckpointEvent.swift
T
Facundo MenzellaandClaude Opus 5 b969826845 Track checkpoint hits through the analytics events pipeline (#7447)
* feat(checkpoints): send checkpoint hits through the analytics events pipeline

Hitting a checkpoint now emits a `checkpoint_hit` feature event, which is
also how khepri learns the checkpoint exists (registration is a side effect
of the hit, there is no separate endpoint).

The event is tracked before resolution and regardless of its outcome, so a
checkpoint reaches the dashboard even when nothing is configured for it yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* chore: register the new checkpoint event files in RevenueCat.xcodeproj

The Tuist workspace generates its own project, so the committed one needs
the files added by hand. Verified with a RevenueCat target build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* refactor(checkpoints): model CheckpointEvent as an enum with a single hit case

Follows PaywallEvent, WorkflowEvent and CustomPaywallEvent, and replaces the
two hardcoded "checkpoint_hit" literals with one exhaustive switch. Adding a
future case (checkpoint results) now fails to compile until both the wire
format and toMap() account for it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MNpP9VnvEwrMckgbFWxnRB

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 12:35:27 +02:00

67 lines
1.7 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// CheckpointEvent.swift
import Foundation
/// Checkpoint events. Sent through the shared feature events pipeline, which is also how the backend learns
/// a checkpoint exists: hits register it, there is no separate registration call.
enum CheckpointEvent: FeatureEvent {
var feature: Feature { .checkpoints }
var eventDiscriminator: String? { nil }
/// A checkpoint was hit.
case hit(Data)
}
extension CheckpointEvent {
/// The content of a ``CheckpointEvent``.
struct Data {
var id: UUID
var identifier: String
var date: Date
init(id: UUID = .init(), identifier: String, date: Date) {
self.id = id
self.identifier = identifier
self.date = date
}
}
}
extension CheckpointEvent {
/// - Returns: the underlying ``CheckpointEvent/Data-swift.struct`` for this event.
var data: Data {
switch self {
case let .hit(data): return data
}
}
/// The value khepri discriminates the analytics events union on. Single source of truth for both the wire
/// format and ``FeatureEvent/toMap()``, so a new case has to be given one here before it compiles.
var eventType: String {
switch self {
case .hit: return "checkpoint_hit"
}
}
}
extension CheckpointEvent.Data: Equatable, Codable, Sendable {}
extension CheckpointEvent: Equatable, Codable, Sendable {}