With the introduction of Segment Builder 2.0, the way you utilize behaviors inside of your templates will (at least in some places) be changing. This is a guide to walk you through what you'll need to know.

We'll explain by way of example.

The Old Way with Segment Builder 1.0

Let's say you create a Cart Abandon campaign, using a segment with a Cart Abandonment behavior. You'd have a segment defined something like this:

If, in your template, you want to grab the products that were abandoned as part of that behavior used in your segment, you could use Liquid code that looks like this:

{% assign products_abandoned = step1.list.product(product_id, name, price).newest.limit(4) %}

Let's focus on the "step1" part of the above Liquid code. That "step1" automatically references back to step #1 of the behavior used in your segment - in this case, the add_to_cart event. We call this an "implicit" reference, because you are not specifying the behavior you want to reference, but rather just telling Zaius to just go check which behavior is being used in the segment applied to the campaign.

The New Way with Segment Builder 2.0

You may have noticed that in Segment Builder 1.0, you were only able to use a single behavior. In Segment Builder 2.0, you are allowed to use *multiple* behaviors! This opens up additional complex use cases that previously were difficult or impossible to achieve (for example, targeting both browse abandoners and cart abandoners in the same campaign).

Since you can now have more than one behavior in your segment, Zaius can no longer *implicitly* know which behavior you're using. Instead, you have to specify the exact behavior you want to reference - we call this an "explicit" reference.

So now, if you want to reference a behavior in your template (let's keep using the cart abandonment example), your Liquid code will need to look something like this:

{% assign products_abandoned = behavior.cart_abandonment_behavior(range_start: now(-14400), range_end: now(0), required: true).step1.list.product(product_id, name, price).newest.limit(4) %}

You'll notice that everything after (and including) "step1" is still the same, but there's now new Liquid code in the beginning to specify and configure your behavior. Below is just the new code.

behavior.cart_abandonment_behavior(range_start: now(-14400), range_end: now(0), required: true)

We'll step through each part of the above new Liquid code to explain what it all means:

behavior

All references to a behavior will simply start with "behavior".

cart_abandonment_behavior

This is the identifier of the behavior you want to reference - typically, this is just the name of your behavior, with underscores instead of spaces, and removed special characters.

range_start: now(-14400)

You need to specify the timeframe you want to use for your behavior, in seconds. In our example we used a timeframe of "in the last 4 hours". So the beginning of our range is 4 hours ago, which is the equivalent of 14400 seconds ago. We can tell Zaius to go back 14400 seconds by using "now(-14400)".

range_end: now(0)

Now we need to specify the *end* of the timeframe you want to use for your behavior. Our timeframe ends *right now*, so we can simply use "now(0)".

required: true

You can tell Zaius whether customers are required to have completed the specified behavior to be allowed to receive the campaign. If the behavior is required, use "true" - if it isn't, use "false".

This sounds difficult! Is there an easier way?

We do have a shortcut for you to help you get at the Liquid code you'll need to explicitly reference your behaviors! Let's keep going with our cart abandonment example.

1. Add a dynamic grid anywhere in your template.
2. Add a Text element to the top left cell. Reference the fields you plan to use in your template by typing them out in Liquid. In our example, you may have {{ product.name }} and {{ product.price }}, because you want to show the name and price of the products that were abandoned.

You'll have something like this:

3. Open up the Details tab for the dynamic grid. Select the behavior you want to use as the **Source**, and modify the **Timeframe** as desired.
4. Toggle on "More Options". Change any other options you may care about, such as the **Sort order**, or whether or not the behavior is **Required** for customers to have completed to receive the campaign.

You'll now see a setup something like this:

5. Toggle on "Use Custom Liquid".

You'll now see the Liquid code automatically generated for you!

6. Click on the Liquid code to pop open a modal. Copy the Liquid, and paste it wherever you need in your template!
7. You can delete the dynamic grid when you're done - it has served its purpose!

When do I have to do all this?

Through the above shortcut, you'll have noticed that, when using behaviors inside of dynamic grids specifically, Zaius already *automatically* creates the Liquid code for referencing behaviors the new way. This means that, if you are just using behaviors inside of dynamic grids, there's nothing more to do!

If you are using behaviors *outside* of dynamic grids, that's when you'll need to write out the Liquid code the manual way. If you've been using behaviors outside of dynamic grids, though, you'll already be used to that! Now there's just a little more code to write, to give Zaius the explicit reference it needs.

What happens if I don't update these behavior references?

If you don't make these changes, and try to launch a campaign with the old Liquid code method, you'll see an error like this:

That will tell you that there's an "implicit" behavior reference somewhere in your template!

Do I have to update all my existing templates?

Don't you worry! When you start using Segment Builder 2.0, we will automatically update the templates in your campaigns to use the new "explicit" reference format.

Keep in mind that any templates you have saved in the "Templates" area of the tool will *not* be automatically updated - since they don't live inside campaigns, they aren't linked to a specific segment, so Zaius has no way of knowing which behavior is the right one. If you need to update these templates, you'll want to use the methods laid out above.

Did this answer your question?