Matching your schema

Now that we've found the UserEvent type, we have to look at the properties it has.

In our example, there are only 3 properties: id, timestamp and name. id and timestamp will be autogenerated by the system, so the only info we can add is the name. That's what we do when we send a event this way:

mics.push("my-event-name");

But now let's consider that we've added some properties to our schema. For instance, when a user gets to the cart page, I want to track the items which are in his/her cart. Each item will have a brand name and its own name.

Your UserEvent type should look something like this:

type UserEvent  {
    id:ID! @TreeIndex(index:"USER_INDEX")
    ts:Timestamp! @TreeIndex(index:"USER_INDEX")
    name:String! @TreeIndex(index:"USER_INDEX")
    items:[Item!]
}

type Item  {
    id:ID! @TreeIndex(index:"USER_INDEX")
    brand:String! @TreeIndex(index:"USER_INDEX")
    name:String! @TreeIndex(index:"USER_INDEX")
}

Now if you want to send this information along with your event, you have to match the structure of your schema, the name of your event being the 1st parameter in the push method, and the 2nd parameter containing all non system-generated properties (remember: UserEvent id and timestamp will be autogenerated).

mics.push("cart-view", {
    "items": [
        {
            "brand": "brand name 1", 
            "name": "product name 1",
            "id": 1
        },
        {
            "brand": "brand name 2", 
            "name": "product name 2",
            "id": 2
        }
    ],
});

Last updated