Personalization用例:购物车放弃电子邮件 personalization-use-case-helper-functions

在此页面上:​遵循购物车放弃用例,该用例使用upperCase、each以及Adobe Journey Optimizer中的辅助函数将电子邮件正文个性化。

在此示例中,您将个性化电子邮件正文。 此消息面向在购物车中遗留商品,但尚未完成购买的客户。

您将使用以下类型的辅助函数:

  • upperCase字符串函数,用于将客户的名字插入大写字母。 了解详情
  • each帮助程序,用于列出购物车中的项目。 了解详情
  • if帮助程序用于插入特定于产品的注释(如果相关产品在购物车中)。 了解详情

➡️ 在此视频中了解如何使用辅助函数

在开始之前,请确保您知道如何配置这些元素:

执行以下步骤:

步骤1:创建初始事件和相关历程 create-context

购物车内容是历程中的上下文信息。 因此,您必须先将初始事件和电子邮件添加到历程,然后才能将购物车特定的信息添加到电子邮件。

  1. 创建其架构包含productListItems数组的事件。

  2. 将此数组中的所有字段定义为此事件的有效负荷字段。

    Adobe Experience Platform文档中了解有关产品列表项数据类型的更多信息。

  3. 创建从此事件开始的历程。

  4. 向历程添加​ 电子邮件 ​活动。

    历程画布,其中包含事件和电子邮件活动

第2步:创建电子邮件 configure-email

  1. 在​ 电子邮件 ​活动中,单击​编辑内容,然后单击​电子邮件Designer

    包含“编辑内容”和“通过电子邮件发送Designer”选项的电子邮件活动

  2. 从电子邮件Designer主页的左侧面板中,将三个结构组件拖放到消息正文上。

  3. 将HTML内容组件拖放到每个新结构组件上。

    发送电子邮件给Designer,邮件正文中包含三个结构组件和HTML内容组件

步骤3:将客户的名字插入大写字母 uppercase-function

  1. 在电子邮件Designer主页上,单击要添加客户名字的HTML组件。

  2. 在上下文工具栏上,单击​显示源代码

    上下文工具栏中的“显示源代码”选项

  3. 在​ 编辑HTML ​窗口中,添加upperCase字符串函数:

    1. 在左侧菜单中,选择​辅助函数

    2. 使用搜索字段查找“大写”。

    3. 从搜索结果中,添加upperCase函数。 为此,请单击{%= upperCase(string) %}: string旁边的加号(+)。

      表达式编辑器显示此表达式:

      code language-handlebars
      {%= upperCase(string) %}
      

      在辅助函数中选择了upperCase函数的 表达式编辑器

  4. 从表达式中删除“string”占位符。

  5. 添加名字令牌:

    1. 在左侧菜单中,选择​配置文件属性

    2. 选择​人员 > 全名

    3. 将​ 名字 ​令牌添加到表达式中。

      表达式编辑器显示此表达式:

      code language-handlebars
      {%= upperCase(profile.person.name.firstName) %}
      

      表达式编辑器显示具有配置文件名字令牌的大写

      Adobe Experience Platform文档中了解有关人员名称数据类型的更多信息。

  6. 单击​验证,然后单击​保存

    使用“验证”和“保存”按钮编辑HTML窗口

  7. 保存消息。

第4步:插入购物车中的项目列表 each-helper

