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
Conversation
// 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(), | ||
'items': [itemCreator()] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😄
packages/firebase_analytics/firebase_analytics/example/lib/main.dart
Outdated
Show resolved
Hide resolved
Map<String, Object> _parameters = {}; | ||
|
||
// Can only pass either a String or a num value | ||
EventParameters addParameter(String key, {String? string, num? number}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this is not much better. We are allowing the consumer to pass both of them, and he's going to have a runtime exception if he does it. We could make a safe API that wouldn't allow the user to pass any kind of invalid data, so that, if it compiles, it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I think I will change addParameter
to addString
& addNumber
to improve it.
I will be keeping the fromMap()
function, as its main purpose is to help transition to the new EventParameters
API, and it will still throw assert on incorrect property values before it ever makes it to the native side.
packages/firebase_analytics/firebase_analytics_platform_interface/lib/src/event_parameters.dart
Outdated
Show resolved
Hide resolved
'double': 42.0, | ||
// 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(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
# Conflicts: # packages/firebase_analytics/firebase_analytics/example/test_driver/firebase_analytics_e2e.dart
logEvent()
so it can only accept strings and numberslogEvent()
& setDefaultParameters()
accepted input types.
logEvent()
& setDefaultParameters()
accepted input types. logEvent()
& setDefaultParameters()
to assert input types.
|
Description
This PR is designed to avoid confusion about what values are accepted when logging a custom event via
logEvent()
. I've implemented an assert on the values passed tologEvent
which throws when the parameter values are notString
ornum
. The same forsetDefaultEventParameters()
except it also allows parameter values to benull
which resets that value as a default parameter.The Firebase documentation states that the only values accepted are strings and numbers:
From android documentation (see bold):
I've also tested on web, iOS and android:
android:
Successful custom event without
items
list:Unsuccessful custom event including
items
list (Note error code 21):iOS:
Successful custom event without
items
list:Unsuccessful custom event including
items
list (Note error code 21):Web:
Web is slightly different as it uses a Chrome extension to debug. It does pass the items list in the request for a custom event, but it appears to stringify the value. See:
The result in the debugger console for
some_values
looks like this:Once decoded, it shows the value as one string (including the object within the array, hence
[object Object]
)setDefaultEventParameters
I've also changed
Int
toLong
for the event parameters bundle in android. The documentation for android saysLong
&Double
only. If you try to addInt
when runningsetDefaultEventParameters()
you will get the following warning in the console logs:It also doesn't show up in the debugger console.
When I changed
putInt()
toputLong()
, the warnings disappear and the default parameters appear in the console:TODO
EventParameters
forsetDefaultEventParameters()
as this only allows strings , null and numbers. See: 🐛 [firebase_analytics] cannot set default parameter due to invalid type #9698Related Issues
closes #8861, #9698
Other related issues which highlight confusion:
#4353
#2835
Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR. Note that you'll have to prefix the issue numbers with flutter/flutter#.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
).This will ensure a smooth and quick review process. Updating the
pubspec.yaml
and changelogs is not required.///
).melos run analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?