Context
Context steps allow you to create and update one or more variables for a user as they move through a Canvas. For example, if you have a Canvas that manages seasonal discounts, you can use a context variable to store a different discount code each time a user enters the Canvas.
Context steps are currently in early access. Contact your Braze account manager if you’re interested in participating in this early access.
How it works
Context steps allows you to create and use temporary data during a user’s journey through a specific Canvas. This data exists only within that Canvas journey and doesn’t persist across different Canvases or outside the session.
Within this framework, each Context step can define multiple context variables—temporary pieces of data that enable you to personalize delays, segment users dynamically, and enrich messaging without permanently altering a user’s profile information.
For example, if you’re managing flight bookings, you could create a context variable for each user’s scheduled flight time. You could then set delays relative to each user’s flight time and send personalized reminders from the same Canvas.
You can set context variables in two ways:
- At Canvas entry: When users enter a Canvas, data from the event or API trigger can automatically populate context variables.
- In a Context step: You can define or update context variables manually inside the Canvas by adding a Context step.
Each context variable includes:
- A name (such as
flight_time
orsubscription_renewal_date
) - A data type (such as number, string, time, or array)
- A value you assign using Liquid or through the Add Personalization tool.
When defined, you can use a context variable throughout the Canvas by referencing it in this format: {{context.${example_variable_name}}}
.
For example,
{{context.${flight_time}}}
could return the user’s scheduled flight time.
Each time a user enters the Canvas—even if they have entered it before—the context variables will be redefined based on the latest entry data and Canvas setup. This allows journeys to stay personalized and accurate, even for users with multiple entries.
Creating a Context step
Step 1: Add a step
Add a step to your Canvas, then drag and drop the component from the sidebar, or select the plus button and select Context.
Step 2: Define the variables
You can define up to 10 context variables for each Context step.
To define a context variable:
- Give your context variable a name.
- Select a data type.
- Write a Liquid expression manually or use Add Personalization to create a Liquid snippet from pre-existing attributes.
- Select Preview to check the value of your context variable.
- (Optional) To additional variables, select Add Context variable and repeat steps 1–4.
- When you’re finished, select Done.
Now you can use your context variable anywhere you use Liquid, such as in Message and User Update steps, by selecting Add Personalization. For a full walkthrough, see Using context variables.
Step 3: Test user paths (optional)
If the context variable is valid, you can reference the variable throughout your Canvas. However, if the context variable wasn’t created correctly, future steps in your Canvas won’t perform correctly either. We recommend testing and previewing your user paths to make sure your messages are sent to the right audience. Look out for common scenarios that create invalid context variables.
For example, if you create a Context step to assign users an appointment time but set the appointment time’s value to a past date, the reminder email you craft in your Message step will never be sent.
Context variable data types
Context variables that are created or updated in the step can be assigned the following data types.
Context variables have the same expected formats for data types as custom events, but context variables do not support nested objects.
Data type | Example variable name | Example value |
---|---|---|
Boolean | loyalty_program | true |
Number | credit_score | 740 |
String | product_name | green_tea |
Array | favorite_products | ["wireless_headphones", "smart_homehub", "fitness_tracker_swatch"] |
Time | last_purchase_date | 2025-12-25T08:15:30:250-0800 |
Object (flattened) | user_profile | { |
Using context variables
For example, let’s say you want to notify passengers about their VIP lounge access before their upcoming flight. This message should only be sent to passengers who purchased a first-class ticket. A context variable is a flexible way to track this information.
Users will enter the Canvas when they purchase a plane ticket. To determine lounge access eligibility, we’ll create a context variable called lounge_access_granted
in a Context step, then reference that context variable in subsequent steps of the user journey.
In this Context step, we’ll use {{custom_attribute.${purchased_flight}}}
to determine if the type of flight they’ve purchased is first class.
Next, we’ll create a Message step to target users where {{context.${lounge_access_granted}}}
is true
. This message will be a a push notification that includes personalized lounge information. Based on this context variable, the eligible passengers will receive the relevant messages before their flight.
- First-class ticket passengers will receive: “Enjoy exclusive VIP lounge access!”
- Business and economy ticket passengers will receive: “Upgrade your flight for exclusive VIP lounge access.”
You can add personalized delay options with the information from the Context step, meaning you can select the variable that delays users.
Converting Connected Content strings to JSON
When making a Connected Content call in a Context step, JSON returned from the call will be evaluated as a string data type for consistency and error prevention. If you want to convert this string into JSON, convert it by using as_json_string
. For example:
1
2
{% connected_content http://example.com :save product %}
{{ product | as_json_string }}
Troubleshooting
Invalid context variables
A context variable is considered invalid when:
- A call to an embedded Connected Content fails.
- The Liquid expression at runtime returns a value that doesn’t match the data type or is empty (null).
For example, if the context variable data type is Number but the Liquid expression returns a string, it is invalid.
In these circumstances:
- The user will advance to the next step.
- The Canvas step analytics will count this as Not Updated.
When troubleshooting, monitor the Not Updated metric to check that your context variable is updating correctly. If the context variable is invalid, your users can continue in your Canvas past the Context step, but may not qualify for later steps.
Refer to Context variable data types for the example setups for each data type.
Frequently asked questions
How do context variables differ from Canvas entry properties?
If you’re participating in the Context step early access, Canvas entry properties are now included as Canvas context variables. This means you can send Canvas entry properties using the Braze API and reference them in other steps, similar to using a context variable with the Liquid snippet.
Can variables reference each other in a singular Context step?
Yes. All variables in a Context step are evaluated in a sequence, meaning you could have the following context variables setup:
Context variable | Value | Description |
---|---|---|
favorite_cuisine |
{{custom_attribute.${Favorite Cuisine}}} |
A user’s favorite type of cuisine. |
promo_code |
EATFRESH |
The available discount code for a user. |
personalized_message |
"Enjoy a discount of" {{promo_code}} "on delivery from your favorite" {{favorite_cuisine}} restaurants!" |
A personalized message that combines the previous variables. |
In a Message step, you could use the Liquid snippet {{context.${personalized_message}}}
to reference the context variable to deliver a personalized message to each user.
This also applies across multiple Context steps. For example, imagine this sequence:
- An initial Context step creates a variable called
JobInfo
with the valuejob_title
. - A Message step references
{{context.${JobInfo}}}
and displaysjob_title
to the user. - Later, a Context step updates the context variable, changing the value of
JobInfo
tojob_description
. - All subsequent steps that reference
JobInfo
will now use the updated valuejob_description
.
Context variables use their most recent value throughout the Canvas, with each update affecting all following steps that reference that variable.