@@ -32,11 +32,11 @@ private enum GoogleDataTransportConfig {
32
32
private let appID : String
33
33
34
34
/// Top-level Classes in the Sessions SDK
35
- private let coordinator : SessionCoordinator
35
+ private let coordinator : SessionCoordinatorProtocol
36
36
private let initiator : SessionInitiator
37
37
private let sessionGenerator : SessionGenerator
38
- private let appInfo : ApplicationInfo
39
- private let settings : SessionsSettings
38
+ private let appInfo : ApplicationInfoProtocol
39
+ private let settings : SettingsProtocol
40
40
41
41
/// Subscribers
42
42
/// `subscribers` are used to determine the Data Collection state of the Sessions SDK.
@@ -82,12 +82,50 @@ private enum GoogleDataTransportConfig {
82
82
coordinator: coordinator,
83
83
initiator: initiator,
84
84
appInfo: appInfo,
85
- settings: settings)
85
+ settings: settings) { result in
86
+ switch result {
87
+ case . success( ( ) ) :
88
+ Logger . logInfo ( " Successfully logged Session Start event " )
89
+ case let . failure( sessionsError) :
90
+ switch sessionsError {
91
+ case let . SessionInstallationsError( error) :
92
+ Logger . logError (
93
+ " Error getting Firebase Installation ID: \( error) . Skipping this Session Event "
94
+ )
95
+ case let . DataTransportError( error) :
96
+ Logger
97
+ . logError (
98
+ " Error logging Session Start event to GoogleDataTransport: \( error) . "
99
+ )
100
+ case . NoDependenciesError:
101
+ Logger
102
+ . logError (
103
+ " Sessions SDK did not have any dependent SDKs register as dependencies. Events will not be sent. "
104
+ )
105
+ case . SessionSamplingError:
106
+ Logger
107
+ . logDebug (
108
+ " Sessions SDK has sampled this session "
109
+ )
110
+ case . DisabledViaSettingsError:
111
+ Logger
112
+ . logDebug (
113
+ " Sessions SDK is disabled via Settings "
114
+ )
115
+ case . DataCollectionError:
116
+ Logger
117
+ . logDebug (
118
+ " Data Collection is disabled for all subscribers. Skipping this Session Event "
119
+ )
120
+ }
121
+ }
122
+ }
86
123
}
87
124
88
125
// Initializes the SDK and begines the process of listening for lifecycle events and logging events
89
- init ( appID: String , sessionGenerator: SessionGenerator , coordinator: SessionCoordinator ,
90
- initiator: SessionInitiator , appInfo: ApplicationInfo , settings: SessionsSettings ) {
126
+ init ( appID: String , sessionGenerator: SessionGenerator , coordinator: SessionCoordinatorProtocol ,
127
+ initiator: SessionInitiator , appInfo: ApplicationInfoProtocol , settings: SettingsProtocol ,
128
+ loggedEventCallback: @escaping ( Result < Void , FirebaseSessionsError > ) -> Void ) {
91
129
self . appID = appID
92
130
93
131
self . sessionGenerator = sessionGenerator
@@ -115,14 +153,18 @@ private enum GoogleDataTransportConfig {
115
153
116
154
let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: self . appInfo)
117
155
156
+ // If there are no Dependencies, then the Sessions SDK can't acknowledge
157
+ // any products data collection state, so the Sessions SDK won't send events.
158
+ guard !self . subscriberPromises. isEmpty else {
159
+ loggedEventCallback ( . failure( . NoDependenciesError) )
160
+ return
161
+ }
162
+
118
163
// Wait until all subscriber promises have been fulfilled before
119
164
// doing any data collection.
120
165
all ( self . subscriberPromises. values) . then ( on: . global( qos: . background) ) { _ in
121
166
guard self . isAnyDataCollectionEnabled else {
122
- Logger
123
- . logDebug (
124
- " Data Collection is disabled for all subscribers. Skipping this Session Event "
125
- )
167
+ loggedEventCallback ( . failure( . DataCollectionError) )
126
168
return
127
169
}
128
170
@@ -136,15 +178,18 @@ private enum GoogleDataTransportConfig {
136
178
137
179
self . addEventDataCollectionState ( event: event)
138
180
139
- if !( self . settings. sessionsEnabled && sessionInfo. shouldDispatchEvents) {
140
- Logger
141
- . logDebug (
142
- " Session Event logging is disabled sessionsEnabled: \( self . settings. sessionsEnabled) , shouldDispatchEvents: \( sessionInfo. shouldDispatchEvents) "
143
- )
181
+ guard sessionInfo. shouldDispatchEvents else {
182
+ loggedEventCallback ( . failure( . SessionSamplingError) )
183
+ return
184
+ }
185
+
186
+ guard self . settings. sessionsEnabled else {
187
+ loggedEventCallback ( . failure( . DisabledViaSettingsError) )
144
188
return
145
189
}
146
190
147
191
self . coordinator. attemptLoggingSessionStart ( event: event) { result in
192
+ loggedEventCallback ( result)
148
193
}
149
194
}
150
195
}
0 commit comments