Skip to content

pddFlag removal + tests for pdd restricted instance of Analytics #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
94 changes: 11 additions & 83 deletions pkgs/unified_analytics/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
);
}

Expand Down Expand Up @@ -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
Expand All @@ -309,7 +251,6 @@ class AnalyticsImpl implements Analytics {
tool: tool.label,
homeDirectory: homeDirectory,
toolsMessageVersion: toolsMessageVersion,
pddFlag: pddFlag,
);
initializer.run();
_showMessage = initializer.firstRun;
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions pkgs/unified_analytics/lib/src/initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
94 changes: 0 additions & 94 deletions pkgs/unified_analytics/test/pdd_approved_test.dart

This file was deleted.