Skip to content

Commit

Permalink
Added external data collection filter back in
Browse files Browse the repository at this point in the history
- updated way products are mapped to PaywallProducts
  • Loading branch information
yusuftor committed Apr 2, 2024
1 parent 41d826f commit bc75145
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ extension Superwall {
disableVerboseEvents: verboseEvents,
isSandbox: dependencyContainer.makeIsSandbox()
) {
await dependencyContainer.eventsQueue.enqueue(event: eventData.jsonData)
await dependencyContainer.eventsQueue.enqueue(
data: eventData.jsonData,
from: event
)
}
dependencyContainer.storage.coreDataManager.saveEventData(eventData)

Expand Down
1 change: 1 addition & 0 deletions Sources/SuperwallKit/Models/Product/ProductVariable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ProductVariable: Encodable, Equatable {
let name: String
let attributes: JSON

/// Encodes in the format `"name": [attributes]`
func encode(to encoder: Encoder) throws {
// Create a container for the custom key (the product name)
var container = encoder.container(keyedBy: DynamicCodingKey.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,31 @@ public final class PaywallOverrides: NSObject, Sendable {
private static func mapToPaywallProducts(
_ products: [String: StoreProduct]
) -> PaywallProducts? {
var paywallProducts: PaywallProducts?
var primaryProduct: StoreProduct?
var secondaryProduct: StoreProduct?
var tertiaryProduct: StoreProduct?

if let primary = products["primary"] {
paywallProducts = PaywallProducts(primary: primary)
primaryProduct = primary

Check warning on line 154 in Sources/SuperwallKit/Paywall/Presentation/Internal/Presentation Request/PaywallOverrides.swift

View workflow job for this annotation

GitHub Actions / Package-SwiftLint

Indentation Width Violation: Code should be indented using one tab or 2 spaces (indentation_width)
}
if let secondary = products["secondary"] {
paywallProducts = PaywallProducts(secondary: secondary)
secondaryProduct = secondary

Check warning on line 157 in Sources/SuperwallKit/Paywall/Presentation/Internal/Presentation Request/PaywallOverrides.swift

View workflow job for this annotation

GitHub Actions / Package-SwiftLint

Indentation Width Violation: Code should be indented using one tab or 2 spaces (indentation_width)
}
if let tertiary = products["tertiary"] {
paywallProducts = PaywallProducts(tertiary: tertiary)
tertiaryProduct = tertiary

Check warning on line 160 in Sources/SuperwallKit/Paywall/Presentation/Internal/Presentation Request/PaywallOverrides.swift

View workflow job for this annotation

GitHub Actions / Package-SwiftLint

Indentation Width Violation: Code should be indented using one tab or 2 spaces (indentation_width)
}

var paywallProducts: PaywallProducts?

// Only initialise PaywallProducts if at least one product is not nil
if primaryProduct != nil || secondaryProduct != nil || tertiaryProduct != nil {
paywallProducts = PaywallProducts(

Check warning on line 167 in Sources/SuperwallKit/Paywall/Presentation/Internal/Presentation Request/PaywallOverrides.swift

View workflow job for this annotation

GitHub Actions / Package-SwiftLint

Indentation Width Violation: Code should be indented using one tab or 2 spaces (indentation_width)
primary: primaryProduct,
secondary: secondaryProduct,
tertiary: tertiaryProduct
)
}

return paywallProducts
}
}
22 changes: 20 additions & 2 deletions Sources/SuperwallKit/Storage/EventsQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,26 @@ actor EventsQueue {
}
}

func enqueue(event: JSON) {
elements.append(event)
func enqueue(
data: JSON,
from event: Trackable
) {
guard externalDataCollectionAllowed(from: event) else {
return
}
elements.append(data)
}

private func externalDataCollectionAllowed(from event: Trackable) -> Bool {
if Superwall.shared.options.isExternalDataCollectionEnabled {
return true
}
if event is InternalSuperwallEvent.TriggerFire
|| event is InternalSuperwallEvent.Attributes
|| event is UserInitiatedEvent.Track {
return false
}
return true
}

func flushInternal(depth: Int = 10) {
Expand Down

0 comments on commit bc75145

Please sign in to comment.