Hi team, I'm using `rudder-sdk-js: ^1.0.18`, and t...
# support
b
Hi team, I'm using
rudder-sdk-js: ^1.0.18
, and trying to use getUserID function. But it is not exported. Could anyone help here please
k
Hey @boundless-football-78239 , Can you please let us know which SDK you are using ?
b
"rudder-sdk-js": "^1.0.18",
k
You are trying to use the getUserID() function because of the issue you just reported below ? CC <!subteam^S04QT1G74Q3|@sdk-team>
b
yes, I tried adding a if check on getUserID function
k
got it, are you seeing that the userId is missing, is this happening immediately or when you open the page next time or some time later ?
b
it is very random. Have tired all 3 approach, userid is there in all 3 times. I'm not able to catch the incident live on api call data. But, in our database there are some userID which are missing, but there user traits are present
Also, why can't I use getUserID function. Why is it not exported
k
so you figured out this issue from your database but from the SDK you could see that everything is fine right ?
b
Yes, on network call in browser, userID is present most of the time. Not able to catch the incident live. But, our database tells us that for some users userID is empty. Also, this is the fix, I'm trying to add: when userID is missing add again before track call
Copy code
if(!window['rudderanalytics']?.getUserId()){
      const user = getUserData();
      if(user){
        window?.['rudderanalytics']?.identify(`${user.userID}`);
      }
    }
But, the function is not defined. But in doc it is
k
got it, let me check on why the getUserId() is not exposed and regarding missing userId but traits being available. What was the datatype of your userId, and can you share few sample events for which traits are present but userId is missing in my DM ?
b
sure
k
seems that you are on a very old version of JS SDK, please update to the latest version of it using the migration guide shared here. once you upgrade to the latest version you should be able to access that API
b
Hi Thanks @kind-carpenter-27609, The version update fix the 1st issue of getUserID. I will dm you sample data for userid missing but user traits are present
👍 1