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

🐛 [firebase_analytics] WEB: User properties and custom events not working since Flutter 3 versions #8757

Closed
jorgeroncero opened this issue May 23, 2022 · 15 comments
Labels
platform: web Issues / PRs which are specifically for web. plugin: analytics resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@jorgeroncero
Copy link
Contributor

jorgeroncero commented May 23, 2022

Bug report

I was able to successfully use Firebase Analytics in Flutter Web in my previous scenario:

  • Flutter 2.10.5
  • firebase_core 1.6.0
  • firebase_analytics 8.3.2

I had some user properties that were sent along with our custom events. Everything was working fine.

But, since Flutter 3, this is not working anymore. My current setup is:

  • Flutter 3.0.0
  • firebase_core 1.17.0
  • firebase_analytics 9.1.8

In this scenario, I'm facing two strange behaviours:

  • Debug in localhost: Custom events are properly sent but they have no user properties in the POST request. If I check the Firebase Realtime dashboard, I can see the events but I can't see the user properties set (as I guessed with the POST request).
  • Deploy in Firebase Hosting: Default events (like page_view) are sent with my User Properties, but custom events fail. I can see page_view in Firebase Realtime dashboard but no custom event appear. In the Chrome console, with Firebase Analytics Debugger on, I can see the following message when trying to send a custom event:
    Event parsing aborted: Cannot convert object to primitive value. Event processing aborted.

Steps to reproduce

Steps to reproduce the behaviour:

  1. Download firebase_analytics example project.
  2. Change firebase_config.dart to your firebase project values.
  3. Set any analytics user property.
  4. Log any custom event.
  5. Run the app in localhost: Custom events are sent but user properties aren't.
  6. Deploy to Firebase Hosting: Custom events are not sent but user properties are set when logging default events.

Expected behavior

User properties and custom events are properly sent with Flutter 3 in WEB environment in localhost and hosting.

Sample project

You can just use the firebase_analytics example project and set your config in the firebase_config.dart file:
Firebase Analytics Example


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.0.1 21A559 darwin-x64, locale en-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.67.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.17.0
Flutter SDK 3.0.0
firebase_analytics_example 0.0.0

dependencies:
- firebase_analytics 9.1.8 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 1.17.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]

dev dependencies:
- drive 1.0.0-1.0.nullsafety.5 [test_api flutter_test flutter_driver stack_trace flutter]
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver archive async boolean_selector characters charcode clock collection crypto matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- test 1.21.1 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core]

dependency overrides:
- firebase_analytics_platform_interface 3.1.6 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.0+13 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_core 1.17.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_platform_interface 4.4.0 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.6.4 [firebase_core_platform_interface flutter flutter_web_plugins js meta]

transitive dependencies:
- _fe_analyzer_shared 40.0.0 [meta]
- analyzer 4.1.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- archive 3.1.11 [crypto path]
- args 2.3.1
- async 2.8.2 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- convert 3.0.1 [typed_data]
- coverage 1.2.0 [args logging package_config path source_maps stack_trace vm_service]
- crypto 3.0.1 [collection typed_data]
- fake_async 1.3.0 [clock collection]
- file 6.1.2 [meta path]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- frontend_server_client 2.1.3 [async path]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform]
- glob 2.0.2 [async collection file path string_scanner]
- http_multi_server 3.2.0 [async]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- io 1.0.3 [meta path string_scanner]
- js 0.6.4
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- mime 1.0.2
- node_preamble 2.0.1
- package_config 2.0.2 [path]
- path 1.8.1
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- pool 1.5.0 [async stack_trace]
- process 4.2.4 [file path platform]
- pub_semver 2.1.1 [collection meta]
- shelf 1.3.0 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.0 [path shelf shelf_static]
- shelf_static 1.1.0 [convert http_parser mime path shelf]
- shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_map_stack_trace 2.1.0 [path stack_trace source_maps]
- source_maps 0.10.10 [source_span]
- source_span 1.8.2 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- sync_http 0.3.0
- term_glyph 1.2.0
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- test_core 0.4.13 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api]
- typed_data 1.3.0 [collection]
- vector_math 2.1.2
- vm_service 8.2.2
- watcher 1.0.1 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- webdriver 3.0.0 [archive matcher path stack_trace sync_http]
- webkit_inspection_protocol 1.1.0 [logging]
- yaml 3.1.1 [collection source_span string_scanner]

