Sending a Complex Search Result Event

Hello everyone!

I’m in need of some counseling. We are trying to send an event using the Js Tracker that would include an entire list of search results, each item is a complex nested object, they look pretty much like this:
{
propertyId: 2,
//some flat properties
rates: [
{
rateId: 56,
//some flat properties
}
]
}

We have been trying to store this as structured events but the smallest we can set the payload is near 5000 characters. Given the char limit of 4096 we are looking for an alternative. We are looking into self describing events but these should be flat objects if I am not mistaken, right?

Is there any standard way we should be doing this?

Thanks for any help in advance!

They don’t have to be flat objects. You can define nested fields in your schema, objects and arrays are supported. They’re just generally tricky to manage.

The one caveat, however, is that if you’re using Redshift as a storage target, that DB is pretty poor when it comes to support for object and array datatypes - these will be loaded as strings, and you’ll need to parse them out when querying.

One potential way to deal with that is to parse the object in the front end, and send the array items as entities (aka contexts) - you can attach these to an event multiple times.

So if the JSON you provided is named ‘obj’ you would do something with a rough logic along the lines of the below (which is a quite hastily written example):

SdEvent = {"schema": "iglu:...", "data": {"propertyId": obj.propertyId, ...}}

ratesEntities = obj.rates.map(x => {"schema": "iglu:...", "data": x})

snowplow('trackSelfDescribingEvent', SdEvent, ratesEntities);

This way you would end up with one row per propertyId in one table, and a one-to-many join on anther table for the items in the array.

If you’re using Snowflake or BigQuery, those databases handle nested and repeated data just fine, so you don’t need to go to that effort.

Hope that helps!

1 Like

You could also make use of the trackSiteSearch function with the site_search schema too and add your results as custom contexts as Colm describes

Docs: https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker#312-tracksitesearch

1 Like