diff --git a/Example/BasicExample/BasicExample.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/BasicExample/BasicExample.xcworkspace/xcshareddata/swiftpm/Package.resolved index 191a1b5..159a789 100644 --- a/Example/BasicExample/BasicExample.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/BasicExample/BasicExample.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/segmentio/analytics-swift", "state": { "branch": "main", - "revision": "939a04164cd4db7ca666dd1e09663edc2d34c4f3", + "revision": "51f56b972de8daee251f18fd2c91fa3a33c8d77e", "version": null } }, @@ -15,8 +15,17 @@ "repositoryURL": "https://github.com/flurry/FlurrySwiftPackage", "state": { "branch": null, - "revision": "5005efa36a92d99077994aa80ef695bf2c6b9935", - "version": "12.1.3" + "revision": "70a9eff3929892a0de7c5480f559637fd7863afe", + "version": "12.4.0" + } + }, + { + "package": "JSONSafeEncoder", + "repositoryURL": "https://github.com/segmentio/jsonsafeencoder-swift.git", + "state": { + "branch": null, + "revision": "8b70dc8c01b7b041912e30e29d2b488a43f782ac", + "version": "1.0.1" } }, { @@ -24,8 +33,8 @@ "repositoryURL": "https://github.com/segmentio/Sovran-Swift.git", "state": { "branch": null, - "revision": "944c17d7c46bd95fc37f09136cabd172be5b413b", - "version": "1.0.3" + "revision": "64f3b5150c282a34af4578188dce2fd597e600e3", + "version": "1.1.0" } } ] diff --git a/Example/BasicExample/BasicExample/BasicExampleApp.swift b/Example/BasicExample/BasicExample/BasicExampleApp.swift index 69b1288..e24d784 100644 --- a/Example/BasicExample/BasicExample/BasicExampleApp.swift +++ b/Example/BasicExample/BasicExample/BasicExampleApp.swift @@ -7,6 +7,7 @@ import SwiftUI import Segment +import SegmentFlurry @main struct BasicExampleApp: App { @@ -22,7 +23,7 @@ extension Analytics { let analytics = Analytics(configuration: Configuration(writeKey: "") .flushAt(3) .trackApplicationLifecycleEvents(true)) - //analytics.add(plugin: ()) + analytics.add(plugin: FlurryDestination()) return analytics } } diff --git a/Package.swift b/Package.swift index 90c21c3..8f70b31 100644 --- a/Package.swift +++ b/Package.swift @@ -22,12 +22,12 @@ let package = Package( .package( name: "Segment", url: "https://github.com/segmentio/analytics-swift.git", - from: "1.1.2" + from: "1.5.2" ), .package( name: "Flurry", url: "https://github.com/flurry/FlurrySwiftPackage/", - from: "12.0.0" + from: "12.4.0" ), ], targets: [ diff --git a/README.md b/README.md index 9ed0e1f..7499407 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,83 @@ -# Swift Destination Plugin Template -This template is resolved around `ExampleDestination` (to be replaced by you). +# Analytics-Swift Flurry -## What does the template provide -### Data class for holding settings -To standardize fetching and using settings in your destination, we recommend using a Coable class to store your destination settings. If marked `Codable`, it will enable you to retrieve your destination settings in a strongly typed construct. +Add `Flurry` device mode support to your applications via this plugin for [Analytics-Swift](https://github.com/segmentio/analytics-swift) -### Settings-related functions -We provide APIs to update your destination settings in `update(settings:type:)`. -`UpdateType.initial` lets you know if this is the intial or subsequent fetch. +## Adding the dependency -`Settings.isDestinationEnabled(key: String)` -- check if your destination is enabled +***Note:** the `Flurry` library itself will be installed as an additional dependency.* -`Settings.integrationSettings(forKey: String)` -- retrieve a typed destination object +### via Xcode +In the Xcode `File` menu, click `Add Packages`. You'll see a dialog where you can search for Swift packages. In the search field, enter the URL to this repo. -### Sample implementation for common destination functions -We have templated common destinations functions like `track`, `identify`, `screen`, `group`, `alias` that you should modify to fit your vendor SDK implementation. Although these functions do not need to return the ending payload, its good practice to do so (for unit testing purposes). +``` +https://github.com/segment-integrations/analytics-swift-flurry +``` -### Transforming events -Often times, destinations need to transform events (eg: change names, modify properties/traits etc.). We have templated an example of transformation in the `track(event:)` example. we recommend you use this approach to perform any such transformations. This will make your code more legible plus improve code quality. +You'll then have the option to pin to a version, or specific branch, as well as which project in your workspace to add it to. Once you've made your selections, click the `Add Package` button. -### Testing functions for primary functions (to be expanded) -We have provided a very bare minimum template for testing the primary destination APIs. We recommend to use this as a starter and build upon it to get test coverage of most scenarios. +### via Package.swift + +Open your Package.swift file and add the following do your the `dependencies` section: + +``` +.package( + name: "Segment", + url: "https://github.com/segment-integrations/analytics-swift-flurry.git", + from: "1.1.3" + ), +``` + + +## Using the Plugin in your App + +Open the file where you setup and configure the Analytics-Swift library. Add this plugin to the list of imports. + +``` +import Segment +import SegmentFlurry // <-- Add this line +``` + +Just under your Analytics-Swift library setup, call `analytics.add(plugin: ...)` to add an instance of the plugin to the Analytics timeline. + +``` +let analytics = Analytics(configuration: Configuration(writeKey: "") + .flushAt(3) + .trackApplicationLifecycleEvents(true)) +analytics.add(plugin: FlurryDestination()) +``` + +Your events will now begin to flow to Flurry in device mode. + + +## Support + +Please use Github issues, Pull Requests, or feel free to reach out to our [support team](https://segment.com/help/). + +## Integrating with Segment + +Interested in integrating your service with us? Check out our [Partners page](https://segment.com/partners/) for more details. + +## License +``` +MIT License + +Copyright (c) 2021 Segment + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/Sources/SegmentFlurry/FlurryDestination.swift b/Sources/SegmentFlurry/FlurryDestination.swift index ace219d..29aabd0 100644 --- a/Sources/SegmentFlurry/FlurryDestination.swift +++ b/Sources/SegmentFlurry/FlurryDestination.swift @@ -34,25 +34,28 @@ import Foundation import Segment -import Flurry +import Flurry_iOS_SDK -/** - An implementation of the Flurry Analytics device mode destination as a plugin. - */ +@objc(SEGFlurryDestination) +public class ObjCSegmentFlurry: NSObject, ObjCPlugin, ObjCPluginShim { + public func instance() -> EventPlugin { return FlurryDestination() } +} -class FlurryDestination: DestinationPlugin { - let timeline = Timeline() - let type = PluginType.destination - let key = "Flurry" - weak var analytics: Analytics? = nil +public class FlurryDestination: DestinationPlugin { + public let timeline = Timeline() + public let type = PluginType.destination + public let key = "Flurry" + weak public var analytics: Analytics? = nil var screenTracksEvents = false - func update(settings: Settings, type: UpdateType) { + public init() { } + + public func update(settings: Settings, type: UpdateType) { // we've already set up this singleton SDK, can't do it again, so skip. guard type == .initial else { return } - guard let flurrySettings: FlurrySettings = settings.integrationSettings(forPlugin: self) else { return } + guard let flurrySettings: FlurrySettings = settings.integrationSettings(forKey: key) else { return } let builder = FlurrySessionBuilder() @@ -67,29 +70,27 @@ class FlurryDestination: DestinationPlugin { Flurry.startSession(apiKey: flurrySettings.apiKey, sessionBuilder: builder) } - func identify(event: IdentifyEvent) -> IdentifyEvent? { + public func identify(event: IdentifyEvent) -> IdentifyEvent? { Flurry.set(userId: event.userId) if let traits = event.traits?.dictionaryValue { if let gender = traits["gender"] as? String { Flurry.set(gender: String(gender.prefix(1))) } - if let value = traits["age"] as? String, let age = Int32(value) { Flurry.set(age: age) } } - return event } - func track(event: TrackEvent) -> TrackEvent? { + public func track(event: TrackEvent) -> TrackEvent? { let props = truncate(properties: event.properties?.dictionaryValue) Flurry.log(eventName: event.event, parameters: props) return event } - func screen(event: ScreenEvent) -> ScreenEvent? { + public func screen(event: ScreenEvent) -> ScreenEvent? { if screenTracksEvents { let props = truncate(properties: event.properties?.dictionaryValue) Flurry.log(eventName: "Viewed \(event.name ?? "") Screen", parameters: props)