Question

Is array of objects possible in UserProperties? Does Amplitude charts allow insights on the key inside array objects ?

  • 12 October 2021
  • 7 replies
  • 69 views

Badge

I have a device on which I connect 3 USB Cameras named : Front, Left, Right.
There will be definately be charts based on the event_type and event_properties.

But, here I am interested in charts that I can create from User Properties.
The User(or device) Properties in any event, may have attached usb array object as below :

{
"device_id": "C8F9E604-F01A-4BD9-95C6-8E5357DF265D",
"event_type": "Camera started",
"event_properties": {
"camera_name": "Left"
},
"os_name": "Android",
"os_version": "4.2.2",
"device_brand": "Verizon",
"device_manufacturer": "Apple",
"device_model": "iPhone 9,1",
"firmware_version": "02.04.10.22",
"usbPeripherals": [
{
"cameraCapable": true,
"microphoneCapable": true,
"speakerCapable": false,
"name": "Left",
"model": "C635",
"vendor": "Logitech"
},
{
"cameraCapable": true,
"microphoneCapable": false,
"speakerCapable": false,
"name": "Front",
"model": "DS-0021",
"vendor": "Hikvision"
},
{
"cameraCapable": true,
"microphoneCapable": false,
"speakerCapable": false,
"name": "Right",
"model": "JC-20",
"vendor": "Jabra"
}
]
}

Is this event structure possible and useful to create below charts?
If not , What can be done differently in event structure for below charts?

Can I create chart say showing distribution of vendors of all camera plugged into across devices  and see camera-only vs other peripheral ?
Can I create a chart showing growth of a particular or top 5 camera vendors over time ?

 


7 replies

Userlevel 4
Badge +4

Hi @vjbhakta ! Welcome to the Community and I’m happy to help! :wave_tone1:

While it is the case that Amplitude can extrapolate nested objects, Amplitude does not really support array of objects and therefore the structure of array of objects is not going to be useful to create charts. If you sent an array of objects like the example you shared, Amplitude will stringify the array of objects. Since it becomes a string, you will not be able to really query on the individual object and therefore will not be able to simply pull the vendor values. 

As such, what can be done differently in event structure in order to be able to create the chart scenarios that you provided is to separate out the arrays. What I mean by this is sending something like 

 "usbPeripherals_vendor": ["Logitech", "etc", "etc"]

When you send the above under the user_properties field, you can then do a group by on usbPeripherals_vendor which will break down the individual values. 

Hope this helps! Let me know if you have any questions. 

Userlevel 6
Badge +4

Agree with Belinda here.

Sending those values in an array as she pointed out is an easier approach for charting purposes, especially when doing a group by.

Also, if you have a single nested json object property, you can try leveraging the EXTRACT_FROM_DICT function in the derived properties feature to create properties on the fly based on a specific key value if that appears useful.

 

Badge

In that case, how would I corelate which type of Peripheral (Camera-only or Camera+microphone) it is and from which vendor ?  say how to create a pie-chart of vendors or models which are camera-only ?
or say pie-chart for models from same vendor and see most popular model from same vendor ?

String array index based ? 
e.g.

"usbPeripherals_vendor": ["Logitech", "Hikvision", "etc"]
"usbPeripherals_model": ["C635", "DS-0021", "etc"]
"usbPeripherals_type": ["Camera+Microphone", "Camera-Only", "etc"]

first entry in string array is for first peripheral in all properties.

Badge

Or Instead of array , will nested property objects help to achieve intended charts? 

e.g. 
 

{
"device_id": "C8F9E604-F01A-4BD9-95C6-8E5357DF265D",
"event_type": "Camera started",
"event_properties": {
"camera_name": "Left"
},
"os_name": "Android",
"os_version": "4.2.2",
"device_brand": "Verizon",
"device_manufacturer": "Apple",
"device_model": "iPhone 9,1",
"firmware_version": "02.04.10.22",
"left_camera": {
"cameraCapable": true,
"microphoneCapable": true,
"speakerCapable": false,
"name": "Left",
"model": "C635",
"vendor": "Logitech"
},
"front_camera": {
"cameraCapable": true,
"microphoneCapable": false,
"speakerCapable": false,
"name": "Front",
"model": "DS-0021",
"vendor": "Hikvision"
},
"right_camera": {
"cameraCapable": true,
"microphoneCapable": false,
"speakerCapable": false,
"name": "Right",
"model": "JC-20",
"vendor": "Jabra"
}
}

is such nested propery possible ?

Does amplitude lists such property in dropdown e.g. front_camera.vendor or front_camera.model ?

Userlevel 4
Badge +4

@vjbhakta Based on your use case, I think nested property objects would help achieve intended charts! Nested property is possible - just not nested arrays. And yes, Amplitude will be able to extrapolate nested property objects into  e.g. front_camera.vendor or front_camera.model, 

By the way, I noticed the camera properties are not under event_properties. Please make sure you add the properties under event_properties as firmware_version, left_camera, etc are not valid top-level fields. 

Badge

@belinda.chiu Thanks for your input. I will try out something with this notation. 
In event-properties , camera in action (turned-on, turned-off) will be mentioned e.g.  camera_name (left, right, front) . but the details of the camera(s) attached to device will be in device properties as per my understanding.

One further question: 
what level of depth is supported for nested properties ?

Userlevel 4
Badge +4

@vjbhakta Ah, I was under the assumption that you were going to send the data to us server-side in which the fields we would support are as followed: https://developers.amplitude.com/docs/http-api-v2#uploadrequestbody

But if you are sending this data through some sort of integration that would help you rearrange the “device properties" as event properties or user properties then do ignore my statement! 

For the depth of the nested properties, I don’t think there’s a limit. But please note that we will extrapolate accordingly: 

  curl -H 'Content-Type: application/json' -d '{"api_key":"API KEY","events":[{"user_id": "test nested property layer", "event_type":"test", "user_properties":{"Nest 1":{"level 1": {"sublevel 1":{"subsublevel 1":"value"}}}},"country":"United States", "ip":"127.0.0.1"}]}' https://api.amplitude.com/2/httpapi

 

Reply