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

Not possible to use setUserId to unset user id using firebase/analytics #6592

Closed
buren opened this issue Sep 8, 2022 · 3 comments
Closed
Assignees

Comments

@buren
Copy link

buren commented Sep 8, 2022

Describe your environment

  • Operating System version: OSX
  • Browser version: Chrome 104
  • Firebase SDK version: v9.8.2
  • Firebase Product: Analytics (auth, database, storage, etc)

Describe the problem

When a user logs out it is currently not possible to unset the user id.

Steps to reproduce:

In code

  1. Initialize a firebase app
  2. Initialize an analytics instance
  3. Try to set the user id to null using setUserId(analytics, null)
  4. Type error

Relevant Code:

To reproduce

import { setUserId } from 'firebase/analytics'

// initialize app 
const analytics = getAnalytics(app)
setUserId(analytics, null)
// Argument of type 'null' is not assignable to parameter of type 'string'.ts

The function signature differs from other places, for example


Here it seems perfectly possible to set the user id to null.

Here null is not allowed

Here in the documentation for Firebase analytics for android it even states explicitly that null should be allowed for compliant implementations. Same thing here for iOS

Here's a similar issue for Firebase React Native invertase/react-native-firebase#4931 and here is another issue in the same repository that says that the documentation says that it's allowed but that the implementation actually doesn't set the userId to null - firebase/firebase-android-sdk#3602.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@hsubox76
Copy link
Contributor

hsubox76 commented Sep 8, 2022

So it seems like there's 2 issues:

  1. The param type is wrong. The internal implementation of this function does allow for string | null and the public-facing wrapper function should as well. We can fix this.

  1. Setting it to null may not actually do anything in Android (perhaps due to a bug) and you're wondering if it's the same on web. There's 2 ways to find out. The easiest way might be to just use a @ts-ignore on that line really quick to ignore the type check error and just see if it actually sets it. Another way is to set it by calling gtag() directly (gtag('config', YOUR_MEASUREMENT_ID, {'user_id': null}). (If you do this, it may not show up in your Firebase Analytics dashboard and you may have to check your Google Analytics dashboard for it.)

If I have time I can try it out, but if you want to speed things up, you can try both of those things and let me know what happens. They may possibly get different results because they're not exactly identical calls.

@dwyfrequency
Copy link
Contributor

The fix has been released in v9.12.1.

@firebase firebase locked and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants