使用 Liquid 自訂您的 Shopify Messaging 行銷活動
Liquid 是 Shopify 的簡單易用程式語言,在 Shopify Theme Store 中的佈景主題也是使用這個語言建立。
您可以使用自訂 Liquid 強化 Shopify Messaging 訊息,方式包括 creating an entirely custom-coded email,或在範本中 adding a custom Liquid section。這些選項可讓您輸入自訂 Liquid 或 HTML。
您可以使用自訂 Liquid 顯示自訂資產,例如並排圖片、自訂按鈕、自訂尺寸圖片,以及自訂區段大小。
本頁內容
注意事項
在開始為 Shopify Messaging 訊息加入自訂 Liquid 之前,請先閱讀下列注意事項:
- 您在程式碼中加入的變數必須 supported by custom Liquid。
- 您只能使用電腦裝置建立自訂 Liquid 區段。
- 在自訂 Liquid 電子郵件中,必須包含
unsubscribe_link或unsubscribe_url變數。若您已啟用電子郵件開啟動作追蹤,則也必須加入open_tracking變數。Learn more about adding required variables to your email。 - 您輸入的程式碼有以下限制:
- 自訂 Liquid 區段上限為 50 KB。
- 自訂程式碼的 Liquid 電子郵件上限為 500 KB。
使用 Liquid 建立自訂程式碼電子郵件
建立電子郵件時若要使用自訂 Liquid 程式碼,您可以 add a custom Liquid section,或在 create a Shopify Messaging campaign 時選取 自行撰寫程式碼,以完全以自訂 Liquid 程式碼建立電子郵件。
自訂 Liquid 支援的 Liquid 變數
您可以使用受支援的變數,透過 Liquid 自訂 Shopify Messaging 電子郵件訊息。您可以檢視下列範本類型所支援的 Liquid 變數清單:
- All email templates
- Abandoned checkout email templates
- Abandoned browse and abandoned cart email templates
所有電子郵件範本可用的 Liquid 變數
您可以使用下列變數,透過 Liquid 自訂任何 Shopify Messaging 電子郵件訊息。
| 變數 | 說明 |
|---|---|
all_products | 您商店中的 All of the products。 |
customer.accepts_marketing | 若顧客同意接收行銷資訊,則傳回 true,否則傳回 false。 |
customer.addresses | 傳回與該顧客相關的所有地址。 |
customer.addresses_count | 傳回與該顧客相關的地址數量。 |
customer.b2b? | 若該顧客為 B2B 顧客,則傳回 true,否則傳回 false。 |
customer.current_location | 傳回該顧客目前選取的公司地址。 |
customer.default_address | 傳回該顧客的預設地址。 |
customer.email | 傳回該顧客的電子郵件地址。 |
customer.first_name | 傳回該顧客的名字。 |
customer.has_account | 若該顧客的電子郵件與 customer account 關聯,則傳回 true,否則傳回 false。 |
customer.has_avatar? | 若顧客帳號已關聯頭像,則傳回 true,否則傳回 false。 |
customer.id | 傳回顧客的 ID。 |
customer.last_name | 傳回顧客的姓氏。 |
customer.last_order | 傳回顧客最近一次下的訂單,不包含測試訂單。 |
customer.name | 傳回顧客的全名。 |
customer.orders | 傳回顧客下的所有訂單。 |
customer.orders_count | 傳回顧客下的訂單總數。 |
customer.payment_methods | 傳回顧客已儲存的付款方式。 |
customer.phone | 傳回顧客的電話號碼。僅在顧客於結帳頁面使用電話號碼、已同意接收簡訊通知,或您已手動將電話號碼加入其顧客帳號時,才會帶入該號碼。 |
customer.store_credit_account.balance | 傳回顧客的商店抵用金餘額,幣別依相關情境而定。例如: |
customer.tags | 傳回與顧客關聯的標籤。 |
customer.tax_exempt | 若顧客享有免稅資格則傳回 true,否則傳回 false。 |
customer.total_spent | 傳回顧客在您商店所有訂單的消費總金額。 |
email.* | 此變數可存取以下電子郵件屬性: subject 會顯示電子郵件的主旨。preview_text 會顯示電子郵件的預覽文字。 |
open_tracking | 此變數可存取預先格式化的 電子郵件開啟動作追蹤區塊。若您建立 自訂程式碼電子郵件且已啟用開啟動作追蹤,則必須使用此變數。 |
shop.* | 此變數可存取下列商店屬性:
name 會顯示商店名稱。domain 會顯示商店的主要網域。url 會顯示商店的網址。shopify_domain 會顯示商店的 Shopify 網域。
|
unsubscribe_url | 此變數可存取原始的退訂網址,且可自訂。若您建立 自訂程式碼電子郵件,則必須包含 unsubscribe_url 或 unsubscribe_link 變數。unsubscribe_url 與 unsubscribe_link 皆一律指向主要網路商店網域,且無法修改為導向其他位置。 |
適用於未完成結帳作業電子郵件的 Liquid 變數
您可以使用下列變數,透過 Liquid 自訂未完成結帳作業的 Shopify Messaging 電子郵件訊息。
只有當電子郵件屬於未完成結帳作業行銷自動化的一部分時,abandoned_checkout 變數才會有值。否則該變數為 null。
| 變數 | 說明 |
|---|---|
abandoned_checkout.* | 此變數可存取未完成結帳作業的下列屬性:
|
id(checkout ID) | 結帳作業的唯一 ID,供內部使用。 |
shop | 您的 Shopify 商店名稱。 |
name | 未完成結帳作業的名稱,也稱為結帳編號。 |
total_price | 訂單總價,計算方式:小計 + 運送成本 - 運費折扣 + 稅額。 |
shipping_price |
運費。 範例: |
shipping_address | 運送地址。 |
billing_address | 帳單地址。 |
line_items | 未完成結帳作業中的所有商品項目清單。 |
unavailable_line_items | 未完成結帳作業中無法供應的所有商品項目清單。 |
note | 附加在未完成結帳作業上的備註。 |
landing_site |
顧客的到達頁面路徑。這是顧客進入商店時造訪的第一個頁面。 範例: |
landing_site_ref |
從到達頁面擷取引用參數。引用參數可以是: 如果 {% if landing_site_ref == 'my-tracking-token' %}
My action...
{% endif %}
|
referring_site |
將顧客帶到您商店的轉介方網址。 範例: |
created_at | 顧客建立該未完成結帳作業的日期和時間。 |
closed_at | 該結帳作業關閉的日期和時間。 |
customer_locale | 顧客的語言代碼,為兩或三個字母,後面可選擇加上地區修飾碼。例如, en、 en-CA |
item_count | 所有品項數量的總和。 |
unique_gateways | 結帳頁面可用且不重複的付款服務供應商清單。 |
discount | 未完成結帳作業中的購物車或商品項目所套用的折扣。 |
discounts | 套用至結帳頁面的折扣清單。 |
successfully_applied_discounts | 成功套用至結帳頁面的折扣。 |
discounts_amount | 所有折扣套用後的折扣金額。 範例:+$5.00 |
discounts_savings | 因所有折扣而節省的金額。 範例:-$5.00 |
buyer_accepts_marketing | 傳回 true或 false,取決於顧客在未完成結帳作業期間是否接受行銷。 |
subtotal_line_items | 用於計算結帳頁面小計的商品項目,不含任何小費項目。 |
requires_shipping | 傳回 true,如果結帳頁面中至少有一個品項需要運送。 |
subtotal_price | 結帳頁面的商品項目小計。 |
| 與未完成結帳作業相關的電子郵件地址。 | |
shop_name | 您的商店名稱。 |
tax_lines |
依稅別細分的稅額: {% for tax_line in tax_lines %}
{{ tax_line.title }} ({{ tax_line.rate_percentage }}%) : {{ tax_line.price | money_with_currency }}
{% endfor %}
|
tax_price | 結帳頁面所有品項的稅額總計。 |
attributes |
附加到未完成結帳作業的任何 屬性。 範例: |
shipping_method | 結帳頁面可用的第一個運送方式的資訊。 |
shipping_methods | 結帳頁面可用的運送方式。 |
free | 傳回 true if the total price of the checkout is zero. |
free_shipping | 傳回 true,如果結帳頁面不需要運送,或運送價格為 0。 |
different_billing_address | 傳回 true或 false,取決於運送地址是否與帳單地址相同。 |
customer | 包含 顧客 輸出屬性的顧客物件。 |
gift_cards | 套用至結帳頁面的禮品卡。 |
gift_cards_amount | 結帳金額中由禮品卡支付的金額。 |
transactions | 結帳頁面的交易。 |
shareable_url | 商品項目中的第一個商品網址。 |
shareable_title | 第一個商品項目的產品名稱。 |
total_tip | 顧客在結帳頁面新增的小費總額。 |
discount_applications | 說明在結帳頁面中商品項目套用折扣的原因與方式。 |
cart_level_discount_applications | 購物車專屬的折扣套用項目。 |
currency | 未完成結帳作業的幣別。 |
line_items_subtotal_price | 套用各商品項目折扣後,結帳頁面所有商品項目價格的總和。 |
適用於放棄瀏覽與放棄購物車電子郵件的 Liquid 變數
僅在電子郵件屬於 放棄購物車或放棄瀏覽的行銷自動化 一部分時,abandoned_visit.* 變數才會填入。請查看此變數可存取的下列屬性。
| 變數 | 說明 |
|---|---|
abandoned_visit.* | 此變數可存取放棄購物車或放棄瀏覽的下列屬性:
|
使用必要變數
建立自訂 Liquid 電子郵件時,必須包含 unsubscribe_link 或 unsubscribe_url 變數。如果您啟用開啟追蹤,則也必須包含 open_tracking 變數。
這些變數可以插入到電子郵件的任何程式碼位置,但最常見的使用位置是在電子郵件的頁尾區段,例如下列範例:
<div id="footer">{{ unsubscribe_link }} {{ open_tracking_block }}</div>自訂 Liquid 程式碼範例
您可以在程式碼編輯器中加入自訂 Liquid 或 HTML。以下程式碼範例說明如何加入 Liquid 程式碼,在電子郵件訊息中顯示您的商店名稱、自訂按鈕以及自訂尺寸的圖片。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ shop.name }} Newsletter</title>
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; line-height: 1.5; color: #333333; background-color: #f5f5f5;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f5f5f5;">
<tr>
<td align="center" style="padding: 20px;">
<table cellpadding="0" cellspacing="0" border="0" width="600" style="background-color: #ffffff; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<!-- Header -->
<tr>
<td align="center" style="background-color: #4a6de5; padding: 30px 20px; color: #ffffff;">
<h1 style="margin: 0; font-size: 28px; font-weight: bold;">{{ shop.name }}</h1>
<p style="margin: 10px 0 0; font-size: 16px;">Your Book Journey with Us</p>
</td>
</tr>
<!-- Content -->
<tr>
<td style="padding: 30px 20px;">
<!-- Greeting Section -->
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
<tr>
<td>
<h2 style="margin: 0 0 15px; font-size: 22px; color: #222222;">Hello {{ customer.name }}!</h2>
<p style="margin: 0 0 15px; font-size: 15px;">We hope this email finds you well. We noticed you're from {{ customer.default_address.city }}.</p>
{% if customer.email %}
<p style="margin: 0 0 15px; font-size: 15px;">Your registered email is: {{ customer.email }}</p>
{% endif %}
</td>
</tr>
</table>
<!-- Reading Journey Section -->
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
<tr>
<td>
<h2 style="margin: 0 0 15px; font-size: 20px; color: #4a6de5;">Your Reading Journey</h2>
<p style="margin: 0 0 15px; font-size: 15px;">Thank you for being a loyal customer! Here's a snapshot of your journey:</p>
<p style="margin: 0 0 15px; font-size: 15px;">You purchased {{ customer.orders_count }} books with us.</p>
{% if customer.last_order %}
<p style="margin: 0 0 15px; font-size: 15px;"> You last read {{customer.last_order.line_items[0].title}}. Great choice! </p>
{% endif %}
</td>
</tr>
</table>
<!-- Recommended Books Section -->
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
<tr>
<td>
<h2 style="margin: 0 0 15px; font-size: 20px; color: #4a6de5;">Books You Might Love</h2>
<p style="margin: 0 0 15px; font-size: 15px;">Based on your reading preferences, we've handpicked these titles just for you:</p>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="50%" style="padding-right: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f9f9f9; border-radius: 4px; padding: 15px;">
<tr>
<td align="center">
<!-- Image with proper email attributes -->
<img src="https:{{ all_products['product-1-handle'] | image_url: width: 200 }}"
alt="Product 1"
width="200"
height="200"
style="display: block; border: 0; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;"
title="Product 1"
border="0">
<h3 style="margin: 0 0 10px; font-size: 16px; color: #333333;">{{ all_products['product-1-handle'].title }}</h3>
<p style="margin: 0 0 10px; font-size: 15px; color: #4a6de5;">${{ all_products['product-1-handle'].price }}</p>
<a href="{{shop.domain}}{{ all_products['product-1-handle'].url }}" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">View Book</a>
</td>
</tr>
</table>
</td>
<td width="50%" style="padding-left: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f9f9f9; border-radius: 4px; padding: 15px;">
<tr>
<td align="center">
<!-- Image with proper email attributes -->
<img src="https:{{ all_products['product-2-handle'] | image_url: width: 200 }}"
alt="Product 2"
width="200"
height="200"
style="display: block; border: 0; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;"
title="Product 2"
border="0">
<h3 style="margin: 0 0 10px; font-size: 16px; color: #333333;">{{ all_products['product-2-handle'].title }}</h3>
<p style="margin: 0 0 10px; font-size: 15px; color: #4a6de5;">${{ all_products['product-2-handle'].price }}</p>
<a href="{{shop.domain}}{{ all_products['product-2-handle'].url }}" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">View Book</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- Book Club Section -->
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
<tr>
<td style="background-color: #f5f7ff; border-radius: 4px; padding: 25px; text-align: center;">
<h2 style="margin: 0 0 15px; font-size: 18px; color: #333333;">This Month's Top Picks</h2>
<p style="margin: 0 0 20px; font-size: 15px;">Discover what other readers are loving this month:</p>
<a href="{{ shop.url }}/pages/book-club" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">Join Our Book Club</a>
</td>
</tr>
</table>
</td>
</tr>
<!-- Footer -->
<tr>
<td style="background-color: #f2f2f2; padding: 30px 20px; text-align: center;">
<p style="margin: 0 0 15px; font-size: 15px;">Best regards,<br><strong>{{ shop.name }} Team</strong></p>
<p style="margin: 0 0 15px; font-size: 12px; color: #999999;">© {{ 'now' | date: '%Y' }} {{ shop.name }}. All rights reserved.</p>
<p style="margin: 0 0 15px; font-size: 12px;">{{ open_tracking_block }}</p>
<a href="{{ unsubscribe_url }}" style="color: #999999; font-size: 12px; text-decoration: underline;">{{ unsubscribe_link }}</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>