Solved

Get user properties in Javascript SDK

  • 3 August 2022
  • 3 replies
  • 389 views

Is it possible to get user properties or just set them? I’m currently using `Identify().append()` to add Optimizely experiment IDs to an `experiments` property, but if a user visits the same page, that experiment is added to the array again. I’m trying to figure out how I can avoid duplicating items in the array.

icon

Best answer by Zhenia Semenina 17 August 2022, 11:05

View original

3 replies

Userlevel 4
Badge +7

Hey there,

Thanks for writing in! 

We use Identify to work with user properties and currently this is indeed the best way to update / edit/ set user properties. 

 

To avoid duplication you could try and build some internal logic in your code that would check current items in the array and only append a new one if it does not exist yet (e.g if...else)

 

That’s what comes to mind! 

 

@Zhenia Semenina That’s exactly what I had in mind, but couldn’t figure out how to access the current items in the array. Is there a method for that? All I’ve seen in the docs is setters, no getters.

Userlevel 4
Badge +7

You could try to make a call using User Profile API and check properties assigned to a specific user.

Read more on it here: 

https://www.docs.developers.amplitude.com/analytics/apis/user-profile-api/#get-user-properties 

 

 

I would not be able to provide exact code snippets but maybe someone on the forum implemented something like this in the past? Would love to hear your experience! 

 

Best,

Zhenia

Reply