@@ -57,25 +57,28 @@ public class Analytics {
57
57
private let commandersActService = CommandersActService ( )
58
58
59
59
private weak var dataSource : AnalyticsDataSource ?
60
+ private weak var delegate : AnalyticsDelegate ?
60
61
61
62
private init ( ) { }
62
63
63
64
/// Starts analytics with the specified configuration.
64
65
///
65
66
/// - Parameters:
66
67
/// - configuration: The configuration to use.
67
- /// - dataSource: The data source to use.
68
+ /// - dataSource: The object that acts as the data source of the analytics.
69
+ /// - delegate: The object that acts as the delegate of the analytics.
68
70
///
69
71
/// This method must be called from your `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)`
70
72
/// delegate method implementation, otherwise the behavior is undefined.
71
73
///
72
74
/// The method throws if called more than once.
73
- public func start( with configuration: Configuration , dataSource: AnalyticsDataSource ? = nil ) throws {
75
+ public func start( with configuration: Configuration , dataSource: AnalyticsDataSource ? = nil , delegate : AnalyticsDelegate ? = nil ) throws {
74
76
guard self . configuration == nil else {
75
77
throw AnalyticsError . alreadyStarted
76
78
}
77
79
self . configuration = configuration
78
80
self . dataSource = dataSource
81
+ self . delegate = delegate
79
82
80
83
UIViewController . setupViewControllerTracking ( )
81
84
@@ -90,22 +93,22 @@ public class Analytics {
90
93
commandersActService. trackPageView (
91
94
commandersActPageView. merging ( globals: dataSource? . commandersActGlobals)
92
95
)
96
+ delegate? . didTrackPageView ( commandersAct: commandersActPageView)
93
97
}
94
98
95
99
/// Sends an event.
96
100
///
97
101
/// - Parameter commandersActEvent: The Commanders Act event data.
98
102
public func sendEvent( commandersAct commandersActEvent: CommandersActEvent ) {
103
+ sendCommandersActEvent ( commandersActEvent)
104
+ delegate? . didSendEvent ( commandersAct: commandersActEvent)
105
+ }
106
+ }
107
+
108
+ extension Analytics {
109
+ func sendCommandersActEvent( _ commandersActEvent: CommandersActEvent ) {
99
110
commandersActService. sendEvent (
100
111
commandersActEvent. merging ( globals: dataSource? . commandersActGlobals)
101
112
)
102
113
}
103
114
}
104
-
105
- public extension String {
106
- /// The source key for apps in production.
107
- static let productionSourceKey = " 1b30366c-9e8d-4720-8b12-4165f468f9ae "
108
-
109
- /// The source key for apps in development.
110
- static let developmentSourceKey = " 39ae8f94-595c-4ca4-81f7-fb7748bd3f04 "
111
- }
0 commit comments