Description
You can reference ODP Behaviors to pull in information including:
- Products the users have abandoned in their cart
- The last brand users browsed on your site
- The last product users purchased
- Custom data you store in ODP (product reviews, blog posts, etc.)
- Referencing behaviors is point-and-click
You can use Liquid to achieve advanced use cases, too:
- Show products that pair well with purchased products, by showing pairings stored in a custom object
- Show products of the same brand as the last brand a user browsed
Steps
How do you reference a Behavior using Liquid?
- Create the behavior in ODP (click the 3 dots at the top nav > Behaviors).
- In ZED, drag in a Dynamic Grid. In the Details tab of the grid, select the object you want data from via the Content Feed dropdown.
- Select the Behavior from the Source dropdown. For this example, we search for "Cart Abandonment"
- Click ‘Convert to Liquid’ .
5. Copy the Liquid generated in ‘Liquid Array Reference’
6. Paste into text element, Variables section, setup block, or a separate text editor
7. Add assignment syntax and opening/closing brackets ( {% assign x = ...%} )
8.Modify any fields ( product_id ) and clauses of the behavior lookup ( .step1, .top, .limit(4) )
9. Apply it to the rest of the logic you are creating.
Liquid Code Breakdown - What exactly can you modify in a behavioral lookup?
Let’s break down the Liquid code used in the previous slide:
behavior.abandon_cart_behavior(range_start: 'auto', range_end: now(0), required: true, filters: array('z_content_shield_filter')).step1.list.product(product_id).top.limit(4)
- ‘behavior.’ → indicates we are doing a behavioral lookup
- ‘.abandon_cart_behavior’ → the Behavior key/the name of the Behavior as used by Liquid
- ‘range_start ...range_end…’ → the time frame; ‘auto’ indicates ‘since the user qualified for the campaign’
- ‘required: true’ → true/false indicates if the user is required to fulfill the behavior to qualify for the campaign
- ‘filters: ...filter’)’ → this requires the returned data to fulfill the account level Content Shield
- ‘step1’ → indicates which step in the behavior we want to return data from
- ‘list’ → indicates a list of data to be returned; omitting ‘list’ will result in just 1 record being returned
- ‘product’ → the object we want data from; this can be ‘event’, ‘order’ or a custom object
- ‘product_id’ → the field we want data from; this can be any field in the referenced object and its child objects
- ‘top’ → this indicates the results’ sorting order; can also be ‘bottom’, ‘oldest’, ‘newest’
- ‘limit(4)’ → limits how many records to be returned; without a limit specified, 10 records are returned
As with object lookups, child objects can be referenced through behavioral lookups;
- step1.list.event(product.image_url, product.name, product.price).top.limit(4)
- step1.list.product(image_url, name, price, category.path, category.name_0).top.limit(4)
- step1.list.event(product.name, product.price, product.category.path, product.category.name_0).top.limit(4)
Additional Resources
- Liquid is “an open source template language created by Shopify”
- “Open source”: Engineers can make changes to it and adapt it for their own needs -- we did this
- “Template language”: A nice way to put data on an email/page
- Sources of public documentation:
- Shopify’s: https://help.shopify.com/en/themes/liquid
- Ours: https://support.optimizely.com/hc/en-us/articles/4407775274253-Personalize-with-optional-content
- Ours: https://support.optimizely.com/hc/en-us/articles/4407775333261-Advanced-Liquid-capabilities-in-ODP
- Shopify also has a Github repo for local testing: https://shopify.github.io/liquid/
Please sign in to leave a comment.