Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
analytics = Analytics(configuration: configuration)

// Add Adjust destination plugin
analytics?.add(plugin: AdjustDestination(name: "Adjust"))
analytics?.add(plugin: AdjustDestination())

// Add Amplitude session plugin
analytics?.add(plugin: AmplitudeSession(name: "Amplitude"))
analytics?.add(plugin: AmplitudeSession())

// Add Mixpanel destination plugin
analytics?.add(plugin: MixpanelDestination(name: "Mixpanel"))
analytics?.add(plugin: MixpanelDestination())

// Add Flurry destination plugin
analytics?.add(plugin: FlurryDestination(name: "Flurry"))
analytics?.add(plugin: FlurryDestination())

// Add the Firebase destination plugin
analytics?.add(plugin: FirebaseDestination(name: "Firebase"))
analytics?.add(plugin: FirebaseDestination())

//Add the AppsFlyer destination plugin
analytics?.add(plugin: AppsFlyerDestination(name: "AppsFlyer"))
analytics?.add(plugin: AppsFlyerDestination())

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
46016C1326BB5BD700BCEE80 /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 46016C1226BB5BD700BCEE80 /* Segment */; };
9613E655265C2E350078A2BD /* SegmentSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9613E654265C2E350078A2BD /* SegmentSwiftUIExampleApp.swift */; };
9613E657265C2E350078A2BD /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9613E656265C2E350078A2BD /* ContentView.swift */; };
9613E659265C2E360078A2BD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9613E658265C2E360078A2BD /* Assets.xcassets */; };
9613E65C265C2E360078A2BD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9613E65B265C2E360078A2BD /* Preview Assets.xcassets */; };
9613E665265C2E880078A2BD /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 9613E664265C2E880078A2BD /* Segment */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -28,18 +28,26 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9613E665265C2E880078A2BD /* Segment in Frameworks */,
46016C1326BB5BD700BCEE80 /* Segment in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
46016C1126BB5BD700BCEE80 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
9613E648265C2E350078A2BD = {
isa = PBXGroup;
children = (
9613E653265C2E350078A2BD /* SegmentSwiftUIExample */,
9613E652265C2E350078A2BD /* Products */,
46016C1126BB5BD700BCEE80 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -88,7 +96,7 @@
);
name = SegmentSwiftUIExample;
packageProductDependencies = (
9613E664265C2E880078A2BD /* Segment */,
46016C1226BB5BD700BCEE80 /* Segment */,
);
productName = SegmentSwiftUIExample;
productReference = 9613E651265C2E350078A2BD /* SegmentSwiftUIExample.app */;
Expand Down Expand Up @@ -118,7 +126,6 @@
);
mainGroup = 9613E648265C2E350078A2BD;
packageReferences = (
9613E663265C2E880078A2BD /* XCRemoteSwiftPackageReference "analytics-swift" */,
);
productRefGroup = 9613E652265C2E350078A2BD /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -335,21 +342,9 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
9613E663265C2E880078A2BD /* XCRemoteSwiftPackageReference "analytics-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "[email protected]:segmentio/analytics-swift.git";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
9613E664265C2E880078A2BD /* Segment */ = {
46016C1226BB5BD700BCEE80 /* Segment */ = {
isa = XCSwiftPackageProductDependency;
package = 9613E663265C2E880078A2BD /* XCRemoteSwiftPackageReference "analytics-swift" */;
productName = Segment;
};
/* End XCSwiftPackageProductDependency section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// add console logging plugins to our multiple instances
Analytics.main.add(plugin: ConsoleLogger(name: "main"))
Analytics.main.add(plugin: ConsentTracking(name: "consent"))
Analytics.main.add(plugin: IDFACollection(name: "idfa"))
Analytics.main.add(plugin: UIKitScreenTracking(name: "autoScreenTracking"))
Analytics.main.add(plugin: ConsentTracking())
Analytics.main.add(plugin: IDFACollection())
Analytics.main.add(plugin: UIKitScreenTracking())

Analytics.support.add(plugin: ConsoleLogger(name: "support"))
Analytics.support.add(plugin: ConsentTracking(name: "consent"))
Analytics.support.add(plugin: ConsentTracking())

Analytics.support.track(name: "test event")

Expand Down
16 changes: 6 additions & 10 deletions Examples/destination_plugins/AdjustDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ internal struct AdjustSettings: Codable {
}

@objc
public class AdjustDestination: NSObject, DestinationPlugin, RemoteNotifications {
public let timeline: Timeline = Timeline()
public let type: PluginType = .destination
public let name: String
public var analytics: Analytics? = nil
class AdjustDestination: NSObject, DestinationPlugin, RemoteNotifications {
let timeline = Timeline()
let type = PluginType.destination
let key = "Adjust"
var analytics: Analytics? = nil

internal var settings: AdjustSettings? = nil

required public init(name: String) {
self.name = name
}

public func update(settings: Settings) {
guard let settings: AdjustSettings = settings.integrationSettings(name: "Adjust") else { return }
guard let settings: AdjustSettings = settings.integrationSettings(forPlugin: self) else { return }
self.settings = settings

var environment = ADJEnvironmentSandbox
Expand Down
43 changes: 35 additions & 8 deletions Examples/destination_plugins/AmplitudeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,45 @@ import Foundation
import Segment

class AmplitudeSession: EventPlugin, iOSLifecycle {

var type: PluginType
var name: String
var key = "Amplitude"
var type = PluginType.enrichment
var analytics: Analytics?

var active = false

private var sessionTimer: Timer?
private var sessionID: TimeInterval?
private let fireTime = TimeInterval(300)

required init(name: String) {
self.name = name
self.type = .enrichment
func update(settings: Settings) {
if settings.isDestinationEnabled(key: key) {
active = true
} else {
active = false
}
}

func execute<T: RawEvent>(event: T?) -> T? {
if !active {
return event
}

var result: T? = event
switch result {
case let r as IdentifyEvent:
result = self.identify(event: r) as? T
case let r as TrackEvent:
result = self.track(event: r) as? T
case let r as ScreenEvent:
result = self.screen(event: r) as? T
case let r as AliasEvent:
result = self.alias(event: r) as? T
case let r as GroupEvent:
result = self.group(event: r) as? T
default:
break
}
return result
}

func track(event: TrackEvent) -> TrackEvent? {
Expand Down Expand Up @@ -101,15 +128,15 @@ class AmplitudeSession: EventPlugin, iOSLifecycle {
}
}


// MARK: - AmplitudeSession Helper Methods
extension AmplitudeSession {

func insertSession(event: RawEvent) -> RawEvent {
var returnEvent = event
if var integrations = event.integrations?.dictionaryValue,
let sessionID = sessionID {

integrations["Amplitude"] = ["session_id": (Int(sessionID) * 1000)]
integrations[key] = ["session_id": (Int(sessionID) * 1000)]
returnEvent.integrations = try? JSON(integrations as Any)
}
return returnEvent
Expand Down
13 changes: 4 additions & 9 deletions Examples/destination_plugins/AppsFlyerDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,17 @@ private struct AppsFlyerSettings: Codable {

@objc
class AppsFlyerDestination: UIResponder, DestinationPlugin, RemoteNotifications, iOSLifecycle {
let timeline = Timeline()
let type = PluginType.destination
let key = "AppsFlyer"

let timeline: Timeline = Timeline()
let type: PluginType = .destination
let name: String
var analytics: Analytics?

fileprivate var settings: AppsFlyerSettings? = nil

required init(name: String) {
self.name = name
analytics?.track(name: "AppsFlyer Loaded")
}

public func update(settings: Settings) {

guard let settings: AppsFlyerSettings = settings.integrationSettings(name: "AppsFlyer") else { return }
guard let settings: AppsFlyerSettings = settings.integrationSettings(forPlugin: self) else { return }
self.settings = settings

AppsFlyerLib.shared().appsFlyerDevKey = settings.appsFlyerDevKey
Expand Down
18 changes: 9 additions & 9 deletions Examples/destination_plugins/FirebaseDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ import FirebaseAnalytics
An implmentation of the Firebase Analytics device mode destination as a plugin.
*/

struct FirebaseSettings: Codable {
let deepLinkURLScheme: String?
}

class FirebaseDestination: DestinationPlugin {
let timeline: Timeline = Timeline()
let type: PluginType = .destination
let name: String
let timeline = Timeline()
let type = PluginType.destination
let key = "Firebase"
var analytics: Segment.Analytics? = nil

required init(name: String) {
self.name = name
}

func update(settings: Settings) {
guard let firebaseSettings = settings.integrationSettings(for: "Firebase") else { return }
if let deepLinkURLScheme = firebaseSettings["deepLinkURLScheme"] as? String {
guard let firebaseSettings: FirebaseSettings = settings.integrationSettings(forPlugin: self) else { return }
if let deepLinkURLScheme = firebaseSettings.deepLinkURLScheme {
FirebaseOptions.defaultOptions()?.deepLinkURLScheme = deepLinkURLScheme
analytics?.log(message: "Added deepLinkURLScheme: \(deepLinkURLScheme)")
}
Expand Down
26 changes: 14 additions & 12 deletions Examples/destination_plugins/FlurryDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,35 @@ import FlurryAnalytics
An implmentation of the Flurry Analytics device mode destination as a plugin.
*/

private struct FlurrySettings: Codable {
let apiKey: String
let sessionContinueSeconds: Int?
let screenTracksEvents: Bool?
}


class FlurryDestination: DestinationPlugin {
let timeline: Timeline = Timeline()
let type: PluginType = .destination
let name: String
let timeline = Timeline()
let type = PluginType.destination
let key = "Flurry"
var analytics: Analytics? = nil

var screenTracksEvents = false

required init(name: String) {
self.name = name
}

func update(settings: Settings) {
guard let jsonSettings = settings.integrationSettings(for: "Flurry") else { return }
guard let flurryApiKey = jsonSettings["apiKey"] as? String else { return }
guard let flurrySettings: FlurrySettings = settings.integrationSettings(forPlugin: self) else { return }

let builder = FlurrySessionBuilder()

if let sessionContinueSeconds = jsonSettings["sessionContinueSeconds"] as? Int {
if let sessionContinueSeconds = flurrySettings.sessionContinueSeconds {
builder.withSessionContinueSeconds(sessionContinueSeconds)
}

if let screenTracksEvents = jsonSettings["screenTracksEvents"] as? Bool {
if let screenTracksEvents = flurrySettings.screenTracksEvents {
self.screenTracksEvents = screenTracksEvents
}

Flurry.startSession(flurryApiKey, with: builder)
Flurry.startSession(flurrySettings.apiKey, with: builder)
}

func identify(event: IdentifyEvent) -> IdentifyEvent? {
Expand Down
16 changes: 5 additions & 11 deletions Examples/destination_plugins/MixpanelDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,21 @@ import Mixpanel
import Segment

class MixpanelDestination: DestinationPlugin, RemoteNotifications {

var type: PluginType
var name: String
let timeline = Timeline()
let type = PluginType.destination
let key = "Mixpanel"
var analytics: Analytics?
var timeline: Timeline

private var mixpanel: MixpanelInstance? = nil
private var settings: [String: Any]? = nil

required init(name: String) {
self.name = name
type = .destination
self.timeline = Timeline()
}

func update(settings: Settings) {

// If we have a mixpanel instance, dump all the data first
mixpanel?.flush()

// TODO: Update the proper types
if let mixPanelSettings = settings.integrationSettings(for: "Mixpanel"),
if let mixPanelSettings = settings.integrationSettings(forKey: key),
let token = mixPanelSettings["token"] as? String {
self.settings = mixPanelSettings
mixpanel = Mixpanel.initialize(token: token)
Expand Down
Loading