Skip to content

Commit

Permalink
exposes locale to event parameters in pricing related events
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemor committed Sep 14, 2021
1 parent bb74bdc commit b624f5a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Sources/Paywall/Misc/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ internal extension SKProduct {
"periodWeeks": periodWeeks,
"periodMonths": periodMonths,
"periodYears": periodYears,
"locale": priceLocale.identifier,
"languageCode": priceLocale.languageCode ?? "n/a",
"currencyCode": priceLocale.currencyCode ?? "n/a",
"currencySymbol": priceLocale.currencySymbol ?? "n/a",

]
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Paywall/Network/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class DeviceHelper {
}

var locale: String {
get { Locale.autoupdatingCurrent.identifier ?? "" }
get { Locale.autoupdatingCurrent.identifier }
}

var languageCode: String {
Expand Down
22 changes: 21 additions & 1 deletion Sources/Paywall/Paywall/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ extension Paywall {
output["product_id"] = p.productIdentifier
for k in p.eventData.keys {
if let v = p.eventData[k] {
output["product_\(k)"] = v
output["product_\(k.camelCaseToSnakeCase())"] = v
}
}
}
Expand Down Expand Up @@ -560,3 +560,23 @@ extension Paywall {
struct SuperwallEventError: LocalizedError {
var message: String
}


extension String {
func camelCaseToSnakeCase() -> String {
let acronymPattern = "([A-Z]+)([A-Z][a-z]|[0-9])"
let fullWordsPattern = "([a-z])([A-Z]|[0-9])"
let digitsFirstPattern = "([0-9])([A-Z])"
return self.processCamelCaseRegex(pattern: acronymPattern)?
.processCamelCaseRegex(pattern: fullWordsPattern)?
.processCamelCaseRegex(pattern:digitsFirstPattern)?.lowercased() ?? self.lowercased()
}



fileprivate func processCamelCaseRegex(pattern: String) -> String? {
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2")
}
}
3 changes: 2 additions & 1 deletion Sources/Paywall/Paywall/SWPaywallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal class SWPaywallViewController: UIViewController {
self?.shimmerView.transform = .identity
self?.purchaseLoadingIndicator.alpha = 0.0
self?.purchaseLoadingIndicator.transform = CGAffineTransform(scaleX: 0.05, y: 0.05)
}, completion: { [weak self] _ in
}, completion: { _ in
// self?.purchaseLoadingIndicator.stopAnimating()
})
case .ready:
Expand Down Expand Up @@ -192,6 +192,7 @@ internal class SWPaywallViewController: UIViewController {
wv.scrollView.minimumZoomScale = 1.0
wv.scrollView.backgroundColor = .clear
wv.scrollView.isOpaque = false



return wv
Expand Down

0 comments on commit b624f5a

Please sign in to comment.