Skip to content

Commit

Permalink
Update based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Dec 18, 2024
1 parent c2fb780 commit f6ea23a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
8 changes: 3 additions & 5 deletions Sources/Core/Tracker/TrackerEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class TrackerEvent : InspectableEvent, StateMachineEvent {

var trueTimestamp: Date?

private(set) var isPrimitive: Bool
private(set) var isPrimitive: Bool = false

private(set) var isService: Bool

private(set) var isWebView: Bool
private(set) var isWebView: Bool = false

init(event: Event, eventId: UUID = UUID(), state: TrackerStateSnapshot? = nil) {
self.eventId = eventId
Expand All @@ -50,12 +50,10 @@ class TrackerEvent : InspectableEvent, StateMachineEvent {
self.state = state ?? TrackerState()

isService = (event is TrackerError)
isWebView = false
isPrimitive = false

switch event {
case _ as WebViewReader:
eventName = (payload[kSPEvent] as? String) ?? "ue"
eventName = (payload[kSPEvent] as? String) ?? kSPEventUnstructured
schema = getWebViewSchema()
isWebView = true

Expand Down
18 changes: 6 additions & 12 deletions Sources/Core/Tracker/WebViewMessageHandlerV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,19 @@ class WebViewMessageHandlerV2: NSObject, WKScriptMessageHandler {
}

func parseSelfDescribingEventDataFromMessage(_ messageString: String?) -> [String : Any]? {
guard (messageString != nil) else { return nil }
guard let eventData = messageString?.data(using: .utf8) else {
logError(message: "WebView: Received event payload is not serializable to JSON, skipping.")
return nil
}
guard let eventJson = try? JSONSerialization.jsonObject(with: eventData) as? [String : Any] else {
if messageString == nil { return nil }
guard let eventData = messageString?.data(using: .utf8),
let eventJson = try? JSONSerialization.jsonObject(with: eventData) as? [String : Any] else {
logError(message: "WebView: Received event payload is not serializable to JSON, skipping.")
return nil
}
return eventJson
}

func parseEntitiesFromMessage(_ messageString: String?) -> [[AnyHashable : Any]]? {
guard (messageString != nil) else { return nil }
guard let entitiesData = messageString?.data(using: .utf8) else {
logError(message: "WebView: Received event payload is not serializable to JSON, skipping.")
return nil
}
guard let entitiesJson = try? JSONSerialization.jsonObject(with: entitiesData) as? [[AnyHashable : Any]] else {
if messageString == nil { return nil }
guard let entitiesData = messageString?.data(using: .utf8),
let entitiesJson = try? JSONSerialization.jsonObject(with: entitiesData) as? [[AnyHashable : Any]] else {
logError(message: "WebView: Received event payload is not serializable to JSON, skipping.")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Snowplow/Snowplow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public class Snowplow: NSObject {
let messageHandlerV2 = WebViewMessageHandlerV2()

webViewConfiguration.userContentController.add(messageHandlerOld, name: "snowplow")
webViewConfiguration.userContentController.add(messageHandlerV2, name: "snowplow")
webViewConfiguration.userContentController.add(messageHandlerV2, name: "snowplowV2")
}

#endif
Expand Down

0 comments on commit f6ea23a

Please sign in to comment.