diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 8e3a0552c0..a76ee94740 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.1.1-dev - Refactoring `dateStamp` utility function to be defined in `utils.dart` instead of having static methods in `Initializer` and `ConfigHandler` +- Remove the `pddFlag` now that the revisions have been finalized to persist data in the log file and session json file ## 1.1.0 diff --git a/pkgs/unified_analytics/example/unified_analytics_example.dart b/pkgs/unified_analytics/example/unified_analytics_example.dart index 8cc68a9fbf..775c3eae79 100644 --- a/pkgs/unified_analytics/example/unified_analytics_example.dart +++ b/pkgs/unified_analytics/example/unified_analytics_example.dart @@ -9,7 +9,10 @@ final String apiSecret = '4yT8__oER3Cd84dtx6r-_A'; // Globally instantiate the analytics class at the entry // point of the tool -final Analytics analytics = Analytics( +// +// Development constructor used here so we don't push +// to production when running +final Analytics analytics = Analytics.development( tool: DashTool.flutterTool, flutterChannel: 'ey-test-channel', flutterVersion: 'Flutter 3.6.0-7.0.pre.47', diff --git a/pkgs/unified_analytics/lib/src/analytics.dart b/pkgs/unified_analytics/lib/src/analytics.dart index da6786158e..2d67a59e79 100644 --- a/pkgs/unified_analytics/lib/src/analytics.dart +++ b/pkgs/unified_analytics/lib/src/analytics.dart @@ -23,68 +23,17 @@ import 'user_property.dart'; import 'utils.dart'; abstract class Analytics { - // TODO: (eliasyishak) enable again once revision has landed; - // also remove all instances of [pddFlag] - - // /// The default factory constructor that will return an implementation - // /// of the [Analytics] abstract class using the [LocalFileSystem] - // factory Analytics({ - // required DashTool tool, - // required String dartVersion, - // String? flutterChannel, - // String? flutterVersion, - // }) { - // // Create the instance of the file system so clients don't need - // // resolve on their own - // const FileSystem fs = LocalFileSystem(); - - // // Resolve the OS using dart:io - // final DevicePlatform platform; - // if (io.Platform.operatingSystem == 'linux') { - // platform = DevicePlatform.linux; - // } else if (io.Platform.operatingSystem == 'macos') { - // platform = DevicePlatform.macos; - // } else { - // platform = DevicePlatform.windows; - // } - - // // Create the instance of the GA Client which will create - // // an [http.Client] to send requests - // final GAClient gaClient = GAClient( - // measurementId: kGoogleAnalyticsMeasurementId, - // apiSecret: kGoogleAnalyticsApiSecret, - // ); - - // return AnalyticsImpl( - // tool: tool, - // homeDirectory: getHomeDirectory(fs), - // flutterChannel: flutterChannel, - // flutterVersion: flutterVersion, - // dartVersion: dartVersion, - // platform: platform, - // toolsMessageVersion: kToolsMessageVersion, - // fs: fs, - // gaClient: gaClient, - // ); - // } - - // TODO: (eliasyishak) remove this contructor once revision has landed - - /// Prevents the unapproved files for logging and session handling - /// from being saved on to the developer's disk until privacy revision - /// has landed + /// The default factory constructor that will return an implementation + /// of the [Analytics] abstract class using the [LocalFileSystem] factory Analytics({ required DashTool tool, required String dartVersion, String? flutterChannel, String? flutterVersion, - FileSystem? fsOverride, - Directory? homeOverride, - DevicePlatform? platformOverride, }) { // Create the instance of the file system so clients don't need // resolve on their own - final FileSystem fs = fsOverride ?? LocalFileSystem(); + const FileSystem fs = LocalFileSystem(); // Resolve the OS using dart:io final DevicePlatform platform; @@ -98,27 +47,21 @@ abstract class Analytics { // Create the instance of the GA Client which will create // an [http.Client] to send requests - // - // When a [fsOverride] is passed in, we can assume to - // use the fake Google Analytics client - final GAClient gaClient = fsOverride != null - ? FakeGAClient() - : GAClient( - measurementId: kGoogleAnalyticsMeasurementId, - apiSecret: kGoogleAnalyticsApiSecret, - ); + final GAClient gaClient = GAClient( + measurementId: kGoogleAnalyticsMeasurementId, + apiSecret: kGoogleAnalyticsApiSecret, + ); return AnalyticsImpl( tool: tool, - homeDirectory: homeOverride ?? getHomeDirectory(fs), + homeDirectory: getHomeDirectory(fs), flutterChannel: flutterChannel, flutterVersion: flutterVersion, dartVersion: dartVersion, - platform: platformOverride ?? platform, + platform: platform, toolsMessageVersion: kToolsMessageVersion, fs: fs, gaClient: gaClient, - pddFlag: true, ); } @@ -295,7 +238,6 @@ class AnalyticsImpl implements Analytics { required this.toolsMessageVersion, required this.fs, required gaClient, - bool pddFlag = false, }) : _gaClient = gaClient { // Initialize date formatting for `package:intl` within constructor // so clients using this package won't need to @@ -309,7 +251,6 @@ class AnalyticsImpl implements Analytics { tool: tool.label, homeDirectory: homeDirectory, toolsMessageVersion: toolsMessageVersion, - pddFlag: pddFlag, ); initializer.run(); _showMessage = initializer.firstRun; @@ -345,21 +286,12 @@ class AnalyticsImpl implements Analytics { homeDirectory.path, kDartToolDirectoryName, kClientIdFileName)) .readAsStringSync(); - // Create the session instance that will be responsible for managing - // all the sessions across every client tool using this pakage - final Session session; - if (pddFlag) { - session = NoopSession(); - } else { - session = Session(homeDirectory: homeDirectory, fs: fs); - } - // Initialize the user property class that will be attached to // each event that is sent to Google Analytics -- it will be responsible // for getting the session id or rolling the session if the duration // exceeds [kSessionDurationMinutes] userProperty = UserProperty( - session: session, + session: Session(homeDirectory: homeDirectory, fs: fs), flutterChannel: flutterChannel, host: platform.label, flutterVersion: flutterVersion, @@ -368,11 +300,7 @@ class AnalyticsImpl implements Analytics { ); // Initialize the log handler to persist events that are being sent - if (pddFlag) { - _logHandler = NoopLogHandler(); - } else { - _logHandler = LogHandler(fs: fs, homeDirectory: homeDirectory); - } + _logHandler = LogHandler(fs: fs, homeDirectory: homeDirectory); } @override diff --git a/pkgs/unified_analytics/lib/src/initializer.dart b/pkgs/unified_analytics/lib/src/initializer.dart index 82faec07c2..cdd34e6279 100644 --- a/pkgs/unified_analytics/lib/src/initializer.dart +++ b/pkgs/unified_analytics/lib/src/initializer.dart @@ -17,7 +17,6 @@ class Initializer { final Directory homeDirectory; final int toolsMessageVersion; bool firstRun = false; - final bool pddFlag; /// Responsibe for the initialization of the files /// necessary for analytics reporting @@ -33,7 +32,6 @@ class Initializer { required this.tool, required this.homeDirectory, required this.toolsMessageVersion, - required this.pddFlag, }); /// Creates the text file that will contain the client ID @@ -118,14 +116,14 @@ class Initializer { // Begin initialization checks for the session file final File sessionFile = fs.file( p.join(homeDirectory.path, kDartToolDirectoryName, kSessionFileName)); - if (!sessionFile.existsSync() && !pddFlag) { + if (!sessionFile.existsSync()) { createSessionFile(sessionFile: sessionFile); } // Begin initialization checks for the log file to persist events locally final File logFile = fs .file(p.join(homeDirectory.path, kDartToolDirectoryName, kLogFileName)); - if (!logFile.existsSync() && !pddFlag) { + if (!logFile.existsSync()) { createLogFile(logFile: logFile); } } diff --git a/pkgs/unified_analytics/test/pdd_approved_test.dart b/pkgs/unified_analytics/test/pdd_approved_test.dart deleted file mode 100644 index 2e5852eb76..0000000000 --- a/pkgs/unified_analytics/test/pdd_approved_test.dart +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io' as io; - -import 'package:file/file.dart'; -import 'package:file/memory.dart'; -import 'package:test/test.dart'; - -import 'package:unified_analytics/src/constants.dart'; -import 'package:unified_analytics/unified_analytics.dart'; - -void main() { - late FileSystem fs; - late Directory home; - late Directory dartToolDirectory; - late Analytics initializationAnalytics; - late Analytics analytics; - late File clientIdFile; - late File sessionFile; - late File configFile; - late File logFile; - - const String homeDirName = 'home'; - const DashTool initialTool = DashTool.flutterTool; - const String dartVersion = 'dartVersion'; - - setUp(() { - // Setup the filesystem with the home directory - final FileSystemStyle fsStyle = - io.Platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix; - fs = MemoryFileSystem.test(style: fsStyle); - home = fs.directory(homeDirName); - dartToolDirectory = home.childDirectory(kDartToolDirectoryName); - - // Create the initial analytics instance that will onboard the tool - initializationAnalytics = Analytics( - tool: initialTool, - dartVersion: dartVersion, - fsOverride: fs, - homeOverride: home, - ); - initializationAnalytics.clientShowedMessage(); - - // The main analytics instance that will be used for the - // tests after having the tool onboarded - analytics = Analytics( - tool: initialTool, - dartVersion: dartVersion, - fsOverride: fs, - homeOverride: home, - ); - - // The 3 files that should have been generated - clientIdFile = home - .childDirectory(kDartToolDirectoryName) - .childFile(kClientIdFileName); - sessionFile = - home.childDirectory(kDartToolDirectoryName).childFile(kSessionFileName); - configFile = - home.childDirectory(kDartToolDirectoryName).childFile(kConfigFileName); - logFile = - home.childDirectory(kDartToolDirectoryName).childFile(kLogFileName); - }); - - test('Initializer properly sets up on first run', () { - expect(dartToolDirectory.existsSync(), true, - reason: 'The directory should have been created'); - expect(clientIdFile.existsSync(), true, - reason: 'The $kClientIdFileName file was not found'); - expect(sessionFile.existsSync(), false, - reason: 'The session handling has been disabled'); - expect(configFile.existsSync(), true, - reason: 'The $kConfigFileName was not found'); - expect(logFile.existsSync(), false, - reason: 'The log file has been disabled'); - expect(dartToolDirectory.listSync().length, equals(2), - reason: - 'There should only be 2 files in the $kDartToolDirectoryName directory'); - expect(initializationAnalytics.shouldShowMessage, true, - reason: 'For the first run, the message should be shown'); - expect(configFile.readAsLinesSync().length, - kConfigString.split('\n').length + 1, - reason: 'The number of lines should equal lines in constant value + 1 ' - 'for the initialized tool'); - }); - - test('Sending events does not cause any errors', () async { - await expectLater( - () => analytics.sendEvent(eventName: DashEvent.hotReloadTime), - returnsNormally); - }); -}