Skip to content

Commit

Permalink
fix(analytics, web): ensure setDefaultEventParameters() API throws …
Browse files Browse the repository at this point in the history
…stating not supported on web. (#7522)
  • Loading branch information
russellwheatley committed Dec 10, 2021
1 parent 3317e2b commit 9a83f12
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 18 deletions.
30 changes: 28 additions & 2 deletions docs/analytics/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ await FirebaseAnalytics.instance

## Default Parameters

Use the `setDefaultEventParameters` method if you have common parameters which need to be sent with each event:
Use the `setDefaultEventParameters` method if you have common parameters which need to be sent with each event. Please
note that this API is not supported on web.

```dart
// Not supported on web
await FirebaseAnalytics.instance
.setDefaultEventParameters({
version: '1.2.3'
Expand Down Expand Up @@ -168,9 +170,33 @@ You can provide a `null` value to remove any previous properties.

## Resetting data

To clear all data associated with the current session, use the `resetAnalyticsData` method:
To clear all data associated with the current session, use the `resetAnalyticsData` method. Please
note that this API is not supported on web.

```dart
// Not supported on web
await FirebaseAnalytics.instance
.resetAnalyticsData();
```

## Set user consent

Set the applicable end user consent state. `default` value for adStorageConsentGranted` & analyticsStorageConsentGranted` is true`.
Please note that this API is not supported on web.

```dart
// Not supported on web
await FirebaseAnalytics.instance
setConsent(adStorageConsentGranted: false, analyticsStorageConsentGranted: true);
```

## Set session timeout duration

Set the duration of inactivity that terminates the current session.
Please note that this API is android only.

```dart
// android support only
await FirebaseAnalytics.instance
setSessionTimeoutDuration(const Duration(minutes: 1))
```
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,20 @@ void testsMain() {
test(
'setSessionTimeoutDuration',
() async {
await expectLater(
analytics
.setSessionTimeoutDuration(const Duration(milliseconds: 5000)),
completes,
);
if (kIsWeb) {
await expectLater(
analytics
.setSessionTimeoutDuration(const Duration(milliseconds: 5000)),
throwsA(isA<UnimplementedError>()),
);
} else {
await expectLater(
analytics
.setSessionTimeoutDuration(const Duration(milliseconds: 5000)),
completes,
);
}
},
skip: kIsWeb,
);

test('setAnalyticsCollectionEnabled', () async {
Expand Down Expand Up @@ -134,23 +141,55 @@ void testsMain() {
test(
'resetAnalyticsData',
() async {
await expectLater(analytics.resetAnalyticsData(), completes);
if (kIsWeb) {
await expectLater(
analytics.resetAnalyticsData(),
throwsA(isA<UnimplementedError>()),
);
} else {
await expectLater(analytics.resetAnalyticsData(), completes);
}
},
skip: kIsWeb,
);

test(
'setConsent',
() async {
await expectLater(
analytics.setConsent(
analyticsStorageConsentGranted: false,
adStorageConsentGranted: true,
),
completes,
);
if (kIsWeb) {
await expectLater(
analytics.setConsent(
analyticsStorageConsentGranted: false,
adStorageConsentGranted: true,
),
throwsA(isA<UnimplementedError>()),
);
} else {
await expectLater(
analytics.setConsent(
analyticsStorageConsentGranted: false,
adStorageConsentGranted: true,
),
completes,
);
}
},
);

test(
'setDefaultEventParameters',
() async {
if (kIsWeb) {
await expectLater(
analytics.setDefaultEventParameters({'default': 'parameters'}),
throwsA(isA<UnimplementedError>()),
);
} else {
await expectLater(
analytics.setDefaultEventParameters({'default': 'parameters'}),
completes,
);
}
},
skip: kIsWeb,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,13 @@ class FirebaseAnalyticsWeb extends FirebaseAnalyticsPlatform {
'setSessionTimeoutDuration() is not supported on Web.',
);
}

@override
Future<void> setDefaultEventParameters(
Map<String, Object> defaultParameters,
) async {
throw UnimplementedError(
'setDefaultEventParameters() is not supported on web',
);
}
}

0 comments on commit 9a83f12

Please sign in to comment.