diff --git a/Example/BasicExample/BasicExample/ContentView.swift b/Example/BasicExample/BasicExample/ContentView.swift index 92f09f7..bec787f 100644 --- a/Example/BasicExample/BasicExample/ContentView.swift +++ b/Example/BasicExample/BasicExample/ContentView.swift @@ -13,12 +13,13 @@ struct ContentView: View { VStack { HStack { Button(action: { - var traits = [String:Any]() + var traits = [String:Codable]() var products = [Any]() products.append(["price":1,"quantity":1,"productId":"foo","color":"blue", "dupe":"override"]) products.append(["price":2,"quantity":2,"productId":"bar","size":"large"]) products.append(["price":3,"quantity":3,"productId":"baz","fit":9]) - traits["products"] = products + let productStr = convertIntoJSONString(arrayObject: products) + traits["products"] = productStr traits["dupe"] = "default" traits["general"] = "value" Analytics.main.track(name: "Order Completed", properties: traits) @@ -39,7 +40,7 @@ struct ContentView: View { Text("Group") }).padding(6) Button(action: { - var traits = [String:Any]() + var traits = [String:Codable]() traits["birthday"] = "1980-06-07T01:21:13Z" traits["email"] = "testuser@test.com" traits["firstName"] = "fnu" @@ -61,6 +62,20 @@ struct ContentView: View { print("Executed Analytics onDisappear()") } } + + func convertIntoJSONString(arrayObject: [Any]) -> String? { + + do { + let jsonData: Data = try JSONSerialization.data(withJSONObject: arrayObject, options: []) + if let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue) { + return jsonString as String + } + + } catch let error as NSError { + print("Array convertIntoJSON - \(error.description)") + } + return nil + } } struct ContentView_Previews: PreviewProvider { diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..6529d6b --- /dev/null +++ b/Package.resolved @@ -0,0 +1,43 @@ +{ + "object": { + "pins": [ + { + "package": "Segment", + "repositoryURL": "https://github.com/segmentio/analytics-swift.git", + "state": { + "branch": null, + "revision": "79fb17a5d4abf8f80e6a0935e57c7df7b670a6c0", + "version": "1.4.1" + } + }, + { + "package": "braze-swift-sdk", + "repositoryURL": "https://github.com/braze-inc/braze-swift-sdk.git", + "state": { + "branch": null, + "revision": "3f322b0ca1ec2f53bc87192a39377be7e8f142db", + "version": "5.8.1" + } + }, + { + "package": "SDWebImage", + "repositoryURL": "https://github.com/SDWebImage/SDWebImage.git", + "state": { + "branch": null, + "revision": "fb50c1d20f24db5322b2f8f379de3618f75fe08e", + "version": "5.15.5" + } + }, + { + "package": "Sovran", + "repositoryURL": "https://github.com/segmentio/Sovran-Swift.git", + "state": { + "branch": null, + "revision": "944c17d7c46bd95fc37f09136cabd172be5b413b", + "version": "1.0.3" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift index 7d16d08..eb82bd4 100644 --- a/Package.swift +++ b/Package.swift @@ -23,12 +23,12 @@ let package = Package( .package( name: "Segment", url: "https://github.com/segmentio/analytics-swift.git", - from: "1.1.2" + from: "1.4.1" ), .package( name: "braze-swift-sdk", url:"https://github.com/braze-inc/braze-swift-sdk.git", - from: "5.0.0"), + from: "5.8.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/SegmentBraze/BrazeDestination.swift b/Sources/SegmentBraze/BrazeDestination.swift index e33fbc5..a782dfa 100644 --- a/Sources/SegmentBraze/BrazeDestination.swift +++ b/Sources/SegmentBraze/BrazeDestination.swift @@ -39,6 +39,11 @@ import UIKit An implementation of the Braze Analytics device mode destination as a plugin. */ +@objc(SEGBrazeDestination) +public class ObjCSegmentBraze: NSObject, ObjCDestination, ObjCDestinationShim { + public func instance() -> DestinationPlugin { return BrazeDestination() } +} + public class BrazeDestination: DestinationPlugin { public let timeline = Timeline() public let type = PluginType.destination @@ -59,11 +64,11 @@ public class BrazeDestination: DestinationPlugin { guard let tempSettings: BrazeSettings = settings.integrationSettings(forPlugin: self) else { return } brazeSettings = tempSettings - var configuration = Braze.Configuration( + let configuration = Braze.Configuration( apiKey: brazeSettings?.apiKey ?? "", endpoint: brazeSettings?.customEndpoint ?? "" ) - configuration.api.addSdkMetadata([Braze.Configuration.Api.SdkMetadata.segment]) + configuration.api.addSDKMetadata([Braze.Configuration.Api.SDKMetadata.segment]) braze = Braze(configuration: configuration) } @@ -232,7 +237,6 @@ private struct BrazeSettings: Codable { let minimumIntervalBetweenTriggerActionsInSeconds: Double? let allowCrawlerActivity: Bool? let enableHtmlInAppMessages: Bool? -// let versionSettings: Dictionary // not Codable let bundlingStatus: String? let serviceWorkerLocation: String? let requireExplicitInAppMessageDismissal: Bool? @@ -266,21 +270,3 @@ extension BrazeDestination { } } - -// Rules for converting keys and values to the proper formats that bridge -// from Segment to the Partner SDK. These are only examples. -private extension BrazeDestination { - - static var eventNameMap = ["ADD_TO_CART": "Product Added", - "PRODUCT_TAPPED": "Product Tapped"] - - static var eventValueConversion: ((_ key: String, _ value: Any) -> Any) = { (key, value) in - if let valueString = value as? String { - return valueString - .replacingOccurrences(of: "-", with: "_") - .replacingOccurrences(of: " ", with: "_") - } else { - return value - } - } -}