Solved

Get the Array length of a user property

  • 8 November 2021
  • 8 replies
  • 523 views

Badge

Hey there,

I have a custom User property “subscriptions” that contains an array of strings as so: subscriptions = [“Netflix”, “Disney+”, “Spotify”]

Is it possible to create a chart that shows the number of subscriptions a user has? That would mean I need to somehow get the length of the array in the Segments area.

I am not sure if something like this works:

Could you please clarify how the operators work with arrays and if what I am trying is doable without creating a new property that contains the number of subscriptions such as number_of_subscriptions: 3

Greetings
Leon

icon

Best answer by Leon 9 November 2021, 10:45

View original

8 replies

Userlevel 6
Badge +8

HI @Leon ,

 

I think the easiest thing to do here would be to use PROPCOUNT(event). So if you have an event with this array of subscriptions, I would target the event (or any event), and then group by the subscriptions. You can then use the PROPCOUNT(A) in the charts to see the size of the array. Would that suit what you are looking for?

Badge

Hey @Denis Holmes,

thanks for the reply. I actually did one more round of testing and from what I saw, I got the feeling that I actually CAN check the length of an array by setting the Segment to: 

where subscriptions > 1

for example. Can you confirm this, or did I misinterpret what the graph was showing me?

Userlevel 6
Badge +8

Hi @Leon ,

 

Yes, this is also a very viable option, and probably the better option for what you need! I would use this moving forward and it should suit your needs. :)

Badge

Awesome, thanks Denis. The Documentation wasn’t as specific about that part and was missing some examples about arrays, that’s why I was unsure!

Badge

I’m trying to test this in the AmpliTunes project. I’m trying to get users who have more than 100 playlists, using the Playlists array user property.

It seems that something like Playlists > 100 will not give me users with more than 100 playlists, but instead any users who have a playlist array with at least one array value value greater than 100. 

Is there a way to segment users with more than 100 playlists without instrumenting number_of_playlists user property?

Thanks.

Userlevel 5
Badge +8

Hi @aleksandra-asanin and welcome! Apologies for the delay. One option is to create a cohort to view the # of people who created 100+ playlists within a given period of time. Here’s an example using AmpliTunes.

 

Can we do something similar but for “event property” instead of user property? 

I have a property array, but I want to know the length of the array like:

Subscription - Start 
where: subscriptions (event property) [‘Netflix’, ‘HBO’, ‘Prime’] 

And I want to know, how many events has only 1 value on the array, or 2, or 3 … 

 

Thank you

Hello @Vincent 

You can count the size of the array by creating a derived property

ITEM_COUNT(PROPERTY(‘name of property', 'event'))

Reply