Skip to content
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
15 changes: 7 additions & 8 deletions PostHog/Models/PostHogEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ import Foundation
/// Unique event identifier generated by the SDK.
@objc public private(set) var uuid: UUID
// Only used for Replay.
// Publicly this remains named apiKey for BeforeSendBlock compatibility,
// but it carries the PostHog project token and is serialized as api_key on the wire.
var apiKey: String?
// Serialized as api_key on the wire.
var projectToken: String?

/// Set by the SDK when this event took the throttled replay debug bundle, so it survives `beforeSend` renames or replacement.
var carriesReplayDebugBundle = false

init(event: String, distinctId: String, properties: [String: Any]? = nil, timestamp: Date = Date(), uuid: UUID = UUID.v7(), apiKey: String? = nil) {
init(event: String, distinctId: String, properties: [String: Any]? = nil, timestamp: Date = Date(), uuid: UUID = UUID.v7(), projectToken: String? = nil) {
self.event = event
self.distinctId = distinctId
self.properties = properties ?? [:]
self.timestamp = timestamp
self.uuid = uuid
self.apiKey = apiKey
self.projectToken = projectToken
}

// NOTE: Ideally we would use the NSCoding behaviour but it gets needlessly complex
Expand Down Expand Up @@ -77,15 +76,15 @@ import Foundation
let uuidObj = UUID(uuidString: uuid) ?? UUID.v7()

// Wire field name remains api_key, but it carries the PostHog project token.
let projectKey = json["api_key"] as? String
let projectToken = json["api_key"] as? String

return PostHogEvent(
event: event,
distinctId: distinctId,
properties: properties,
timestamp: timestampDate,
uuid: uuidObj,
apiKey: projectKey
projectToken: projectToken
)
}

Expand All @@ -98,7 +97,7 @@ import Foundation
"uuid": uuid.postHogUuidString,
]

if let projectToken = apiKey {
if let projectToken {
// Wire field name remains api_key, but it carries the PostHog project token.
json["api_key"] = projectToken
}
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class PostHogApi {
}

for event in events {
event.apiKey = config.projectToken
event.projectToken = config.projectToken
}

let toSend = events.map { $0.toJSON() }
Expand Down
16 changes: 8 additions & 8 deletions PostHog/PostHogConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ public typealias BeforeSendBlock = (PostHogEvent) -> PostHogEvent?
///
/// Note: Event triggers will only work with the instance that first enables surveys.
/// In case of multiple instances, please make sure you are capturing events on the instance that has config.surveys = true
@available(watchOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(macOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(tvOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(visionOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(watchOS, unavailable, message: "Surveys are only available on iOS")
@available(macOS, unavailable, message: "Surveys are only available on iOS")
@available(tvOS, unavailable, message: "Surveys are only available on iOS")
@available(visionOS, unavailable, message: "Surveys are only available on iOS")
@objc public var surveys: Bool {
get { _surveys }
set { _surveys = newValue }
Expand All @@ -437,10 +437,10 @@ public typealias BeforeSendBlock = (PostHogEvent) -> PostHogEvent?
/// Configuration for mobile survey presentation and localization.
///
/// Mutate fields on `config.surveysConfig` or replace this object before calling setup.
@available(watchOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(macOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(tvOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(visionOS, unavailable, message: "Surveys are only available on iOS 15+")
@available(watchOS, unavailable, message: "Surveys are only available on iOS")
@available(macOS, unavailable, message: "Surveys are only available on iOS")
@available(tvOS, unavailable, message: "Surveys are only available on iOS")
@available(visionOS, unavailable, message: "Surveys are only available on iOS")
@objc public var surveysConfig: PostHogSurveysConfig {
get { _surveysConfig }
set { _surveysConfig = newValue }
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ let maxRetryDelay = 30.0
}

if config.projectToken.isEmpty {
hedgeLog("PostHog SDK will be disabled because projectToken or apiKey is empty.")
hedgeLog("PostHog SDK will be disabled because projectToken is empty.")
return
}

Expand Down
4 changes: 2 additions & 2 deletions PostHogTests/PostHogStorageMigrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class PostHogStorageMigrationTest {
],
timestamp: Date(timeIntervalSince1970: 1707221234000),
uuid: UUID(),
apiKey: "test_project_token"
projectToken: "test_project_token"
),
PostHogEvent(
event: "$snapshot",
Expand Down Expand Up @@ -285,7 +285,7 @@ class PostHogStorageMigrationTest {
],
timestamp: Date(timeIntervalSince1970: 1707221235),
uuid: UUID(),
apiKey: "test_project_token"
projectToken: "test_project_token"
),
]

Expand Down
2 changes: 1 addition & 1 deletion sdk_compliance_adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Reset the SDK and adapter state.

1. **macOS environment** (local Mac or GitHub Actions `macos-latest`)
2. **Docker Desktop** installed and running
3. **Swift 5.9+** installed
3. **Swift 6.2+** installed

### Steps

Expand Down
2 changes: 1 addition & 1 deletion sdk_compliance_adapter/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo ""

# Check prerequisites
if ! command -v swift &> /dev/null; then
echo "❌ Error: Swift not found. Please install Swift 5.9+"
echo "❌ Error: Swift not found. Please install Swift 6.2+"
exit 1
fi

Expand Down
Loading