Skip to content

Commit

Permalink
[CP-beta]Opt out users from GA3 if opted out of GA4 (flutter#147060)
Browse files Browse the repository at this point in the history
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
What is the link to the issue this cherry-pick is addressing?

No issue link for this one but this will help us make sense of MAU number differences between GA3 and GA4.

### Changelog Description:
Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/wiki/Hotfix-Documentation-Best-Practices) for examples

Sends a new event, `ga4_and_ga3_status_mismatch` for users that have opted out of GA4 (package:unified_analytics) but remain opted into GA3

### Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch)

No impact to developer workflows.

### Workaround:
Is there a workaround for this issue?

No

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

No steps to validate, no changes to developer workflows
  • Loading branch information
flutteractionsbot authored Apr 19, 2024
1 parent 312b9e8 commit 8e34fb0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/flutter_tools/lib/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Future<int> run(

// TODO(eliasyishak): Set the telemetry for the unified_analytics
// package as well, the above will be removed once we have
// fully transitioned to using the new package
// fully transitioned to using the new package, https://github.com/flutter/flutter/issues/128251
await globals.analytics.setTelemetry(false);
}

Expand All @@ -111,10 +111,21 @@ Future<int> run(

// TODO(eliasyishak): Set the telemetry for the unified_analytics
// package as well, the above will be removed once we have
// fully transitioned to using the new package
// fully transitioned to using the new package, https://github.com/flutter/flutter/issues/128251
await globals.analytics.setTelemetry(true);
}

// Send an event to GA3 for any users that are opted into GA3
// analytics but have opted out of GA4 (package:unified_analytics)
// TODO(eliasyishak): remove once GA3 sunset, https://github.com/flutter/flutter/issues/128251
if (!globals.analytics.telemetryEnabled &&
globals.flutterUsage.enabled) {
UsageEvent(
'ga4_and_ga3_status_mismatch',
'opted_out_of_ga4',
flutterUsage: globals.flutterUsage,
).send();
}

await runner.run(args);

Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class ConfigCommand extends FlutterCommand {

// TODO(eliasyishak): Set the telemetry for the unified_analytics
// package as well, the above will be removed once we have
// fully transitioned to using the new package
// fully transitioned to using the new package,
// https://github.com/flutter/flutter/issues/128251
await globals.analytics.setTelemetry(value);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/doctor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ class Doctor {
doctorInvocationId: analyticsTimestamp,
));
}
// TODO(eliasyishak): remove this after migrating from package:usage
// TODO(eliasyishak): remove this after migrating from package:usage,
// https://github.com/flutter/flutter/issues/128251
DoctorResultEvent(validator: validator, result: result).send();
}

Expand Down
81 changes: 81 additions & 0 deletions packages/flutter_tools/test/general.shard/runner/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ void main() {
group('unified_analytics', () {
late FakeAnalytics fakeAnalytics;
late MemoryFileSystem fs;
late TestUsage testUsage;

setUp(() {
fs = MemoryFileSystem.test();
Expand All @@ -361,6 +362,7 @@ void main() {
fs: fs,
fakeFlutterVersion: FakeFlutterVersion(),
);
testUsage = TestUsage();
});

testUsingContext(
Expand All @@ -387,6 +389,85 @@ void main() {
},
);

testUsingContext(
'runner sends mismatch event to ga3 if user opted in to ga3 but out of ga4 analytics',
() async {
io.setExitFunctionForTests((int exitCode) {});

// Begin by opting out of telemetry for package:unified_analytics
// and leaving legacy analytics opted in
await fakeAnalytics.setTelemetry(false);
expect(fakeAnalytics.telemetryEnabled, false);
expect(testUsage.enabled, true);

await runner.run(
<String>[],
() => <FlutterCommand>[],
// This flutterVersion disables crash reporting.
flutterVersion: '[user-branch]/',
shutdownHooks: ShutdownHooks(),
);

expect(
testUsage.events,
contains(const TestUsageEvent(
'ga4_and_ga3_status_mismatch',
'opted_out_of_ga4',
)),
);
expect(fakeAnalytics.telemetryEnabled, false);
expect(testUsage.enabled, true);
expect(fakeAnalytics.sentEvents, isEmpty);

},
overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
},
);

testUsingContext(
'runner does not send mismatch event to ga3 if user opted out of ga3 & ga4 analytics',
() async {
io.setExitFunctionForTests((int exitCode) {});

// Begin by opting out of telemetry for package:unified_analytics
// and legacy analytics
await fakeAnalytics.setTelemetry(false);
testUsage.enabled = false;
expect(fakeAnalytics.telemetryEnabled, false);
expect(testUsage.enabled, false);

await runner.run(
<String>[],
() => <FlutterCommand>[],
// This flutterVersion disables crash reporting.
flutterVersion: '[user-branch]/',
shutdownHooks: ShutdownHooks(),
);

expect(
testUsage.events,
isNot(contains(const TestUsageEvent(
'ga4_and_ga3_status_mismatch',
'opted_out_of_ga4',
))),
);
expect(fakeAnalytics.telemetryEnabled, false);
expect(testUsage.enabled, false);
expect(fakeAnalytics.sentEvents, isEmpty);

},
overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
},
);

testUsingContext(
'runner enabling analytics with flag',
() async {
Expand Down

0 comments on commit 8e34fb0

Please sign in to comment.