Skip to content
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

feat(firebase_analytics): provide isSupported for v9/analytics #8899

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ void testsMain() {
analytics = FirebaseAnalytics.instance;
});

test('isSupported', () async {
final result = await FirebaseAnalytics.instance.isSupported();
expect(result, isA<bool>());
});

test('logEvent', () async {
await expectLater(analytics.logEvent(name: 'testing'), completes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class FirebaseAnalytics extends FirebasePluginPlatform {
return FirebaseAnalytics.instanceFor(app: defaultAppInstance);
}

Future<bool> isSupported() {
return _delegate.isSupported();
}

/// Logs a custom Flutter Analytics event with the given [name] and event [parameters].
Future<void> logEvent({
required String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class MethodChannelFirebaseAnalytics extends FirebaseAnalyticsPlatform {
return MethodChannelFirebaseAnalytics(app: app);
}

/// Returns "true" as this API is used to inform users of web browser support
@override
Future<bool> isSupported() {
return Future.value(true);
}

@override
Future<void> logEvent({
required String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ abstract class FirebaseAnalyticsPlatform extends PlatformInterface {
throw UnimplementedError('delegateFor() is not implemented');
}

/// isSupported() informs web users whether
/// the browser supports Firebase.Analytics
Future<bool> isSupported() {
throw UnimplementedError('isSupported() is not implemented');
}

/// Logs the given event [name] with the given [parameters].
Future<void> logEvent({
required String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class FirebaseAnalyticsWeb extends FirebaseAnalyticsPlatform {
return FirebaseAnalyticsWeb(app: app);
}

@override
Future<bool> isSupported() {
return analytics_interop.Analytics.isSupported();
}

@override
Future<void> logEvent({
required String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Analytics extends JsObjectWrapper<analytics_interop.AnalyticsJsImpl> {
return _expando[jsObject] ??= Analytics._fromJsObject(jsObject);
}

static Future<bool> isSupported() {
return handleThenable(analytics_interop.isSupported());
}

/// Non-null App for this instance of analytics service.
App get app => App.getInstance(jsObject.app);

Expand All @@ -41,7 +45,11 @@ class Analytics extends JsObjectWrapper<analytics_interop.AnalyticsJsImpl> {
AnalyticsCallOptions? callOptions,
}) {
return analytics_interop.logEvent(
jsObject, name, util.jsify(parameters ?? {}), callOptions);
jsObject,
name,
util.jsify(parameters ?? {}),
callOptions,
);
}

void setAnalyticsCollectionEnabled({required bool enabled}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ external AnalyticsJsImpl getAnalytics([AppJsImpl? app]);
external AnalyticsJsImpl initializeAnalytics([AppJsImpl app]);

@JS()
external bool isSupported();
external PromiseJsImpl<bool> isSupported();

@JS()
external void logEvent(
Expand All @@ -31,7 +31,9 @@ external void logEvent(

@JS()
external void setAnalyticsCollectionEnabled(
AnalyticsJsImpl analytics, bool enabled);
AnalyticsJsImpl analytics,
bool enabled,
);

@JS()
external void setCurrentScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ void setupTests() {
);
});

test('isSupported', () async {
final result = await FirebaseAnalytics.instance.isSupported();
expect(result, isA<bool>());
});

test('logEvent', () async {
await expectLater(
FirebaseAnalytics.instance.logEvent(name: 'testing'),
Expand Down