Skip to content

Commit

Permalink
Merge pull request #117 from superwall-me/develop
Browse files Browse the repository at this point in the history
3.0.0-beta.8
  • Loading branch information
yusuftor authored Mar 14, 2023
2 parents 58f17de + e75787b commit f7d0bf6
Show file tree
Hide file tree
Showing 29 changed files with 1,443 additions and 170 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

The changelog for `SuperwallKit`. Also see the [releases](https://github.com/superwall-me/Superwall-iOS/releases) on GitHub.

## 3.0.0-beta.8

### Enhancements

- Prevents the tracking of events that have the same name as internally tracked `SuperwallEvents` like `paywall_open`.

### Fixes

- Fixes an issue with reporting in the dashboard due to a mismatch of keys between client and server.

## 3.0.0-beta.7

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The preferred installation method is with [Swift Package Manager](https://swift.
To include the *Superwall* SDK in your app, add the following to your Podfile:

```
pod 'SuperwallKit', '3.0.0-beta.7'
pod 'SuperwallKit', '3.0.0-beta.8'
```

If you don't want to use the v3 beta, you'll need to add this instead:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ enum InternalSuperwallEvent {
}

struct Attributes: TrackableSuperwallEvent {
let appInstalledAtString: String
var superwallEvent: SuperwallEvent {
return .userAttributes(customParameters)
}
func getSuperwallParameters() async -> [String: Any] { [:] }
func getSuperwallParameters() async -> [String: Any] {
return [
"application_installed_at": appInstalledAtString
]
}
var customParameters: [String: Any] = [:]
}

Expand Down Expand Up @@ -161,8 +166,7 @@ enum InternalSuperwallEvent {
func getSuperwallParameters() async -> [String: Any] {
let fromEvent = eventData != nil
let params: [String: Any] = [
"is_triggered_from_event": fromEvent,
"event_name": eventData?.name ?? ""
"is_triggered_from_event": fromEvent
]

switch state {
Expand Down Expand Up @@ -211,27 +215,29 @@ enum InternalSuperwallEvent {
switch triggerResult {
case .noRuleMatch:
return params + [
"result": "no_rule_match",
"trigger_name": triggerName
"result": "no_rule_match"
]
case .holdout(let experiment):
return params + [
"variant_id": experiment.variant.id as Any,
"experiment_id": experiment.id as Any,
"result": "holdout",
"trigger_name": triggerName
"result": "holdout"
]
case let .paywall(experiment):
return params + [
"variant_id": experiment.variant.id as Any,
"experiment_id": experiment.id as Any,
"paywall_identifier": experiment.variant.paywallId as Any,
"result": "present",
"trigger_name": triggerName
"result": "present"
]
case .eventNotFound:
return params + [
"result": "eventNotFound"
]
case .error:
return params + [
"result": "error"
]
case .eventNotFound,
.error:
return [:]
}
}
}
Expand Down Expand Up @@ -325,11 +331,15 @@ enum InternalSuperwallEvent {
eventParams += transactionDict
}
return eventParams
case .fail(let message):
return await paywallInfo.eventParams(
forProduct: product,
otherParams: ["message": message]
)
case .fail(let error):
switch error {
case .failure(let message, _),
.pending(let message):
return await paywallInfo.eventParams(
forProduct: product,
otherParams: ["message": message]
)
}
}
}
}
Expand Down Expand Up @@ -433,8 +443,7 @@ enum InternalSuperwallEvent {
func getSuperwallParameters() async -> [String: Any] {
let fromEvent = eventData != nil
var params: [String: Any] = [
"is_triggered_from_event": fromEvent,
"event_name": eventData?.name ?? ""
"is_triggered_from_event": fromEvent
]
params += await paywallInfo.eventParams()
return params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ enum UserInitiatedEvent {

func getSuperwallParameters() async -> [String: Any] { [:] }
}

struct DefaultPaywall: TrackableUserInitiatedEvent {
let rawName = "$present"
let canImplicitlyTriggerPaywall = false
let customParameters: [String: Any] = [:]

func getSuperwallParameters() async -> [String: Any] { [:] }
}
/*
// MARK: - To be deprecated/deleted
struct PushNotification: TrackableUserInitiatedEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ enum TrackingLogic {
]

// Add a special property if it's a superwall event
var isStandardEvent = false
if trackableEvent is TrackableSuperwallEvent {
isStandardEvent = true
}
let isStandardEvent = trackableEvent is TrackableSuperwallEvent

var eventParams: [String: Any] = [
"$is_standard_event": isStandardEvent,
"$event_name": eventName
Expand Down Expand Up @@ -110,6 +108,31 @@ enum TrackingLogic {
}
}

/// Checks whether the user is tracking an event with the same name as a superwall event.
static func checkNotSuperwallEvent(_ event: String) throws {
for superwallEvent in SuperwallEventObjc.allCases where superwallEvent.description == event {
Logger.debug(
logLevel: .error,
scope: .paywallPresentation,
message: "Do not track an event with the same name as a SuperwallEvent",
info: ["event": event]
)
let userInfo: [String: Any] = [
NSLocalizedDescriptionKey: NSLocalizedString(
"",
value: "Do not track an event with the same name as a SuperwallEvent",
comment: ""
)
]
let error = NSError(
domain: "com.superwall",
code: 400,
userInfo: userInfo
)
throw error
}
}

static func canTriggerPaywall(
_ event: Trackable,
triggers: Set<String>,
Expand Down
113 changes: 43 additions & 70 deletions Sources/SuperwallKit/Analytics/Superwall Event/SuperwallEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public enum SuperwallEvent {
/// When the paywall fails to present.
case paywallPresentationFail(reason: PaywallPresentationFailureReason)

internal var canImplicitlyTriggerPaywall: Bool {
var canImplicitlyTriggerPaywall: Bool {
switch self {
case .appInstall,
.sessionStart,
Expand All @@ -147,123 +147,96 @@ extension SuperwallEvent {
let objcEvent: SuperwallEventObjc
let description: String

init(
objcEvent: SuperwallEventObjc,
description: String
) {
init(objcEvent: SuperwallEventObjc) {
self.objcEvent = objcEvent
self.description = description
self.description = objcEvent.description
}
}

var backingData: BackingData {
switch self {
case .firstSeen:
return .init(objcEvent: .firstSeen, description: "first_seen")
return .init(objcEvent: .firstSeen)
case .appOpen:
return .init(objcEvent: .appOpen, description: "app_open")
return .init(objcEvent: .appOpen)
case .appLaunch:
return .init(objcEvent: .appLaunch, description: "app_launch")
return .init(objcEvent: .appLaunch)
case .appInstall:
return .init(objcEvent: .appInstall, description: "app_install")
return .init(objcEvent: .appInstall)
case .sessionStart:
return .init(objcEvent: .sessionStart, description: "session_start")
return .init(objcEvent: .sessionStart)
case .subscriptionStatusDidChange:
return .init(objcEvent: .subscriptionStart, description: "subscription_status_did_change")
return .init(objcEvent: .subscriptionStatusDidChange)
case .appClose:
return .init(objcEvent: .appClose, description: "app_close")
return .init(objcEvent: .appClose)
case .deepLink:
return .init(objcEvent: .deepLink, description: "deepLink_open")
return .init(objcEvent: .deepLink)
case .triggerFire:
return .init(objcEvent: .triggerFire, description: "trigger_fire")
return .init(objcEvent: .triggerFire)
case .paywallOpen:
return .init(objcEvent: .paywallOpen, description: "paywall_open")
return .init(objcEvent: .paywallOpen)
case .paywallClose:
return .init(objcEvent: .paywallClose, description: "paywall_close")
return .init(objcEvent: .paywallClose)
case .transactionStart:
return .init(objcEvent: .transactionStart, description: "transaction_start")
return .init(objcEvent: .transactionStart)
case .transactionFail:
return .init(objcEvent: .transactionFail, description: "transaction_fail")
return .init(objcEvent: .transactionFail)
case .transactionAbandon:
return .init(objcEvent: .transactionAbandon, description: "transaction_abandon")
return .init(objcEvent: .transactionAbandon)
case .transactionTimeout:
return .init(objcEvent: .transactionTimeout, description: "transaction_timeout")
return .init(objcEvent: .transactionTimeout)
case .transactionComplete:
return .init(objcEvent: .transactionComplete, description: "transaction_complete")
return .init(objcEvent: .transactionComplete)
case .subscriptionStart:
return .init(objcEvent: .subscriptionStart, description: "subscription_start")
return .init(objcEvent: .subscriptionStart)
case .freeTrialStart:
return .init(objcEvent: .freeTrialStart, description: "freeTrial_start")
return .init(objcEvent: .freeTrialStart)
case .transactionRestore:
return .init(objcEvent: .transactionRestore, description: "transaction_restore")
return .init(objcEvent: .transactionRestore)
case .userAttributes:
return .init(objcEvent: .userAttributes, description: "user_attributes")
return .init(objcEvent: .userAttributes)
case .nonRecurringProductPurchase:
return .init(objcEvent: .nonRecurringProductPurchase, description: "nonRecurringProduct_purchase")
return .init(objcEvent: .nonRecurringProductPurchase)
case .paywallResponseLoadStart:
return .init(objcEvent: .paywallResponseLoadStart, description: "paywallResponseLoad_start")
return .init(objcEvent: .paywallResponseLoadStart)
case .paywallResponseLoadNotFound:
return .init(objcEvent: .paywallResponseLoadNotFound, description: "paywallResponseLoad_notFound")
return .init(objcEvent: .paywallResponseLoadNotFound)
case .paywallResponseLoadFail:
return .init(objcEvent: .paywallResponseLoadFail, description: "paywallResponseLoad_fail")
return .init(objcEvent: .paywallResponseLoadFail)
case .paywallResponseLoadComplete:
return .init(objcEvent: .paywallResponseLoadComplete, description: "paywallResponseLoad_complete")
return .init(objcEvent: .paywallResponseLoadComplete)
case .paywallWebviewLoadStart:
return .init(objcEvent: .paywallWebviewLoadStart, description: "paywallWebviewLoad_start")
return .init(objcEvent: .paywallWebviewLoadStart)
case .paywallWebviewLoadFail:
return .init(objcEvent: .paywallWebviewLoadFail, description: "paywallWebviewLoad_fail")
return .init(objcEvent: .paywallWebviewLoadFail)
case .paywallWebviewLoadComplete:
return .init(objcEvent: .paywallWebviewLoadComplete, description: "paywallWebviewLoad_complete")
return .init(objcEvent: .paywallWebviewLoadComplete)
case .paywallWebviewLoadTimeout:
return .init(objcEvent: .paywallWebviewLoadTimeout, description: "paywallWebviewLoad_timeout")
return .init(objcEvent: .paywallWebviewLoadTimeout)
case .paywallProductsLoadStart:
return .init(objcEvent: .paywallProductsLoadStart, description: "paywallProductsLoad_start")
return .init(objcEvent: .paywallProductsLoadStart)
case .paywallProductsLoadFail:
return .init(objcEvent: .paywallProductsLoadFail, description: "paywallProductsLoad_fail")
return .init(objcEvent: .paywallProductsLoadFail)
case .paywallProductsLoadComplete:
return .init(objcEvent: .paywallProductsLoadComplete, description: "paywallProductsLoad_complete")
return .init(objcEvent: .paywallProductsLoadComplete)
case .paywallPresentationFail(reason: let reason):
switch reason {
case .userIsSubscribed:
return .init(
objcEvent: .paywallPresentationFailUserIsSubscribed,
description: "paywallPresentationFail_userIsSubscribed"
)
return .init(objcEvent: .paywallPresentationFailUserIsSubscribed)
case .holdout:
return .init(
objcEvent: .paywallPresentationFailInHoldout,
description: "paywallPresentationFail_holdout"
)
return .init(objcEvent: .paywallPresentationFailInHoldout)
case .noRuleMatch:
return .init(
objcEvent: .paywallPresentationFailNoRuleMatch,
description: "paywallPresentationFail_noRuleMatch"
)
return .init(objcEvent: .paywallPresentationFailNoRuleMatch)
case .eventNotFound:
return .init(
objcEvent: .paywallPresentationFailEventNotFound,
description: "paywallPresentationFail_eventNotFound"
)
return .init(objcEvent: .paywallPresentationFailEventNotFound)
case .debuggerLaunched:
return .init(
objcEvent: .paywallPresentationFailDebuggerLaunched,
description: "paywallPresentationFail_debuggerLaunched"
)
return .init(objcEvent: .paywallPresentationFailDebuggerLaunched)
case .alreadyPresented:
return .init(
objcEvent: .paywallPresentationFailAlreadyPresented,
description: "paywallPresentationFail_alreadyPresented"
)
return .init(objcEvent: .paywallPresentationFailAlreadyPresented)
case .noPresenter:
return .init(
objcEvent: .paywallPresentationFailNoPresenter,
description: "paywallPresentationFail_noPresenter"
)
return .init(objcEvent: .paywallPresentationFailNoPresenter)
case .noPaywallViewController:
return .init(
objcEvent: .paywallPresentationFailNoPaywallViewController,
description: "paywallPresentationFail_noPaywallViewController"
)
return .init(objcEvent: .paywallPresentationFailNoPaywallViewController)
}
}
}
Expand Down
Loading

0 comments on commit f7d0bf6

Please sign in to comment.