Skip to content

Commit

Permalink
fix(analytics): setCurrentScreen() was deprecated, using `logScreen…
Browse files Browse the repository at this point in the history
…View()` instead (firebase#12085)
  • Loading branch information
kzrnm authored Jan 5, 2024
1 parent 387e943 commit c6341b9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ class _MyHomePageState extends State<MyHomePage> {
setMessage('setUserId succeeded');
}

Future<void> _testSetCurrentScreen() async {
await widget.analytics.setCurrentScreen(
screenName: 'Analytics Demo',
screenClassOverride: 'AnalyticsDemo',
);
setMessage('setCurrentScreen succeeded');
}

Future<void> _testSetAnalyticsCollectionEnabled() async {
await widget.analytics.setAnalyticsCollectionEnabled(false);
await widget.analytics.setAnalyticsCollectionEnabled(true);
Expand Down Expand Up @@ -337,10 +329,6 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _testSetUserId,
child: const Text('Test setUserId'),
),
MaterialButton(
onPressed: _testSetCurrentScreen,
child: const Text('Test setCurrentScreen'),
),
MaterialButton(
onPressed: _testSetAnalyticsCollectionEnabled,
child: const Text('Test setAnalyticsCollectionEnabled'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class _TabsPageState extends State<TabsPage>
}

void _sendCurrentTabToAnalytics() {
analytics.setCurrentScreen(
analytics.logScreenView(
screenName: '${TabsPage.routeName}/tab$selectedIndex',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FirebaseAnalyticsObserver extends RouteObserver<ModalRoute<dynamic>> {
void _sendScreenView(Route<dynamic> route) {
final String? screenName = nameExtractor(route.settings);
if (screenName != null) {
analytics.setCurrentScreen(screenName: screenName).catchError(
analytics.logScreenView(screenName: screenName).catchError(
(Object error) {
final _onError = this._onError;
if (_onError == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class FirebaseAnalytics extends FirebasePluginPlatform {
///
/// * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setCurrentScreen(android.app.Activity, java.lang.String, java.lang.String)
/// * https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#setscreennamescreenclass
@Deprecated(
'setCurrentScreen() has been deprecated. Please use logScreenView()',
)
Future<void> setCurrentScreen({
required String? screenName,
String screenClassOverride = 'Flutter',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ void main() {
});

test('setCurrentScreen', () async {
// ignore: deprecated_member_use_from_same_package
await analytics!.setCurrentScreen(
screenName: 'test-screen-name',
screenClassOverride: 'test-class-override',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void main() {
throwsA(isA<AssertionError>()),
);

// test 2 reserved events
// test 3 reserved events
await expectLater(
FirebaseAnalytics.instance.logAdImpression(
adPlatform: 'foo',
Expand All @@ -134,6 +134,14 @@ void main() {
),
completes,
);

await expectLater(
FirebaseAnalytics.instance.logScreenView(
screenClass: 'FooActivity',
screenName: 'bar',
),
completes,
);
});

test(
Expand Down Expand Up @@ -171,6 +179,7 @@ void main() {

test('setCurrentScreen', () async {
await expectLater(
// ignore: deprecated_member_use
FirebaseAnalytics.instance.setCurrentScreen(screenName: 'screen-name'),
completes,
);
Expand Down

0 comments on commit c6341b9

Please sign in to comment.