Context Enricher
The Zaraz Context Enricher is a tool to modify or enrich the context that is being used across Zaraz using a Cloudflare Worker. The Context Enricher allows you access to the client and system variables.
To use a Context Enricher, you first need to create a new Cloudflare Worker. You can do this through the Cloudflare dashboard or by using Wrangler.
To create a new Worker in the Cloudflare dashboard:
- Log in to the Cloudflare dashboard ↗.
- Go to Workers & Pages and select Create application.
- Give a name to your Worker and select Deploy.
- Select Edit code.
You have now created a basic Worker that responds with "Hello world." To make this Worker functional when using it as a Context Enricher, you need to change the code to return the context back:
Keep reading for more complete examples of different use cases or refer to Zaraz Context.
Now that your Worker is published, you can select it in your Zaraz settings:
- Log in to the Cloudflare dashboard ↗.
- Go to Zaraz > Settings.
- Select your Context Enricher Worker.
- Save your settings.
Your Context Enricher will now run on all Zaraz requests in that given zone.
You can use the Context Enricher to add information to your context. For example, you could use an API to get the current weather for the user's location and add it to the context.
Now, you can use the weather property anywhere in Zaraz by choosing the Track Property
from the attributes input and entering weather
.
Let's assume we want to redact sensitive information, such as emails. For this, we're going to replace all occurrences of email addresses throughout the context. Please keep in mind that this is only an example and might not fit all edge or use cases.
For the sake of simplicity of this example, we're going to replace all strings that contain an @
symbol: