Skip to content

Commit

Permalink
Merge pull request #168 from TelemetryDeck/feature/vision-country-code
Browse files Browse the repository at this point in the history
Adds support for accessing the Storefront country code on visionOS
  • Loading branch information
Jeehut authored Jul 6, 2024
2 parents 9ec0f0c + 4a18c11 commit 410ef5e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension TelemetryDeck {

let priceValueInUSD: Double

if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) {
if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) {
if transaction.currency?.identifier == "USD" {
priceValueInUSD = priceValueInNativeCurrency
} else if
Expand All @@ -47,18 +47,23 @@ extension TelemetryDeck {
}
}

#if os(visionOS)
let countryCode = "US" // NOTE: visionOS 1.x does not support the `storefrontCountryCode` field
#else
let countryCode = transaction.storefrontCountryCode
#endif
let countryCode: String
if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) {
countryCode = transaction.storefront.countryCode
} else {
#if os(visionOS)
countryCode = "US"
#else
countryCode = transaction.storefrontCountryCode
#endif
}

var purchaseParameters: [String: String] = [
"TelemetryDeck.Purchase.type": transaction.subscriptionGroupID != nil ? "subscription" : "one-time-purchase",
"TelemetryDeck.Purchase.countryCode": countryCode,
]

if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) {
if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) {
if let currencyCode = transaction.currency?.identifier {
purchaseParameters["TelemetryDeck.Purchase.currencyCode"] = currencyCode
}
Expand Down

0 comments on commit 410ef5e

Please sign in to comment.