此步骤演示对事件数据进行迭代。 有关迭代不同数据源(事件、自定义操作响应和其他上下文数据)的完整示例,请参阅使用Handlebars迭代上下文数据

  1. 重新打开消息内容。

  2. 在电子邮件Designer主页上,单击要列出购物车内容的HTML组件。

  3. 在上下文工具栏上,单击​显示源代码

    上下文工具栏中的“显示源代码”选项

  4. 在​ 编辑HTML ​窗口中,添加each帮助程序:

    1. 在左侧菜单中,选择​辅助函数

    2. 使用搜索字段查找“each”。

    3. 从搜索结果中,添加each帮助程序。

      表达式编辑器显示此表达式:

      code language-handlebars
      {{#each someArray as |variable|}} {{/each}}
      

      每个帮助程序模板的 表达式编辑器

  5. productListItems数组添加到表达式:

    1. 从表达式中删除“someArray”占位符。

    2. 在左侧菜单中,选择​上下文属性

      上下文属性​仅在历程上下文已传递到消息后可用。

    3. 选择​Journey Optimizer > Events > event_name,然后展开​ productListItems ​节点。

      在此示例中,event_name​表示事件的名称。

    4. 将​ Product ​令牌添加到表达式中。

      表达式编辑器显示此表达式:

      code language-handlebars
      {{#each context.journey.events.event_ID.productListItems.product as |variable|}} {{/each}}
      

      在此示例中,event_ID​表示事件的ID。

      在上下文属性中具有productListItems的 表达式编辑器

    5. 修改表达式:

      1. 删除“.product”字符串。
      2. 将“variable”占位符替换为“product”。

      此示例显示了修改后的表达式:

      code language-handlebars
      {{#each context.journey.events.event_ID.productListItems as |product|}}
      
  6. 将此代码粘贴到开始{{#each}}标记和结束{{/each}}标记之间:

    code language-html
    <table>
       <tbody>
          <tr>
             <td><b>#name</b></td>
             <td><b>#quantity</b></td>
             <td><b>$#priceTotal</b></td>
          </tr>
       </tbody>
    </table>
    
  7. 为项目名称、数量和价格添加个性化令牌:

    1. 从HTML表中删除占位符“#name”。
    2. 从上一个搜索结果中,将​ Name ​令牌添加到表达式中。

    重复这些步骤两次:

    • 将占位符“#quantity”替换为​ 数量 ​令牌。
    • 将占位符“#priceTotal”替换为​ 总价 ​令牌。

    此示例显示了修改后的表达式:

    code language-handlebars
    {{#each context.journey.events.event_ID.productListItems as |product|}}
       <table>
          <tbody>
             <tr>
             <td><b>{{product.name}}</b></td>
             <td><b>{{product.quantity}}</b></td>
             <td><b>${{product.priceTotal}}</b></td>
             </tr>
          </tbody>
       </table>
    {{/each}}
    
  8. 单击​验证,然后单击​保存

    在配置每个块后,使用“验证并保存”的 表达式编辑器

步骤5:插入特定于产品的说明 if-helper

  1. 在电子邮件Designer主页上,单击要在其中插入注释的HTML组件。

  2. 在上下文工具栏上,单击​显示源代码

    上下文工具栏中的“显示源代码”选项

  3. 在​ 编辑HTML ​窗口中,添加if帮助程序:

    1. 在左侧菜单中,选择​辅助函数

    2. 使用搜索字段查找“if”。

    3. 从搜索结果中,添加if帮助程序。

      表达式编辑器显示此表达式:

      code language-handlebars
      {%#if condition1%} render_1
         {%else if condition2%} render_2
         {%else%} default_render
      {%/if%}
      

      带有if帮助程序模板的 表达式编辑器

  4. 从表达式中删除此条件:

    code language-handlebars
    {%else if condition2%} render_2
    

    此示例显示了修改后的表达式:

    code language-handlebars
    {%#if condition1%} render_1
       {%else%} default_render
    {%/if%}
    
  5. 将产品名称令牌添加到条件:

    1. 从表达式中删除“condition1”占位符。

    2. 在左侧菜单中,选择​上下文属性

    3. 选择​Journey Orchestration > Events > event_name,然后展开​ productListItems ​节点。

      在此示例中,event_name​表示事件的名称。

    4. 将​ Name ​令牌添加到表达式中。

      表达式编辑器显示此表达式:

      code language-handlebars
      {%#if context.journey.events.`event_ID`.productListItems.name%}
         render_1
         {%else%} default_render
      {%/if%}
      

      在if条件中具有productListItems名称令牌的 表达式编辑器

  6. 修改表达式:

    1. 在表达式编辑器中,在name令牌之后指定产品名称。

      使用以下语法,其中​ product_name ​表示产品的名称:

      code language-javascript
      = "product_name"
      

      在此示例中,产品名称为“Juno Jacket”:

      code language-handlebars
      {%#if context.journey.events.`event_ID`.productListItems.name = "Juno Jacket" %}
         render_1
         {%else%} default_render
      {%/if%}
      
    2. 将“render_1”占位符替换为注释文本。

      示例:

      code language-handlebars
      {%#if context.journey.events.`event_ID`.productListItems.name = "Juno Jacket" %}
         Due to longer than usual lead times on the Juno Jacket, please expect item to ship two weeks after purchase.
         {%else%} default_render
      {%/if%}
      
    3. 从表达式中删除“default_render”占位符。

  7. 单击​验证,然后单击​保存

    配置if块后,使用“验证并保存”编辑HTML窗口

  8. 保存消息。

步骤6:测试并发布旅程 test-and-publish

  1. 打开​ 测试 ​切换开关,然后单击​触发事件

    历程切换为打开并触发事件按钮

  2. 在​ 事件配置 ​窗口中,输入输入值,然后单击​发送

    测试模式仅适用于测试用户档案。

    具有输入值和发送按钮的事件配置窗口

    电子邮件将发送到测试用户档案的地址。

    在此示例中,电子邮件包含有关Juno Jacket的注释,因为该产品位于购物车中:

    在邮件正文中显示Juno Jacket送货注释的示例电子邮件

  3. 验证没有错误,然后发布历程。

Handlebars函数 handlebars

用例 use-case

操作方法视频 video

了解如何使用辅助函数。

AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: This page walks through a cart abandonment email use case using three helper functions — upperCase, each, and if — to display a customer’s first name in capitals, list cart items, and insert a product-specific shipping note conditionally.

Intents:

  • Create a journey event whose schema includes the productListItems array
  • Insert a customer’s first name in uppercase using {%= upperCase(profile.person.name.firstName) %}
  • List cart items by iterating over context.journey.events.event_ID.productListItems with {{#each}}
  • Display a product-specific note conditionally using {%#if context.journey.events.\event_ID`.productListItems.name = “product_name” %}`
  • Test the journey in test mode using a test profile with event payload, then publish

Glossary:

  • upperCase: A PQL string function that converts a string to uppercase; called with {%= upperCase(string) %}. (product-specific)
  • each helper: A Handlebars block helper ({{#each array as |alias|}} ... {{/each}}) that iterates over an array such as productListItems. (product-specific)
  • if helper: A conditional block helper ({%#if condition%} ... {%else%} ... {%/if%}) that renders content only when the specified condition is true.
  • productListItems: A standard XDM array representing cart contents, with fields including name, quantity, and priceTotal. (product-specific)
  • Test mode: A journey feature that enables sending test messages to test profile addresses to verify journey and message behavior before publication. (product-specific)

Guardrails:

  • Contextual attributes (including journey event data) are available in the personalization editor only after the message has been placed inside a journey that includes the relevant event.
  • Test mode works only with test profiles.

Terminology:

  • Canonical name: cart abandonment email — variants: cart abandonment use case
  • Do not confuse: context.journey.events.event_ID.productListItems (event-sourced array, accessed via Contextual attributes) ≠ profile.* attributes (profile-sourced, always available)

FAQ:

  • Q: What helper functions are used in this use case? — Three: upperCase (renders first name in capitals), each (iterates over the cart items array), and if (conditionally displays a product-specific shipping note).
  • Q: Where does the cart item data come from in the personalization expression? — From the journey event’s productListItems array, accessed via Contextual attributes at context.journey.events.event_ID.productListItems.
  • Q: Can contextual attributes be used before placing the message inside a journey? — No. Contextual attributes are available in the personalization editor only after the message is placed inside a journey that includes the relevant event.
  • Q: How do I test the email with cart data? — Turn on the Test toggle in the journey, click Trigger an event, and enter the input values in the Event configuration window, then click Send. The email is sent to the test profile’s address.
recommendation-more-help
journey-optimizer-help