diff --git a/PostHog/Models/PostHogEvent.swift b/PostHog/Models/PostHogEvent.swift index 6418b3c60..1044b8d4a 100644 --- a/PostHog/Models/PostHogEvent.swift +++ b/PostHog/Models/PostHogEvent.swift @@ -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 @@ -77,7 +76,7 @@ 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, @@ -85,7 +84,7 @@ import Foundation properties: properties, timestamp: timestampDate, uuid: uuidObj, - apiKey: projectKey + projectToken: projectToken ) } @@ -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 } diff --git a/PostHog/PostHogApi.swift b/PostHog/PostHogApi.swift index c6fdf758d..4a1ef47ff 100644 --- a/PostHog/PostHogApi.swift +++ b/PostHog/PostHogApi.swift @@ -207,7 +207,7 @@ class PostHogApi { } for event in events { - event.apiKey = config.projectToken + event.projectToken = config.projectToken } let toSend = events.map { $0.toJSON() } diff --git a/PostHog/PostHogConfig.swift b/PostHog/PostHogConfig.swift index d559fb89d..c81b6d2ea 100644 --- a/PostHog/PostHogConfig.swift +++ b/PostHog/PostHogConfig.swift @@ -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 } @@ -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 } diff --git a/PostHog/PostHogSDK.swift b/PostHog/PostHogSDK.swift index be6a49dac..dda450163 100644 --- a/PostHog/PostHogSDK.swift +++ b/PostHog/PostHogSDK.swift @@ -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 } diff --git a/PostHogTests/PostHogStorageMigrationTest.swift b/PostHogTests/PostHogStorageMigrationTest.swift index a270a8c1d..901038d4c 100644 --- a/PostHogTests/PostHogStorageMigrationTest.swift +++ b/PostHogTests/PostHogStorageMigrationTest.swift @@ -256,7 +256,7 @@ class PostHogStorageMigrationTest { ], timestamp: Date(timeIntervalSince1970: 1707221234000), uuid: UUID(), - apiKey: "test_project_token" + projectToken: "test_project_token" ), PostHogEvent( event: "$snapshot", @@ -285,7 +285,7 @@ class PostHogStorageMigrationTest { ], timestamp: Date(timeIntervalSince1970: 1707221235), uuid: UUID(), - apiKey: "test_project_token" + projectToken: "test_project_token" ), ] diff --git a/sdk_compliance_adapter/README.md b/sdk_compliance_adapter/README.md index 30b405197..343bb83c7 100644 --- a/sdk_compliance_adapter/README.md +++ b/sdk_compliance_adapter/README.md @@ -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 diff --git a/sdk_compliance_adapter/run_tests.sh b/sdk_compliance_adapter/run_tests.sh index 5a245aa6d..fde1667fe 100755 --- a/sdk_compliance_adapter/run_tests.sh +++ b/sdk_compliance_adapter/run_tests.sh @@ -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