Skip to content

Commit 0c64667

Browse files
committed
Adds params to PaywallInfo
1 parent 7310ea9 commit 0c64667

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for `SuperwallKit`. Also see the [releases](https://github.com/sup
77
### Enhancements
88

99
- Updates Superscript to 0.2.4.
10+
- Adds the `params` passed in when presenting the paywall to `PaywallInfo`.
1011

1112
## 4.0.6
1213

Sources/SuperwallKit/Models/Paywall/Paywall.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ struct Paywall: Codable {
101101
/// user does not purchase.
102102
var featureGating: FeatureGatingBehavior
103103

104+
/// The parameters passed to present the paywall.
105+
var params: JSON
106+
104107
/// The local notifications for the paywall, e.g. to notify the user of free trial expiry.
105108
var localNotifications: [LocalNotification]
106109

@@ -141,6 +144,7 @@ struct Paywall: Codable {
141144
case surveys
142145
case manifest
143146
case isScrollEnabled
147+
case params
144148

145149
case responseLoadStartTime
146150
case responseLoadCompleteTime
@@ -255,6 +259,9 @@ struct Paywall: Codable {
255259

256260
manifest = try values.decodeIfPresent(ArchiveManifest.self, forKey: .manifest)
257261
isScrollEnabled = try values.decodeIfPresent(Bool.self, forKey: .isScrollEnabled) ?? true
262+
263+
// Not encoding/decoding because this can change whenever the paywall is presented.
264+
params = [:]
258265
}
259266

260267
func encode(to encoder: Encoder) throws {
@@ -345,7 +352,8 @@ struct Paywall: Codable {
345352
computedPropertyRequests: [ComputedPropertyRequest] = [],
346353
surveys: [Survey] = [],
347354
manifest: ArchiveManifest? = nil,
348-
isScrollEnabled: Bool
355+
isScrollEnabled: Bool,
356+
params: JSON
349357
) {
350358
self.databaseId = databaseId
351359
self.identifier = identifier
@@ -378,6 +386,7 @@ struct Paywall: Codable {
378386
self.surveys = surveys
379387
self.manifest = manifest
380388
self.isScrollEnabled = isScrollEnabled
389+
self.params = params
381390
}
382391

383392
func getInfo(fromPlacement: PlacementData?) -> PaywallInfo {
@@ -412,7 +421,8 @@ struct Paywall: Codable {
412421
computedPropertyRequests: computedPropertyRequests,
413422
surveys: surveys,
414423
presentation: presentation,
415-
isScrollEnabled: isScrollEnabled
424+
isScrollEnabled: isScrollEnabled,
425+
params: params.dictionaryValue
416426
)
417427
}
418428

@@ -424,6 +434,7 @@ struct Paywall: Codable {
424434
presentationSourceType = paywall.presentationSourceType
425435
experiment = paywall.experiment
426436
featureGating = paywall.featureGating
437+
params = paywall.params
427438
}
428439
}
429440

@@ -463,7 +474,8 @@ extension Paywall: Stubbable {
463474
productsLoadingInfo: .init(),
464475
shimmerLoadingInfo: .init(),
465476
paywalljsVersion: "",
466-
isScrollEnabled: true
477+
isScrollEnabled: true,
478+
params: [:]
467479
)
468480
}
469481
}

Sources/SuperwallKit/Paywall/Presentation/PaywallInfo.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public final class PaywallInfo: NSObject {
128128
/// Indicates whether scrolling of the webview is enabled.
129129
public let isScrollEnabled: Bool
130130

131+
/// The parameters passed to ``Superwall/register(event:params:)`` or
132+
/// ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)``
133+
/// when presenting the paywall.
134+
public let params: [String: Any]
135+
131136
init(
132137
databaseId: String,
133138
identifier: String,
@@ -159,7 +164,8 @@ public final class PaywallInfo: NSObject {
159164
computedPropertyRequests: [ComputedPropertyRequest],
160165
surveys: [Survey],
161166
presentation: PaywallPresentationInfo,
162-
isScrollEnabled: Bool
167+
isScrollEnabled: Bool,
168+
params: [String: Any]
163169
) {
164170
self.databaseId = databaseId
165171
self.identifier = identifier
@@ -181,6 +187,7 @@ public final class PaywallInfo: NSObject {
181187
self.computedPropertyRequests = computedPropertyRequests
182188
self.surveys = surveys
183189
self.presentation = presentation
190+
self.params = params
184191

185192
if placementData != nil {
186193
self.presentedBy = "placement"
@@ -261,6 +268,10 @@ public final class PaywallInfo: NSObject {
261268
"is_scroll_enabled": isScrollEnabled as Any
262269
]
263270

271+
for (key, value) in params {
272+
output["params_\(key)"] = value
273+
}
274+
264275
var loadingVars: [String: Any] = [:]
265276
for key in output.keys {
266277
if key.contains("_load_"),
@@ -368,7 +379,8 @@ extension PaywallInfo: Stubbable {
368379
style: .none,
369380
delay: 0
370381
),
371-
isScrollEnabled: true
382+
isScrollEnabled: true,
383+
params: [:]
372384
)
373385
}
374386

@@ -416,7 +428,8 @@ extension PaywallInfo: Stubbable {
416428
style: .none,
417429
delay: 0
418430
),
419-
isScrollEnabled: true
431+
isScrollEnabled: true,
432+
params: [:]
420433
)
421434
}
422435
}

Sources/SuperwallKit/Paywall/Request/PaywallRequestManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ actor PaywallRequestManager {
105105
if let featureGating = request.overrides.featureGatingBehavior {
106106
paywall.featureGating = featureGating
107107
}
108+
paywall.params = request.placementData?.parameters ?? [:]
108109
return paywall
109110
}
110111

0 commit comments

Comments
 (0)