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): update logEvent() & setDefaultParameters() to assert input types. #9520

Merged
merged 21 commits into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
514ea81
feat(analytics): update logEvent so it can only accept strings and nums
russellwheatley Sep 12, 2022
07bca4c
chore(in-app-messaging): update example app
russellwheatley Sep 12, 2022
c991ef2
feat(analytics): write tests and update event_parameters.dart
russellwheatley Sep 13, 2022
7a81816
feat(analytics): rm incorrect code
russellwheatley Sep 13, 2022
d85f8f4
feat(analytics): improve assertion message
russellwheatley Sep 13, 2022
281bf77
chore: analyze and formatting
russellwheatley Sep 13, 2022
a00eb9c
chore: analyze and formatting
russellwheatley Sep 13, 2022
aef5641
feat(analytics): update EventParameters API
russellwheatley Sep 14, 2022
4076b92
Merge branch 'master' into @russell/analytics-8861/2
russellwheatley Dec 8, 2022
dd00a27
update integration tests with new API
russellwheatley Dec 8, 2022
6ef36bf
feat(analytics): `setDefaultParameters()` uses `EventParameters` API
russellwheatley Dec 8, 2022
ab29980
feat(analytics): update event parameters
russellwheatley Dec 9, 2022
a67d312
feat(analytics, android): update int to long
russellwheatley Dec 9, 2022
fcbd3f8
feat(analytics): update docs
russellwheatley Dec 9, 2022
72e3e5e
feat(analytics): update inline docs
russellwheatley Dec 9, 2022
c7d1039
feat(analytics): update inline docs
russellwheatley Dec 9, 2022
cce45c7
Merge branch 'master' into @russell/analytics-8861/2
russellwheatley Dec 23, 2022
16f90f2
chore(analytics): revert changes to make it backwards compatible
russellwheatley Dec 23, 2022
8781763
test(analytics): assert exception for incorrect param
russellwheatley Dec 23, 2022
e832483
test(analytics): assert exception for incorrect param
russellwheatley Dec 23, 2022
e764349
chore(analytics): update comments
russellwheatley Dec 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,7 +53,8 @@ private static Bundle createBundleFromMap(Map<String, Object> map) {
if (value instanceof String) {
bundle.putString(key, (String) value);
} else if (value instanceof Integer) {
bundle.putInt(key, (Integer) value);
// FirebaseAnalytics default event parameters only support long and double types, so we convert the int to a long.
bundle.putLong(key, (Integer) value);
} else if (value instanceof Long) {
bundle.putLong(key, (Long) value);
} else if (value instanceof Double) {
Expand Down
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'firebase_options.dart';
Expand Down Expand Up @@ -68,7 +69,28 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

Future<void> _setDefaultEventParameters() async {
if (kIsWeb) {
setMessage(
'"setDefaultEventParameters()" is not supported on web platform',
);
} else {
// Only strings, numbers & null (longs & doubles for android, ints and doubles for iOS) are supported for default event parameters:
await widget.analytics.setDefaultEventParameters(<String, dynamic>{
'string': 'string',
'int': 42,
'long': 12345678910,
'double': 42.0,
'bool': true.toString(),
});
setMessage('setDefaultEventParameters succeeded');
}
}

Future<void> _sendAnalyticsEvent() async {
// Only strings and numbers (longs & doubles for android, ints and doubles for iOS) are supported for GA custom event parameters:
// https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#+logeventwithname:parameters:
// https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics#public-void-logevent-string-name,-bundle-params
await widget.analytics.logEvent(
name: 'test_event',
parameters: <String, dynamic>{
Expand All @@ -79,9 +101,9 @@ class _MyHomePageState extends State<MyHomePage> {
// Only strings and numbers (ints & doubles) are supported for GA custom event parameters:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets#overview
'bool': true.toString(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about to introduce an addBool method, which behind the scenes saves it as value.toString()?

This way we might support most of these base types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not as it isn't stored as a boolean and hence misleading, true.toString() is painless enough.

'items': [itemCreator()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have items anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for custom events (logEvent()). See the description for why 😄

},
);

setMessage('logEvent succeeded');
}

Expand Down Expand Up @@ -327,6 +349,10 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _testResetAnalyticsData,
child: const Text('Test resetAnalyticsData'),
),
MaterialButton(
onPressed: _setDefaultEventParameters,
child: const Text('Test setDefaultEventParameters'),
),
Text(
_message,
style: const TextStyle(color: Color.fromARGB(255, 0, 155, 0)),
Expand Down