Skip to main content

When I am sending user id in init method, it sets the amplitude user id which is working fine, but when I call the init method without user id ( null ), it still uses the old user id. It should set the user id as null.
Is this an expected behaviour or it is a bug?
Do I need to use the setUserId method separately ? ( this one I don’t prefer as it is not a promise )

Hi @Vishal 

I’m not quite sure here, but you can try using this to set user_id as null instead of init method

amplitude.getInstance().setUserId(null);

https://www.docs.developers.amplitude.com/data/sdks/javascript/#logged-out-and-anonymous-users

 


Hi @Saish Redkar thanks for your reply, I really appreciate.
But I don’t want to use setUserId(null) method as this is not a promise and I have like chain of amplitude api calls, which should be executed in the way it is written.
So using setUserId(null) ( not a promise ) will create inconsistency. 
Thanks again 😊


By the way @Saish Redkar does this happen on your end as well ?
I am passing null to setUserId and it causes this error can not read length of null ?
I mean this is really weird.


Alright I found out that if we want to reset the user id during initialisation we have to pass empty string in init(api_key, user_id || “”) method.


We are using Google Tag Manager.

We’re having an issue where we do not see setUserId in our Init tag anywhere, but it is coming through in our Custom event data. We do not currently have custom UserId to use and do not want to set it.

The only different item is that we do have tag sequencing on to make sure our init tag fires before the event (we’re just testing things out). Where else could this setUserId be getting set? Could it be in the GTM template somehow?

I’ve published our GTM container to make sure all changes are live. We’re using the Amplitude Browser SDK tag in GTM. My project key matches the API key I put into the tag.

Thank you

This is a custom tag we’re testing to send viewed page data as a Custom Event.

 


Reply