Accessing JSON in Cookies

We are currently facing an issue while setting up a trigger for Zaraz Analytics. The trigger is supposed to be based on values stored in a JSON cookie, but it is not functioning as expected.

Our objective is to configure variables by extracting data from a JSON string stored in a cookie. In our attempt to retrieve the user’s ID, we used the following syntax: {{ }}. However, this approach did not work.

Interestingly, we observed that extracting values from a cookie that contains a simple string, number, or boolean works fine. The problem specifically arises when dealing with a JSON string.

Given this scenario, we suspect that we need to parse the value of system.cookies.user into an object. Unfortunately, we have been unable to find any documentation confirming whether this is possible or not.

Any assistance or guidance on resolving this issue would be greatly appreciated.

You can use a Worker Variable for this (Worker Variables · Cloudflare Zaraz docs), or the Context Enricher (Context Enricher · Cloudflare Zaraz docs) . Depending on the structure of the cookie value you might even be able to use JSONata (Using JSONata · Cloudflare Zaraz docs)

We did try JSONata but we couldn’t get it to work. We thought about the context enricher but were waiting to see if we could figure out the JSONata as we are just trying to access two properties from the cookie.

We figured it out using a combo of $decodeUrlComponent and $eval