@jorgeroncero jorgeroncero added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels May 23, 2022
@jorgeroncero jorgeroncero changed the title 🐛 [firebase_analytics] User properties and custom events not working since Flutter 3 versions 🐛 [firebase_analytics] WEB: User properties and custom events not working since Flutter 3 versions May 23, 2022
@kolotum
Copy link
Contributor

kolotum commented May 23, 2022

I think this issue is not related to Flutter 3 but to firebase_analytics. We are seeing the same described behaviour with the following configuration for Flutter Web:

  • Flutter 2.10
  • firebase_core: 1.14.0
  • firebase_core_web: 1.6.1
  • firebase_analytics: 9.1.3
  • firebase_analytics_web: 0.4.0+9

When we set a user property we are facing the error Event parsing aborted: Cannot convert object to primitive value. Event processing aborted. and can not send any analytics events in that session.

Without setting user properties (skip step 3 above) the analytics events are sent successfully.

--

Update:
This issue seems to be introduced with firebase_analytics: 9.0.0. I think we will downgrade to firebase_analytics 8.3.4 for now.

@jorgeroncero
Copy link
Contributor Author

@kolotum Yes, I was referring to the Firebase versions that came with Flutter 3.

The problem is that once you upgrade and apply changes for Flutter 3, you can't downgrade to 8.x.x versions because you get Firebase initialization errors. I think firebase_core is trying to use firebasejs version 9 (module) and it's not properly loading analytics if you use a downgraded version.

@darshankawar darshankawar added the triage Issue is currently being triaged. label May 24, 2022
@darshankawar
Copy link

Thanks for the report. Using steps to replicate provided above and running on web, I observed the same result as reported.
Used latest plugin version to verify this.

Maybe related to : #8403

@darshankawar darshankawar added plugin: analytics platform: web Issues / PRs which are specifically for web. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels May 24, 2022
@jorgeroncero
Copy link
Contributor Author

Upgraded to latest versions and still happening.

firebase_core: ^1.17.1
firebase_analytics: ^9.1.9

@mrseth01
Copy link

mrseth01 commented Jun 3, 2022

I am testing the code from this PR #8810 to see if it helps. I'll report back after some hours to see what data is being retrieved by GA4: #8810

@jorgeroncero
Copy link
Contributor Author

jorgeroncero commented Jun 3, 2022

I am testing the code from this PR #8810 to see if it helps. I'll report back after some hours to see what data is being retrieved by GA4: #8810

EDIT1: I've just tested again, and userId user property is set, but custom user properties aren't.

EDIT2: Tested in release mode and I get the same as when deployed in Firebase Hosting -> "Event parsing aborted: Cannot convert object to primitive value" after set user property + send custom event

I've just tested that PR example app in localhost and the issue is still there. Events are successfully logged but user properties aren't.

With GA Debug Extension ON, I can see the following messages:

Set user property

Click To Expand
Processing commands (1)

Processing GTAG command: ["config", "G-XXXXXXXXX", {update: true, user_properties: {my_user_property: indeed}}]

GTAG Command: "config", target: "G-XXXXXXXXX", configuration: {update: true, user_properties: {my_user_property: indeed}}

Log event

Click To Expand
Processing commands (1)

Processing GTAG command: ["event", "test_event", {string: "string", int: 42, long: 12345678910, double: 42, bool: "true", items: [{affiliation: "affil", currency: "USD", coupon: "coup", creative_name: "creativeName", creative_slot: "creativeSlot", discount: 2.22, index: 3, item_brand: "itemBrand", item_category: "itemCategory", item_category2: "itemCategory2", item_category3: "itemCategory3", item_category4: "itemCategory4", item_category5: "itemCategory5", item_id: "itemId", item_list_id: "itemListId", item_list_name: "itemListName", item_name: "itemName", item_variant: "itemVariant", location_id: "locationId", price: 9.99, promotion_id: "promotionId", promotion_name: "promotionName", quantity: 1}], send_to: "G-XXXXXXXXX"}]

Sending event "test_event" to undefined

Invalid event parameter "_ipe" on event "test_event", parameter will not be logged

Loaded existing client id: ...
Event would be batched, but batching is disabled in debug mode.

