Skip to content

Commit b55f0d4

Browse files
authored
pddFlag removal + tests for pdd restricted instance of Analytics (#86)
* `pddFlag` removal * Update example to use development constructor
1 parent 516995e commit b55f0d4

File tree

5 files changed

+18
-182
lines changed

5 files changed

+18
-182
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.1.1-dev
22

33
- Refactoring `dateStamp` utility function to be defined in `utils.dart` instead of having static methods in `Initializer` and `ConfigHandler`
4+
- Remove the `pddFlag` now that the revisions have been finalized to persist data in the log file and session json file
45

56
## 1.1.0
67

pkgs/unified_analytics/example/unified_analytics_example.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ final String apiSecret = '4yT8__oER3Cd84dtx6r-_A';
99

1010
// Globally instantiate the analytics class at the entry
1111
// point of the tool
12-
final Analytics analytics = Analytics(
12+
//
13+
// Development constructor used here so we don't push
14+
// to production when running
15+
final Analytics analytics = Analytics.development(
1316
tool: DashTool.flutterTool,
1417
flutterChannel: 'ey-test-channel',
1518
flutterVersion: 'Flutter 3.6.0-7.0.pre.47',

pkgs/unified_analytics/lib/src/analytics.dart

Lines changed: 11 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,17 @@ import 'user_property.dart';
2323
import 'utils.dart';
2424

2525
abstract class Analytics {
26-
// TODO: (eliasyishak) enable again once revision has landed;
27-
// also remove all instances of [pddFlag]
28-
29-
// /// The default factory constructor that will return an implementation
30-
// /// of the [Analytics] abstract class using the [LocalFileSystem]
31-
// factory Analytics({
32-
// required DashTool tool,
33-
// required String dartVersion,
34-
// String? flutterChannel,
35-
// String? flutterVersion,
36-
// }) {
37-
// // Create the instance of the file system so clients don't need
38-
// // resolve on their own
39-
// const FileSystem fs = LocalFileSystem();
40-
41-
// // Resolve the OS using dart:io
42-
// final DevicePlatform platform;
43-
// if (io.Platform.operatingSystem == 'linux') {
44-
// platform = DevicePlatform.linux;
45-
// } else if (io.Platform.operatingSystem == 'macos') {
46-
// platform = DevicePlatform.macos;
47-
// } else {
48-
// platform = DevicePlatform.windows;
49-
// }
50-
51-
// // Create the instance of the GA Client which will create
52-
// // an [http.Client] to send requests
53-
// final GAClient gaClient = GAClient(
54-
// measurementId: kGoogleAnalyticsMeasurementId,
55-
// apiSecret: kGoogleAnalyticsApiSecret,
56-
// );
57-
58-
// return AnalyticsImpl(
59-
// tool: tool,
60-
// homeDirectory: getHomeDirectory(fs),
61-
// flutterChannel: flutterChannel,
62-
// flutterVersion: flutterVersion,
63-
// dartVersion: dartVersion,
64-
// platform: platform,
65-
// toolsMessageVersion: kToolsMessageVersion,
66-
// fs: fs,
67-
// gaClient: gaClient,
68-
// );
69-
// }
70-
71-
// TODO: (eliasyishak) remove this contructor once revision has landed
72-
73-
/// Prevents the unapproved files for logging and session handling
74-
/// from being saved on to the developer's disk until privacy revision
75-
/// has landed
26+
/// The default factory constructor that will return an implementation
27+
/// of the [Analytics] abstract class using the [LocalFileSystem]
7628
factory Analytics({
7729
required DashTool tool,
7830
required String dartVersion,
7931
String? flutterChannel,
8032
String? flutterVersion,
81-
FileSystem? fsOverride,
82-
Directory? homeOverride,
83-
DevicePlatform? platformOverride,
8433
}) {
8534
// Create the instance of the file system so clients don't need
8635
// resolve on their own
87-
final FileSystem fs = fsOverride ?? LocalFileSystem();
36+
const FileSystem fs = LocalFileSystem();
8837

8938
// Resolve the OS using dart:io
9039
final DevicePlatform platform;
@@ -98,27 +47,21 @@ abstract class Analytics {
9847

9948
// Create the instance of the GA Client which will create
10049
// an [http.Client] to send requests
101-
//
102-
// When a [fsOverride] is passed in, we can assume to
103-
// use the fake Google Analytics client
104-
final GAClient gaClient = fsOverride != null
105-
? FakeGAClient()
106-
: GAClient(
107-
measurementId: kGoogleAnalyticsMeasurementId,
108-
apiSecret: kGoogleAnalyticsApiSecret,
109-
);
50+
final GAClient gaClient = GAClient(
51+
measurementId: kGoogleAnalyticsMeasurementId,
52+
apiSecret: kGoogleAnalyticsApiSecret,
53+
);
11054

11155
return AnalyticsImpl(
11256
tool: tool,
113-
homeDirectory: homeOverride ?? getHomeDirectory(fs),
57+
homeDirectory: getHomeDirectory(fs),
11458
flutterChannel: flutterChannel,
11559
flutterVersion: flutterVersion,
11660
dartVersion: dartVersion,
117-
platform: platformOverride ?? platform,
61+
platform: platform,
11862
toolsMessageVersion: kToolsMessageVersion,
11963
fs: fs,
12064
gaClient: gaClient,
121-
pddFlag: true,
12265
);
12366
}
12467

@@ -295,7 +238,6 @@ class AnalyticsImpl implements Analytics {
295238
required this.toolsMessageVersion,
296239
required this.fs,
297240
required gaClient,
298-
bool pddFlag = false,
299241
}) : _gaClient = gaClient {
300242
// Initialize date formatting for `package:intl` within constructor
301243
// so clients using this package won't need to
@@ -309,7 +251,6 @@ class AnalyticsImpl implements Analytics {
309251
tool: tool.label,
310252
homeDirectory: homeDirectory,
311253
toolsMessageVersion: toolsMessageVersion,
312-
pddFlag: pddFlag,
313254
);
314255
initializer.run();
315256
_showMessage = initializer.firstRun;
@@ -345,21 +286,12 @@ class AnalyticsImpl implements Analytics {
345286
homeDirectory.path, kDartToolDirectoryName, kClientIdFileName))
346287
.readAsStringSync();
347288

348-
// Create the session instance that will be responsible for managing
349-
// all the sessions across every client tool using this pakage
350-
final Session session;
351-
if (pddFlag) {
352-
session = NoopSession();
353-
} else {
354-
session = Session(homeDirectory: homeDirectory, fs: fs);
355-
}
356-
357289
// Initialize the user property class that will be attached to
358290
// each event that is sent to Google Analytics -- it will be responsible
359291
// for getting the session id or rolling the session if the duration
360292
// exceeds [kSessionDurationMinutes]
361293
userProperty = UserProperty(
362-
session: session,
294+
session: Session(homeDirectory: homeDirectory, fs: fs),
363295
flutterChannel: flutterChannel,
364296
host: platform.label,
365297
flutterVersion: flutterVersion,
@@ -368,11 +300,7 @@ class AnalyticsImpl implements Analytics {
368300
);
369301

370302
// Initialize the log handler to persist events that are being sent
371-
if (pddFlag) {
372-
_logHandler = NoopLogHandler();
373-
} else {
374-
_logHandler = LogHandler(fs: fs, homeDirectory: homeDirectory);
375-
}
303+
_logHandler = LogHandler(fs: fs, homeDirectory: homeDirectory);
376304
}
377305

378306
@override

pkgs/unified_analytics/lib/src/initializer.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Initializer {
1717
final Directory homeDirectory;
1818
final int toolsMessageVersion;
1919
bool firstRun = false;
20-
final bool pddFlag;
2120

2221
/// Responsibe for the initialization of the files
2322
/// necessary for analytics reporting
@@ -33,7 +32,6 @@ class Initializer {
3332
required this.tool,
3433
required this.homeDirectory,
3534
required this.toolsMessageVersion,
36-
required this.pddFlag,
3735
});
3836

3937
/// Creates the text file that will contain the client ID
@@ -118,14 +116,14 @@ class Initializer {
118116
// Begin initialization checks for the session file
119117
final File sessionFile = fs.file(
120118
p.join(homeDirectory.path, kDartToolDirectoryName, kSessionFileName));
121-
if (!sessionFile.existsSync() && !pddFlag) {
119+
if (!sessionFile.existsSync()) {
122120
createSessionFile(sessionFile: sessionFile);
123121
}
124122

125123
// Begin initialization checks for the log file to persist events locally
126124
final File logFile = fs
127125
.file(p.join(homeDirectory.path, kDartToolDirectoryName, kLogFileName));
128-
if (!logFile.existsSync() && !pddFlag) {
126+
if (!logFile.existsSync()) {
129127
createLogFile(logFile: logFile);
130128
}
131129
}

pkgs/unified_analytics/test/pdd_approved_test.dart

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)