clever-army-23352
06/07/2023, 8:28 PMrudderanalytics.getAnonymousId()
as shown below
rudderanalytics.identify({ action: "impression"}, traits, function(){
console.log(rudderanalytics.getAnonymousId())
})
The issue we have is the getAnonymousId
call just returns undefined but according to the SDK documentation it should give the actual Id. https://rudderlabs.gitbook.io/rudderlabs-1/docs/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk/js-sdk-faqs.
So why is this happening and why can't we retrieve the anonymousId after we call identify?high-zoo-17436
06/08/2023, 4:56 AMrudderanalytics.getAnonymousId()
2. This is not the right way to call identify
rudderanalytics.identify({ action: "impression"}, traits, function(){
console.log(rudderanalytics.getAnonymousId())
})
The first parameter should be the userId not some object. Ref: https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/supported-api/#identify
You can make use of this onLoaded load option to get anonymousId. Ref: https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk/#onloadedclever-army-23352
06/08/2023, 1:29 PMhigh-zoo-17436
06/09/2023, 4:46 AMIn the case of the first item being the userId, that is only in the case when there is one to be added, but if there is not a userID calling identify will then generate an anonymousId doesn’t it?No As I already mentioned anonymousId is not dependent on identify call. Once you call
rudderanalytics.load()
and the SDK is loaded it is being created.clever-army-23352
06/09/2023, 3:26 PM