Request parameters:
v: 2
tid: G-XXXXXXXXX
gtm: 2oe610
_p: 105388656
_dbg: 1
_z: ccd.tdB
_fid: e_cjPhYMxEvpMiydzDlGGP
cid: 1414685205.1646059528
ul: es-es
sr: 1920x1080
Event parameters:
en: test_event
_ee: 1
_et: 10814
ep.screen_name: /
ep.origin: firebase
ep.string: string
epn.int: 42
epn.long: 12345678910
epn.double: 42
ep.bool: true
Shared parameters:
sid: 1654246705
sct: 7
seg: 1
dl: http://localhost/
dt: Firebase Analytics Demo

@russellwheatley
Copy link
Member

Hey @jronceroscb, I'm confused

I am testing the code from this PR #8810 to see if it helps. I'll report back after some hours to see what data is being retrieved by GA4: #8810

EDIT1: I've just tested again, and userId user property is set, but custom user properties aren't.

EDIT2: Tested in release mode and I get the same as when deployed in Firebase Hosting -> "Event parsing aborted: Cannot convert object to primitive value" after set user property + send custom event

I've just tested that PR example app in localhost and the issue is still there. Events are successfully logged but user properties aren't.

With GA Debug Extension ON, I can see the following messages:

Set user property

Click To Expand

Processing commands (1)

Processing GTAG command: ["config", "G-XXXXXXXXX", {update: true, user_properties: {my_user_property: indeed}}]

GTAG Command: "config", target: "G-XXXXXXXXX", configuration: {update: true, user_properties: {my_user_property: indeed}}

Log event

Click To Expand

Processing commands (1)

Processing GTAG command: ["event", "test_event", {string: "string", int: 42, long: 12345678910, double: 42, bool: "true", items: [{affiliation: "affil", currency: "USD", coupon: "coup", creative_name: "creativeName", creative_slot: "creativeSlot", discount: 2.22, index: 3, item_brand: "itemBrand", item_category: "itemCategory", item_category2: "itemCategory2", item_category3: "itemCategory3", item_category4: "itemCategory4", item_category5: "itemCategory5", item_id: "itemId", item_list_id: "itemListId", item_list_name: "itemListName", item_name: "itemName", item_variant: "itemVariant", location_id: "locationId", price: 9.99, promotion_id: "promotionId", promotion_name: "promotionName", quantity: 1}], send_to: "G-XXXXXXXXX"}]

Sending event "test_event" to undefined

Invalid event parameter "_ipe" on event "test_event", parameter will not be logged

Loaded existing client id: ...
Event would be batched, but batching is disabled in debug mode.

Request parameters:
v: 2
tid: G-XXXXXXXXX
gtm: 2oe610
_p: 105388656
_dbg: 1
_z: ccd.tdB
_fid: e_cjPhYMxEvpMiydzDlGGP
cid: 1414685205.1646059528
ul: es-es
sr: 1920x1080
Event parameters:
en: test_event
_ee: 1
_et: 10814
ep.screen_name: /
ep.origin: firebase
ep.string: string
epn.int: 42
epn.long: 12345678910
epn.double: 42
ep.bool: true
Shared parameters:
sid: 1654246705
sct: 7
seg: 1
dl: http://localhost/[](http://localhost/)
dt: Firebase Analytics Demo

Hey @jronceroscb, I'm trying to interpret what the issue is here. In debug mode, I don't see any error in the console, and the debug logs appear to show the custom event and user properties are correctly interpreted.

Does this debug log not mean user property is set?

Processing commands (1)
js?l=dataLayer&id=G-F79DJ0VFGS:202 Processing GTAG command: ["config", "G-F79DJ0VFGS", {update: true, user_properties: {regular: indeed}}]
js?l=dataLayer&id=G-F79DJ0VFGS:202 GTAG Command: "config", target: "G-F79DJ0VFGS", configuration: {update: true, user_properties: {regular: indeed}}

@russellwheatley russellwheatley added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 7, 2022
@jorgeroncero
Copy link
Contributor Author

Hello @russellwheatley, thanks for the response. My guess is that the user property is set locally but is not propagated to Firebase servers.

