Unverified Commit 8e34fb03 authored by flutteractionsbot's avatar flutteractionsbot Committed by GitHub

[CP-beta]Opt out users from GA3 if opted out of GA4 (#147060)

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
parent 312b9e81
......@@ -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);
}
......@@ -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);
......
......@@ -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);
}
......
......@@ -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();
}
......
......@@ -353,6 +353,7 @@ void main() {
group('unified_analytics', () {
late FakeAnalytics fakeAnalytics;
late MemoryFileSystem fs;
late TestUsage testUsage;
setUp(() {
fs = MemoryFileSystem.test();
......@@ -361,6 +362,7 @@ void main() {
fs: fs,
fakeFlutterVersion: FakeFlutterVersion(),
);
testUsage = TestUsage();
});
testUsingContext(
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment