Files
purchases-ios/Sources/Events/FeatureEvents/Networking/FeatureEventsRequest.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

70 lines
2.4 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
//
// FeatureEventsRequest.swift
//
// Created by Nacho Soto on 9/6/23.
import Foundation
/// The content of a request to the feature events endpoint.
struct FeatureEventsRequest {
var events: [AnyEncodable]
init(events: [AnyEncodable]) {
self.events = events
}
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
// swiftlint:disable:next cyclomatic_complexity
init(events: [StoredFeatureEvent]) {
self.init(events: events.compactMap { storedEvent -> AnyEncodable? in
switch storedEvent.feature {
case .paywalls:
guard let event = PaywallEvent(storedEvent: storedEvent) else {
return nil
}
return AnyEncodable(event)
case .customerCenter:
switch storedEvent.eventDiscriminator {
case CustomerCenterEventDiscriminator.answerSubmitted.rawValue:
guard let event = CustomerCenterAnswerSubmittedEventRequest.create(from: storedEvent) else {
return nil
}
return AnyEncodable(event)
default:
guard let event = CustomerCenterEventBaseRequest.createBase(from: storedEvent) else {
return nil
}
return AnyEncodable(event)
}
case .customPaywalls:
guard let event = CustomPaywallEvent(storedEvent: storedEvent) else {
return nil
}
return AnyEncodable(event)
case .workflows:
guard let event = FeatureEventsRequest.WorkflowEvent(storedEvent: storedEvent) else {
return nil
}
return AnyEncodable(event)
case .checkpoints:
guard let event = FeatureEventsRequest.CheckpointEvent(storedEvent: storedEvent) else {
return nil
}
return AnyEncodable(event)
}
})
}
}
extension FeatureEventsRequest: HTTPRequestBody {}