From my understanding, user properties are not sent until an event is logged. So, setting a user property locally seems to be working, but when logging an event, the event has no user properties in the request.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jun 7, 2022
@jorgeroncero
Copy link
Contributor Author

By the way, I've been testing the Javascript SDK (9.8.2 version) to discard a possible issue in JS, and the user properties are correctly set when logging an event.

As you can see in the next log, there is a 'up" parameter with the user property -> up.my_property: codelab

Log event JAVASCRIPT SDK

Click To Expand
Processing commands (1)

Processing GTAG command: ["event", "my_event", {my_param: "test", send_to: "XXXXXXXX"}]
Invalid event parameter "_ipe" on event "my_event", parameter will not be logged

Loaded existing client id: XXXXXXXX.YYYYYYYY
Event would be batched, but batching is disabled in debug mode.
Sending event "my_event" to undefined
Request parameters:
v: 2
tid: XXXXXXXX
gtm: 2oe660
_p: 2060749588
_dbg: 1
_z: ccd.tdB
_fid: fFNhc131I3cXax6DfyE2ex
cid: 1339912682.1650876975
ul: es-es
sr: 1920x1080
Event parameters:
en: my_event
_ee: 1
_et: 8107
ep.origin: firebase
ep.my_param: test
up.my_property: codelab
Shared parameters:
uid: my_user_id
sid: 1654599993
sct: 1
seg: 1
dl: http://127.0.0.1/
dt: 
Sending request: https://www.google-analytics.com/g/collect?v=2&tid=XXXXXXXX&gtm=2oe660&_p=2060749588&_dbg=1&_z=ccd.tdB&_fid=fFNhc131I3cXax6DfyE2ex&cid=1339912682.1650876975&ul=es-es&sr=1920x1080&_s=3&uid=my_user_id&sid=1654599993&sct=1&seg=1&dl=http%3A%2F%2F127.0.0.1%2F&dt=&en=my_event&_ee=1&_et=8107&ep.origin=firebase&ep.my_param=test&up.my_property=codelab

@jorgeroncero
Copy link
Contributor Author

jorgeroncero commented Jun 7, 2022

@russellwheatley I think I've found what might be the issue. I think that the user properties in Flutter are being set as Objects and not as Strings.

If you compare the Analytics Debug messages between Flutter and Javascript SDK you can see the difference:

Flutter

Processing GTAG command: ["config", "XXXXXXXX", {update: true, user_properties: {my_property: analytics_example}}]

Javascript SDK

Processing GTAG command: ["config", "XXXXXXXX", {update: true, user_properties: {my_property: "codelab"}}]

Can you see the difference between analytics_example and "codelab"? One is an object and the other is a string.

@jorgeroncero
Copy link
Contributor Author

@russellwheatley that was it!! I've managed to make it work, I'll make a pull request to your v9/analytics branch.

@russellwheatley
Copy link
Member

Awesome work, @jronceroscb! We gratefully accept PRs 😄

@darshankawar darshankawar removed the Needs Attention This issue needs maintainer attention. label Jun 8, 2022
@deepak786
Copy link
Contributor

deepak786 commented Jul 20, 2022

I have the same issue with Firebase user properties.
Browser console shows the log that user property is being set
Screen Shot 2022-07-20 at 7 28 44 PM

But when debugging using debugView with GA debugger, I can't see it.

This PR #8852 has merged already and the changes are available in master branch https://github.com/firebase/flutterfire/blob/master/packages/firebase_analytics/firebase_analytics_web/lib/interop/analytics.dart

Is this issue resolved already for user properties with the latest version https://pub.dev/packages/firebase_analytics_web (0.4.1)?

@russellwheatley
Copy link
Member

Hey @deepak786, this has been released with the web v9 JS SDK release: https://github.com/firebase/flutterfire/blob/master/packages/firebase_analytics/firebase_analytics/CHANGELOG.md#920. Use the latest version and it should be fine now.

@darshankawar darshankawar added the resolution: fixed A fix has been merged or is pending merge from a PR. label Jul 22, 2022
@deepak786
Copy link
Contributor

deepak786 commented Jul 22, 2022

I have to wait until this issue is not resolved #9132
Otherwise, the Web build will not work. I had to downgrade all the Firebase libraries for the web. #9132 (comment)

@firebase firebase locked and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: web Issues / PRs which are specifically for web. plugin: analytics resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants