@@ -27,10 +27,13 @@ import 'utils.dart';
27
27
28
28
abstract class Analytics {
29
29
/// The default factory constructor that will return an implementation
30
- /// of the [Analytics] abstract class using the [LocalFileSystem]
30
+ /// of the [Analytics] abstract class using the [LocalFileSystem] .
31
31
///
32
32
/// If [enableAsserts] is set to `true` , then asserts for GA4 limitations
33
- /// will be enabled
33
+ /// will be enabled.
34
+ ///
35
+ /// [flutterChannel] and [flutterVersion] are nullable in case the client
36
+ /// using this package is unable to resolve those values.
34
37
factory Analytics ({
35
38
required DashTool tool,
36
39
required String dartVersion,
@@ -83,10 +86,13 @@ abstract class Analytics {
83
86
84
87
/// Factory constructor to return the [AnalyticsImpl] class with
85
88
/// Google Analytics credentials that point to a test instance and
86
- /// not the production instance where live data will be sent
89
+ /// not the production instance where live data will be sent.
87
90
///
88
91
/// By default, [enableAsserts] is set to `true` to check against
89
- /// GA4 limitations
92
+ /// GA4 limitations.
93
+ ///
94
+ /// [flutterChannel] and [flutterVersion] are nullable in case the client
95
+ /// using this package is unable to resolve those values.
90
96
factory Analytics .development ({
91
97
required DashTool tool,
92
98
required String dartVersion,
@@ -142,22 +148,22 @@ abstract class Analytics {
142
148
}
143
149
144
150
/// Factory constructor to return the [AnalyticsImpl] class with a
145
- /// [MemoryFileSystem] to use for testing
151
+ /// [MemoryFileSystem] to use for testing.
146
152
@visibleForTesting
147
153
factory Analytics .test ({
148
154
required DashTool tool,
149
155
required Directory homeDirectory,
150
156
required String measurementId,
151
157
required String apiSecret,
152
- String ? flutterChannel,
153
- String ? flutterVersion,
154
158
required String dartVersion,
155
- int toolsMessageVersion = kToolsMessageVersion,
156
- String toolsMessage = kToolsMessage,
157
159
required FileSystem fs,
158
160
required DevicePlatform platform,
161
+ String ? flutterChannel,
162
+ String ? flutterVersion,
159
163
SurveyHandler ? surveyHandler,
160
164
GAClient ? gaClient,
165
+ int toolsMessageVersion = kToolsMessageVersion,
166
+ String toolsMessage = kToolsMessage,
161
167
}) =>
162
168
AnalyticsImpl (
163
169
tool: tool,
@@ -179,57 +185,57 @@ abstract class Analytics {
179
185
);
180
186
181
187
/// Retrieves the consent message to prompt users with on first
182
- /// run or when the message has been updated
188
+ /// run or when the message has been updated.
183
189
String get getConsentMessage;
184
190
185
- /// Returns true if it is OK to send an analytics message. Do not cache,
191
+ /// Returns true if it is OK to send an analytics message. Do not cache,
186
192
/// as this depends on factors that can change, such as the configuration
187
193
/// file contents.
188
194
bool get okToSend;
189
195
190
196
/// Returns a map object with all of the tools that have been parsed
191
- /// out of the configuration file
197
+ /// out of the configuration file.
192
198
Map <String , ToolInfo > get parsedTools;
193
199
194
- /// Boolean that lets the client know if they should display the message
200
+ /// Boolean that lets the client know if they should display the message.
195
201
bool get shouldShowMessage;
196
202
197
- /// Boolean indicating whether or not telemetry is enabled
203
+ /// Boolean indicating whether or not telemetry is enabled.
198
204
bool get telemetryEnabled;
199
205
200
206
/// Returns a map representation of the [UserProperty] for the [Analytics]
201
207
/// instance.
202
208
///
203
- /// This is what will get sent to Google Analytics with every request
209
+ /// This is what will get sent to Google Analytics with every request.
204
210
Map <String , Map <String , Object ?>> get userPropertyMap;
205
211
206
212
/// Method to be invoked by the client using this package to confirm
207
213
/// that the client has shown the message and that it can be added to
208
- /// the config file and start sending events the next time it starts up
214
+ /// the config file and start sending events the next time it starts up.
209
215
void clientShowedMessage ();
210
216
211
- /// Call this method when the tool using this package is closed
217
+ /// Call this method when the tool using this package is closed.
212
218
///
213
219
/// Prevents the tool from hanging when if there are still requests
214
- /// that need to be sent off
220
+ /// that need to be sent off.
215
221
void close ();
216
222
217
- /// Method to fetch surveys from the specified endpoint [kContextualSurveyUrl]
223
+ /// Method to fetch surveys from the endpoint [kContextualSurveyUrl] .
218
224
///
219
225
/// Any survey that is returned by this method has already passed
220
- /// the survey conditions specified in the remote survey metadata file
226
+ /// the survey conditions specified in the remote survey metadata file.
221
227
///
222
228
/// If the method returns an empty list, then there are no surveys to be
223
- /// shared with the user
229
+ /// shared with the user.
224
230
Future <List <Survey >> fetchAvailableSurveys ();
225
231
226
- /// Query the persisted event data stored on the user's machine
232
+ /// Query the persisted event data stored on the user's machine.
227
233
///
228
- /// Returns null if there are no persisted logs
234
+ /// Returns null if there are no persisted logs.
229
235
LogFileStats ? logFileStats ();
230
236
231
237
/// Send preconfigured events using specific named constructors
232
- /// on the [Event] class
238
+ /// on the [Event] class.
233
239
///
234
240
/// Example
235
241
/// ```dart
@@ -238,33 +244,37 @@ abstract class Analytics {
238
244
Future <Response >? send (Event event);
239
245
240
246
/// Pass a boolean to either enable or disable telemetry and make
241
- /// the necessary changes in the persisted configuration file
247
+ /// the necessary changes in the persisted configuration file.
242
248
///
243
249
/// Setting the telemetry status will also send an event to GA
244
- /// indicating the latest status of the telemetry from [reportingBool]
250
+ /// indicating the latest status of the telemetry from [reportingBool] .
245
251
Future <void > setTelemetry (bool reportingBool);
246
252
247
253
/// Calling this will result in telemetry collection being suppressed for
248
- /// the current invocation
254
+ /// the current invocation.
249
255
///
250
256
/// If you would like to permanently disable telemetry
251
- /// collection use `setTelemetry(false)`
257
+ /// collection use:
258
+ ///
259
+ /// ```dart
260
+ /// analytics.setTelemetry(false)
261
+ /// ```
252
262
void suppressTelemetry ();
253
263
254
- /// Method to run after interacting with a [Survey]
264
+ /// Method to run after interacting with a [Survey] instance.
255
265
///
256
266
/// Pass a [Survey] instance which can be retrieved from
257
- /// ` fetchAvailableSurveys()`
267
+ /// [Analytics. fetchAvailableSurveys] .
258
268
///
259
- /// [surveyButton] is the button that was interacted with by the user
269
+ /// [surveyButton] is the button that was interacted with by the user.
260
270
void surveyInteracted ({
261
271
required Survey survey,
262
272
required SurveyButton surveyButton,
263
273
});
264
274
265
- /// Method to be called after a survey has been shown to the user
275
+ /// Method to be called after a survey has been shown to the user.
266
276
///
267
- /// Calling this will snooze the survey so it won't be shown immediately
277
+ /// Calling this will snooze the survey so it won't be shown immediately.
268
278
///
269
279
/// The snooze period is defined by the [Survey.snoozeForMinutes] field.
270
280
void surveyShown (Survey survey);
@@ -286,27 +296,27 @@ class AnalyticsImpl implements Analytics {
286
296
/// Tells the client if they need to show a message to the
287
297
/// user; this will return true if it is the first time the
288
298
/// package is being used for a developer or if the consent
289
- /// message has been updated by the package
299
+ /// message has been updated by the package.
290
300
late bool _showMessage;
291
301
292
302
/// This will be switch to true once it has been confirmed by the
293
- /// client using this package that they have shown this message
294
- /// to the developer
303
+ /// client using this package that they have shown the
304
+ /// consent message to the developer.
295
305
///
296
306
/// If the tool using this package as already shown the consent message
297
- /// and it has been added to the config file, it will be set as true
307
+ /// and it has been added to the config file, it will be set as true.
298
308
///
299
309
/// It will also be set to true once the tool using this package has
300
- /// invoked [clientShowedMessage]
310
+ /// invoked [clientShowedMessage] .
301
311
///
302
- /// If this is false, all events will be blocked from being sent
312
+ /// If this is false, all events will be blocked from being sent.
303
313
bool _clientShowedMessage = false ;
304
314
305
315
/// When set to `true` , various assert statements will be enabled
306
- /// to ensure usage of this class is within GA4 limitations
316
+ /// to ensure usage of this class is within GA4 limitations.
307
317
final bool _enableAsserts;
308
318
309
- /// Telemetry suppression flag that is set via ` suppressTelemetry()`
319
+ /// Telemetry suppression flag that is set via [Analytics. suppressTelemetry] .
310
320
bool _telemetrySuppressed = false ;
311
321
312
322
AnalyticsImpl ({
@@ -399,18 +409,18 @@ class AnalyticsImpl implements Analytics {
399
409
}
400
410
401
411
/// Checking the [telemetryEnabled] boolean reflects what the
402
- /// config file reflects
412
+ /// config file reflects.
403
413
///
404
414
/// Checking the [_showMessage] boolean indicates if this the first
405
415
/// time the tool is using analytics or if there has been an update
406
416
/// the messaging found in constants.dart - in both cases, analytics
407
- /// will not be sent until the second time the tool is used
417
+ /// will not be sent until the second time the tool is used.
408
418
///
409
- /// Additionally, if the client has not invoked `clientShowedMessage` ,
410
- /// then no events shall be sent.
419
+ /// Additionally, if the client has not invoked
420
+ /// [Analytics.clientShowedMessage] , then no events shall be sent.
411
421
///
412
422
/// If the user has suppressed telemetry [_telemetrySuppressed] will
413
- /// return `true` to prevent events from being sent for current invocation
423
+ /// return `true` to prevent events from being sent for current invocation.
414
424
@override
415
425
bool get okToSend =>
416
426
telemetryEnabled &&
0 commit comments