Liquid use case library
Looking for inspiration to craft the perfect personalization using Liquid? Take a look through our collection of Liquid use cases, outlined by category below.
Use the search bar or the checkboxes below to find the use cases that fit your need.
記念日と祝日
- ユーザーの記念年に基づいてメッセージをパーソナライズする
- ユーザーの誕生日週に基づいてメッセージをパーソナライズする
- 誕生月のユーザーにキャンペーンを送信する
- 主要な祝日にメッセージを送信しないようにする
ユーザーの記念年に基づいてメッセージをパーソナライズする
このユースケースでは、ユーザーの初回サインアップ日に基づいてアプリの記念日を計算し、何年目のお祝いかに応じて異なるメッセージを表示する方法を示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{% assign this_month = 'now' | date: "%B" %}
{% assign this_day = 'now' | date: "%d" %}
{% assign anniversary_month = {{custom_attribute.${registration_date}}} | date: "%B" %}
{% assign anniversary_day = {{custom_attribute.${registration_date}}} | date: "%d" %}
{% assign anniversary_year = {{custom_attribute.${registration_date}}} | date: "%Y" %}
{% if this_month == anniversary_month %}
{% if this_day == anniversary_day %}
{% if anniversary_year == '2021' %}
Exactly one year ago today we met for the first time!
{% elsif anniversary_year == '2020' %}
Exactly two years ago today we met for the first time!
{% elsif anniversary_year == '2019' %}
Exactly three years ago today we met for the first time!
{% else %}
{% abort_message("Not same year") %}
{% endif %}
{% else %}
{% abort_message("Not same day") %}
{% endif %}
{% else %}
{% abort_message("Not same month") %}
{% endif %}
説明: ここでは、予約変数 now を使用して、現在の日時を ISO 8601 形式でテンプレートに挿入しています。フィルター %B(「May」のような月名)と %d(「18」のような日)で現在の月と日をフォーマットします。次に、signup_date の値にも同じ日時フィルターを使用して、条件タグとロジックで2つの値を比較できるようにします。
さらに3つの変数ステートメントを繰り返して、signup_date の %B と %d を取得し、%Y(「2021」のような年)も追加します。これにより、signup_date の日時が年だけに変換されます。日と月がわかればユーザーの記念日が今日かどうかを確認でき、年がわかれば何年経ったかがわかるため、何年目のお祝いかを伝えることができます。
サインアップ日を収集してきた年数分の条件を作成できます。
ユーザーの誕生日週に基づいてメッセージをパーソナライズする
このユースケースでは、ユーザーの誕生日を見つけて現在の日付と比較し、誕生日週の前、最中、後に特別な誕生日メッセージを表示する方法を示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{% assign this_week = 'now' | date: '%W' %}
{% assign birthday_week = {{${date_of_birth}}} | date: '%W' %}
{% assign last_week = {{this_week}} | minus: 1 %}
{% assign next_week = {{this_week}} | plus: 1 %}
{% assign birthday_week_conversion = {{birthday_week}} | plus: 0 %}
{% if {{last_week}} == {{birthday_week_conversion}} %}
Happy birthday for last week!
{% elsif {{birthday_week}} == {{this_week}} %}
Happy birthday for this week!
{% elsif {{next_week}} == {{birthday_week_conversion}} %}
Happy birthday for next week!
{% else %}
No birthday for you!
{% endif %}
説明: 記念年のユースケースと同様に、ここでは予約変数 now を取得し、%W フィルター(年間52週のうちの第12週のような週番号)を使用して、ユーザーの誕生日が該当する年間の週番号を取得します。ユーザーの誕生日週が現在の週と一致する場合、お祝いメッセージを送信します。
last_week と next_week のステートメントも含めて、メッセージングをさらにパーソナライズしています。
誕生月のユーザーにキャンペーンを送信する
このユースケースでは、ユーザーの誕生月を計算し、誕生日が今月かどうかを確認し、該当する場合は特別なメッセージを送信する方法を示します。
1
2
3
4
5
6
7
{% assign this_month = 'now' | date: "%B" %}
{% assign birth_month = {{${date_of_birth}}} | date: "%B" %}
{% if {{this_month}} == {{birth_month}} %}
Message body
{% else %}
{% abort_message("Not their birthday month") %}
{% endif %}
説明: 誕生日週のユースケースと同様ですが、ここでは %B フィルター(「May」のような月名)を使用して、今月が誕生日のユーザーを計算します。月次メールで誕生日のユーザーに呼びかけるなどの活用が考えられます。
主要な祝日にメッセージを送信しないようにする
このユースケースでは、ホリデーシーズン中にメッセージを送信しつつ、エンゲージメントが低くなりがちな主要な祝日の当日は送信を避ける方法を示します。
1
2
3
4
5
6
{% assign today = 'now' | date: '%Y-%m-%d' %}
{% if today == "2023-12-24" or today == "2023-12-25" or today == "2023-12-26" %}
{% abort_message %}
{% else %}
Message if today isn't one of the provided holidays.
{% endif %}
説明: ここでは、today という用語を予約変数 now(現在の日時)に割り当て、フィルター %Y(「2023」のような年)、%m(「12」のような月)、%d(「25」のような日)を使用して日付をフォーマットします。次に条件文を実行し、変数 today が指定した祝日と一致する場合、メッセージを中止します。
この例では、クリスマスイブ、クリスマス、ボクシングデー(クリスマスの翌日)を使用しています。
アプリの使用状況
- セッションを記録していないユーザーにその言語でメッセージを送信する
- ユーザーが最後にアプリを開いた時期に基づいてメッセージをパーソナライズする
- ユーザーが3日以内にアプリを使用した場合に異なるメッセージを表示する
セッションを記録していないユーザーにその言語でメッセージを送信する
このユースケースでは、ユーザーがセッションを記録したかどうかを確認し、記録していない場合は、カスタム属性で手動収集した言語に基づいてメッセージを表示するロジックを含めます。アカウントに言語情報が紐づいていない場合は、デフォルト言語でメッセージを表示します。ユーザーがセッションを記録している場合は、ユーザーに紐づいた言語情報を取得し、適切なメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{% if {{${last_used_app_date}}} == nil %}
{% if {{custom_attribute.${user_language}}} == 'en' %}
Message in English based on custom attribute
{% elsif {{custom_attribute.${user_language}}} == 'fr' %}
Message in French based on custom attribute
{% else %}
Does not have language - Default language
{% endif %}
{% else %}
{% if ${language} == 'en' %}
Message in English based on Language
{% elsif ${language} == 'fr' %}
Message in French based on Language
{% else %}
Has language - Default language
{% endif %}
{% endif %}
説明: ここでは、ネストされた2つのグループ化された if ステートメントを使用しています。最初の if ステートメントは、last_used_app_date が nil かどうかを確認して、ユーザーがセッションを開始したかどうかをチェックします。これは、{{${language}}} がユーザーのセッション記録時に SDK によって自動収集されるためです。ユーザーがセッションを記録していない場合、まだ言語情報がないため、言語関連のカスタム属性が保存されているかどうかを確認し、その情報に基づいて可能であればその言語でメッセージを表示します。
2番目の if ステートメントは、標準(デフォルト)属性を確認するだけです。ユーザーの last_used_app_date が nil ではないため、セッションを記録済みであり、言語情報を取得できているからです。
Nil は、Liquid コードが結果を返さない場合に返される予約変数です。Nil は if ブロック内で false として扱われます。
ユーザーが最後にアプリを開いた時期に基づいてメッセージをパーソナライズする
このユースケースでは、ユーザーが最後にアプリを開いた時刻を計算し、経過時間に応じて異なるパーソナライズされたメッセージを表示します。
1
2
3
4
5
6
7
8
{% assign last_used_date = {{${last_used_app_date}}} | date: "%s" %}
{% assign now = 'now' | date: "%s" %}
{% assign difference_in_days = {{now}} | minus: {{last_used_date}} | divided_by: 86400 %}
{% if {{difference_in_days}} < 3 %}
Happy to see you again!
{% else %}
It's been a while; here are some of our latest updates.
{% endif %}
ユーザーが3日以内にアプリを使用した場合に異なるメッセージを表示する
このユースケースでは、ユーザーがどのくらい前にアプリを使用したかを計算し、経過時間に応じて異なるパーソナライズされたメッセージを表示します。
1
2
3
4
5
6
7
8
{% assign last_used_date = {{${last_used_app_date}}} | date: "%s" %}
{% assign now = 'now' | date: "%s" %}
{% assign difference_in_days = {{now}} | minus: {{last_used_date}} | divided_by: 86400 %}
{% if {{difference_in_days}} < 3 %}
Message for a recently active user
{% else %}
Message for a less active user
{% endif %}
カウントダウン
- 今日の日付にX日を加算する
- 設定した時点からのカウントダウンを計算する
- 特定の配送日と優先度のカウントダウンを作成する
- 日数でカウントダウンを作成する
- 日から時間、分へのカウントダウンを作成する
- 特定の日付までの残り日数を表示する
- カスタム日付属性の到来までの残り日数を表示する
- 残り時間を表示し、残りX時間の場合はメッセージを中止する
- ユーザーのメンバーシップ終了のX日前にアプリ内メッセージを送信する
- ユーザーの日付と言語に基づいてアプリ内メッセージをパーソナライズする
- 30日後の日付を月と日のフォーマットでテンプレートに挿入する
今日の日付にX日を加算する
このユースケースでは、現在の日付に特定の日数を加算して、メッセージ内で参照・追加します。たとえば、週末のエリアイベントを紹介する週中のメッセージを送信したい場合に使用できます。
1
Here are the movies we're showing on {{ "now" | date:'%s' | plus:259200 | date:"%F" }}!
plus の値は常に秒単位なので、最後にフィルター %F を使用して秒を日付に変換します。
メッセージにイベントリストへの URL やディープリンクを含めて、将来のアクションのリストにユーザーを誘導することをお勧めします。
設定した時点からのカウントダウンを計算する
このユースケースでは、特定の日付と現在の日付の差を日数で計算します。この差を使用して、ユーザーにカウントダウンを表示できます。
1
2
3
4
5
{% assign event_date = '2023-12-31' | date: "%s" %}
{% assign today = 'now' | date: "%s" %}
{% assign difference = event_date | minus: today %}
{% assign difference_days = difference | divided_by: 86400 %}
you have {{ difference_days }} days left!
特定の配送日と優先度のカウントダウンを作成する
このユースケースでは、さまざまな配送オプションを取得し、受け取りまでの所要時間を計算し、特定の日付までに荷物を受け取れるよう購入を促すメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{% assign standard_shipping_start = "2023-12-10T00:00-05:00" | date: "%s" %}
{% assign standard_shipping_end = "2023-12-20T13:00-05:00" | date: "%s" %}
{% assign express_shipping_end = "2023-12-22T24:00-05:00" | date: "%s" %}
{% assign overnight_shipping_end = "2023-12-23T24:00-05:00" | date: "%s" %}
{% assign today = 'now' | date: "%s" %}
{% assign difference_s = standard_shipping_end | minus: today %}
{% assign difference_s_days = difference_s | divided_by: 86400.00 | round %}
{% assign difference_e = express_shipping_end | minus: today %}
{% assign difference_e_days = difference_e | divided_by: 86400.00 | round %}
{% assign difference_o = overnight_shipping_end | minus: today %}
{% assign difference_o_days = difference_o | divided_by: 86400.00 | round %}
{% if today >= standard_shipping_start and today <= standard_shipping_end %}
{% if difference_s_days == 0 %}
This is the last day to order with standard shipping, so your order gets here on time for Christmas Eve!
{% elsif difference_s_days == 1 %}
There is {{difference_s_days}} day left to order with standard shipping, so your order gets here on time for Christmas Eve!
{% else %}
There are {{difference_s_days}} days left to order with standard shipping so your order gets here on time for Christmas Eve!
{% endif %}
{% elsif today > standard_shipping_end and today < express_shipping_end %}
{% if difference_e_days == 1 %}
There is {{difference_e_days}} day left to order with express shipping, so your order gets here on time for Christmas Eve!
{% else %}
There are {{difference_e_days}} days left to order with express shipping so your order gets here on time for Christmas Eve!
{% endif %}
{% elsif today >= express_shipping_end and today < overnight_shipping_end %}
This is the last day for overnight shipping so your order gets here on time for Christmas Eve!
{% else %}
{% abort_message("Unable to order and ship in time") %}
{% endif %}
日数でカウントダウンを作成する
このユースケースでは、特定のイベントと現在の日付の間の残り時間を計算し、イベントまでの残り日数を表示します。
1
2
3
4
5
{% assign event_date = {{custom_attribute.${last_selected_event_date}}} | date: "%s" %}
{% assign today = 'now' | date: "%s" %}
{% assign difference = event_date | minus: today %}
{% assign difference_days = difference | divided_by: 86400 %}
Your order will arrive in {{ difference_days }} days!
date 値を持つカスタム属性フィールドが必要です。
日から時間、分へのカウントダウンを作成する
このユースケースでは、特定のイベントと現在の日付の間の残り時間を計算します。イベントまでの残り時間に応じて、時間の値(日、時間、分)を変更し、異なるパーソナライズされたメッセージを表示します。
たとえば、顧客の注文到着まで2日ある場合は「ご注文は2日後に届きます」と表示し、1日未満の場合は「ご注文は17時間後に届きます」と変更できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
{% assign today = 'now' | date: "%s" %}
{% assign scheme_finish = "2017-10-13T10:30:30" | date: "%s" %}
{% assign difference_seconds = scheme_finish | minus: today %}
{% assign difference_minutes = difference_seconds | divided_by: 60 %}
{% assign difference_hours = difference_seconds | divided_by: 3600 %}
{% assign difference_days = difference_seconds | divided_by: 86400 %}
{% if {{difference_minutes}} > 59 and {{difference_minutes}} < 1440 %}
You have {{difference_hours}} hours left till your order arrives!
{% elsif {{difference_minutes}} < 59 %}
You have {{difference_minutes}} minutes left till your order arrives!
{% else %}
You have {{difference_days}} days left till your order arrives!
{% endif %}
date 値を持つカスタム属性フィールドが必要です。また、日、時間、分で時間を表示する際のしきい値を設定する必要があります。
特定の日付までの残り日数を表示する
このユースケースでは、現在の日付と将来のイベント日の差を計算し、イベントまでの残り日数を示すメッセージを表示します。
1
2
3
4
5
{% assign event_date = '2024-01-15' | date: "%s" %}
{% assign today = 'now' | date: "%s" %}
{% assign difference = event_date | minus: today %}
{% assign difference_days = difference | divided_by: 86400 %}
There are {{difference_days}} days until your birthday!
カスタム日付属性の到来までの残り日数を表示する
このユースケースでは、現在の日付と将来の日付の差を日数で計算し、差が設定した数値と一致する場合にメッセージを表示します。
この例では、カスタム日付属性の2日前にユーザーにメッセージが届きます。それ以外の場合、メッセージは送信されません。
1
2
3
4
5
6
7
8
9
{% assign today = 'now' | date: '%j' | plus: 0 %}
{% assign surgery_date = {{custom_attribute.${surgery_date}}} | date: '%j' | plus: 0 %}
{% assign difference_days = {{surgery_date}} | minus: {{today}} %}
{% if difference_days == 2 %}
Your surgery is in 2 days on {{custom_attribute.${surgery_date}}}
{% else %}
{% abort_message %}
{% endif %}
残り時間を表示し、残りX時間の場合はメッセージを中止する
このユースケースでは、特定の日付までの残り時間を計算し、その長さに応じて(日付が近すぎる場合はメッセージをスキップして)異なるパーソナライズされたメッセージを表示します。
たとえば、「ロンドン行きのチケット購入まであとX時間です」と表示しますが、ロンドン行きのフライト時刻まで2時間以内の場合はメッセージを送信しません。
1
2
3
4
5
6
7
8
9
10
{% assign today = 'now' | date: "%s" %}
{% assign dep_time = {{event_properties.${outboundDate}}} | date: "%s" %}
{% assign time_to_dep = dep_time | minus: today %}
{% if {{time_to_dep}} < 7200 %}
{% abort_message("OutboundDate less than 2 hours") %}
{% elsif {{time_to_dep}} > 7200 and {{time_to_dep}} < 86400 %}
Don't forget to buy your ticket to {{event_properties.${toStation}}} within next 24 hours!
{% else %}
Still traveling to {{event_properties.${toStation}}} in more than 24 hours? Book now!
{% endif %}
カスタムイベントプロパティが必要です。
ユーザーのメンバーシップ終了のX日前にアプリ内メッセージを送信する
このユースケースでは、メンバーシップの有効期限を取得し、期限切れまでの残り時間を計算し、メンバーシップの残り期間に応じて異なるメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{% assign membership_expiry = {{custom_attribute.${membership_expiry_date}}} | date: "%s" %}
{% assign today = 'now' | date: "%s" %}
{% assign difference = membership_expiry | minus: today %}
{% assign difference_days = difference | divided_by: 86400 %}
{% if difference_days > 4 and difference_days <= 7 %}
You have {{difference_days}} days left in your trial, make sure you upgrade!
{% elsif difference_days > 2 and difference_days <= 4 %}
HURRY! You have {{difference_days}} days left in your trial, make sure you upgrade!
{% elsif difference_days == 2 %}
LAST CHANCE! You have {{difference_days}} days left in your trial. Make sure you upgrade!
{% else %}
You have few days left in your trial. Make sure to upgrade!
{% endif %}
ユーザーの日付と言語に基づいてアプリ内メッセージをパーソナライズする
このユースケースでは、イベントまでのカウントダウンを計算し、ユーザーの言語設定に基づいてその言語でカウントダウンを表示します。
たとえば、月に1回ユーザーにアップセルメッセージを送信して、オファーの有効期間を知らせる場合、4つのアプリ内メッセージを使用できます。
- 初回
- 残り2日
- 残り1日
- 最終日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{% assign today = 'now' | date: "%s" %}
{% assign end_date = "2021-04-16T23:59:59" | date: "%s" %}
{% assign difference = end_date | minus: today %}
{% assign difference_days = difference | divided_by: 86400 %}
{% if {{difference_days}} >= 3 %}
{% if ${language} == 'de' %}
Hallo, das Angebot gilt bis zum 16.04.
{% elsif ${language} == 'ch' %}
Grüezi, das Angebot gilt bis zum 16.04.
{% elsif ${language} == 'en' %}
The offer is valid until 16.04.
{% else %}
The offer is valid until 16.04.
{% endif %}
{% elsif {{difference_days}} == 2 %}
{% if ${language} == 'de' %}
INSERT MESSAGE
{% elsif ${language} == 'ch' %}
INSERT MESSAGE
{% elsif ${language} == 'en' %}
INSERT MESSAGE
{% else %}
INSERT MESSAGE
{% endif %}
{% elsif {{difference_days}} == 1 %}
{% if ${language} == 'de' %}
INSERT MESSAGE
{% elsif ${language} == 'ch' %}
INSERT MESSAGE
{% elsif ${language} == 'en' %}
INSERT MESSAGE
{% else %}
INSERT MESSAGE
{% endif %}
{% elsif {{difference_days}} == 0 %}
{% if ${language} == 'de' %}
Hallo, das Angebot gilt noch heute.
{% elsif ${language} == 'ch' %}
Hallo, das Angebot gilt noch heute.
{% elsif ${language} == 'en' %}
Grüezi, das Angebot gilt noch heute.
{% else %}
Hi, the offer is only valid today.
{% endif %}
{% else %}
{% abort_message("Calculation failed") %}
{% endif %}
date 値を割り当て、指定した日付が日付範囲外の場合の中止ロジックを含める必要があります。正確な日の計算には、割り当てる終了日に 23:59:59 を含める必要があります。
30日後の日付を月と日のフォーマットでテンプレートに挿入する
このユースケースでは、メッセージングで使用するために30日後の日付を表示します。
1
2
{% assign today = 'now' | date: "%s" %}
{% assign thirty_days = today | plus: 2592000 | date: "%B %d" %}
カスタム属性
- 一致するカスタム属性に基づいてメッセージをパーソナライズする
- 2つのカスタム属性を減算して差額を金額として表示する
- フルネームが first_name フィールドに保存されている場合にユーザーの名を参照する
一致するカスタム属性に基づいてメッセージをパーソナライズする
このユースケースでは、ユーザーが特定のカスタム属性を持っているかどうかを確認し、持っている場合は異なるパーソナライズされたメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
{% if custom_attribute.${hasShovel} == true and custom_attribute.${VisitToGroundTooTough} > 0 %}
The ground is very hard. The dirt road goes East.
{% elsif custom_attribute.${hasShovel} == true %}
The dirt road goes East.
{% elsif custom_attribute.${VisitToStart} > 0 %}
The dirt road goes East.
The shovel here.
{% else %}
You are at a dead-end of a dirt road. The road goes to the east. In the distance, you can see that it will eventually fork off. The trees here are very tall royal palms, and they are spaced equidistant from each other.
There is a shovel here.
{% endif %}
2つのカスタム属性を減算して差額を金額として表示する
このユースケースでは、2つの金額カスタム属性を取得し、差額を計算して表示することで、目標達成までの残り金額をユーザーに知らせます。
1
2
3
4
{% assign event_goal = {{custom_attribute.${last_selected_event_personal_goal}}} %}
{% assign current_raised = {{custom_attribute.${last_selected_event_personal_amount_raised}}} %}
{% assign difference = event_goal | minus: current_raised %}
You only have ${{ difference | round: 0 | number_with_delimiter }} left to raise!
フルネームが first_name フィールドに保存されている場合にユーザーの名を参照する
このユースケースでは、ユーザーの名(姓と名が1つのフィールドに保存されている場合)を取得し、その名を使用してウェルカムメッセージを表示します。
1
2
3
{{${first_name} | truncatewords: 1, "" | default: 'hi'}}
{% assign name = {{${first_name}}} | split: ' ' %}
Hi {{name[0]}}, here's your message!
説明: split フィルターは、{{${first_name}}} に保持されている文字列を配列に変換します。{{name[0]}} を使用することで、配列の最初の項目(ユーザーの名)のみを参照します。
カスタムイベント
- カスタムイベントが現在から2時間以内の場合にプッシュ通知を中止する
- ユーザーがカスタムイベントを3回実行するたびにキャンペーンを送信する
- 1つのカテゴリからのみ購入したユーザーにメッセージを送信する
- 過去1か月間にカスタムイベントが発生した回数を追跡する
カスタムイベントが現在から2時間以内の場合にプッシュ通知を中止する
このユースケースでは、イベントまでの時間を計算し、残り時間に応じて異なるパーソナライズされたメッセージを表示します。
たとえば、カスタムイベントプロパティが今後2時間以内に到来する場合にプッシュ送信を防止したい場合があります。この例では、電車のチケットの放棄カートのシナリオを使用しています。
1
2
3
4
5
6
7
8
9
10
{% assign today = 'now' | date: "%s" %}
{% assign dep_time = {{event_properties.${outboundDate_Time}}} | date: "%s" %}
{% assign time_to_dep = dep_time | minus: today %}
{% if {{time_to_dep}} <= 7200 %}
{% abort_message("OutboundDate less than 2 hours") %}
{% elsif {{time_to_dep}} > 7200 and {{time_to_dep}} < 86400 %}
Don't forget to buy your ticket to {{event_properties.${toStation}}} within next 24 hours
{% else %}
Still traveling to {{event_properties.${toStation}}} in more than 24 hours? Book now
{% endif %}
ユーザーがカスタムイベントを3回実行するたびにキャンペーンを送信する
このユースケースでは、ユーザーがカスタムイベントを3回実行したかどうかを確認し、該当する場合はメッセージを表示するかキャンペーンを送信します。
1
2
3
4
5
6
7
{% assign cadence = custom_attribute.${example} | minus: 1 | modulo: 3 %}
{% if custom_attribute.${example} == blank %}
{% abort_message("Error calculating cadence") %}
{% elsif cadence != 0 %}
{% abort_message("Skip message") %}
{% endif %}
Did you forget something in your shopping cart?
カスタムイベントカウントのイベントプロパティを持つか、Braze エンドポイントへの Webhook を使用する必要があります。これは、ユーザーがイベントを実行するたびにカスタム属性(example_event_count)をインクリメントするためです。この例では3回ごとのケイデンス(1、4、7、10など)を使用しています。ケイデンスをゼロから開始する場合(0、3、6、9など)は、minus: 1 を削除してください。
1つのカテゴリからのみ購入したユーザーにメッセージを送信する
このユースケースでは、ユーザーが購入したカテゴリのリストを取得し、購入カテゴリが1つだけの場合にメッセージを表示します。
1
2
3
4
5
6
7
{% assign category = {{custom_attribute.${categories_purchased}}} %}
{% assign uniq_cat = {{category | uniq }} %}
{% if {{uniq_cat | size}} == 1 %}
{{uniq_cat}}
{% else %}
{% abort_message("Purchase category doesn't exist") %}
{% endif %}
過去1か月間にカスタムイベントが発生した回数を追跡する
このユースケースでは、当月の1日から前月までの間にカスタムイベントが記録された回数を計算します。その後、users/track コールを実行してこの値をカスタム属性として保存できます。なお、このキャンペーンは月次データを使用できるようになるまで、2か月連続で実行する必要があります。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{% capture body %}
{
"braze_id": "{{${braze_id}}}",
"fields_to_export": ["custom_events"]
}
{% endcapture %}
{% connected_content YOUR_BRAZE_ENDPOINT/users/export/ids
:method post
:headers { "Authorization": "Bearer YOUR_API_KEY" }
:body {{body}}
:content_type application/json
:save response
:retry %}
{% for custom_event in response.users[0].custom_events %}
{% assign ce_name = custom_event.name %}
{% comment %} The following custom event name will need to be amended for the target custom event. {% endcomment %}
{% if ce_name == "Project Exported" %}
{% comment %}{{custom_event.name}}: {{custom_event.count}}{% endcomment %}
{% assign current_count = custom_event.count %}
{% endif %}
{% endfor %}
{% assign prev_month_count = {{custom_attribute.${projects_exported_prev_month}}} %}
{% assign latest_count = current_count | minus: prev_month_count %}
{% assign now = "now" | date: "%s" %}
{% assign yesterday = {{now}} | minus: 86400 %}
{% assign previous_month = {{yesterday}} | date: "%B" %}
{% assign previous_year = {{yesterday}} | date: "%y" %}
{% assign formatted_month = previous_month | downcase %}
{% comment %}The Custom Event name that is being tracked will be needed to be amended for the target Custom Event in the Attribute Name below. {% endcomment %}
1
2
3
4
5
6
"attributes": [
{
"external_id":"{{${user_id}}}",
"projects_exported_{{formatted_month}}_{{previous_year}}": "{{latest_count}}"
}
]
言語
月名を別の言語で表示する
このユースケースでは、現在の日付、月、年を表示し、月名を別の言語で表示します。この例ではスウェーデン語を使用しています。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{% assign day = 'now' | date: "%e" %}
{% assign year = 'now' | date: "%Y" %}
{% assign month = 'now' | date: "%B" %}
{% if {{month}} == 'January' %}
{{day}} Januari {{year}}
{% elsif {{month}} == 'February' %}
{{day}} Februari {{year}}
{% elsif {{month}} == 'March' %}
{{day}} Mars {{year}}
{% elsif {{month}} == 'April' %}
{{day}} April {{year}}
{% elsif {{month}} == 'May' %}
{{day}} Maj {{year}}
{% elsif {{month}} == 'June' %}
{{day}} Juni {{year}}
{% elsif {{month}} == 'July' %}
{{day}} Juli {{year}}
{% elsif {{month}} == 'August' %}
{{day}} Augusti {{year}}
{% elsif {{month}} == 'September' %}
{{day}} September {{year}}
{% elsif {{month}} == 'October' %}
{{day}} Oktober {{year}}
{% elsif {{month}} == 'November' %}
{{day}} November {{year}}
{% elsif {{month}} == 'December' %}
{{day}} December {{year}}
{% endif %}
ユーザーの言語に基づいて画像を表示する
このユースケースでは、ユーザーの言語に基づいて画像を表示します。なお、このユースケースは Braze メディアライブラリにアップロードされた画像でのみテストされています。
1
2
3
4
5
6
7
8
9
{% if ${language} == 'en' %}
English image URL (for example, https://cdn-staging.braze.com/appboy/communication/assets/image_assets/images/60aecba96a93150c749b4d57/original.png?1622068137)
{% elsif ${language} == 'ru' %}
Russian image URL
{% elsif ${language} == 'es' %}
Spanish image URL
{% else %}
Fallback image URL
{% endif %}
曜日とユーザーの言語に基づいてメッセージをパーソナライズする
このユースケースでは、現在の曜日を確認し、その曜日に基づいて、ユーザーの言語が提供された言語オプションのいずれかに設定されている場合、その言語で特定のメッセージを表示します。
この例は火曜日で止まっていますが、各曜日に対して繰り返すことができます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{% assign today = 'now' | date: '%A' %}
{% if today == 'Monday' %}
{% if ${language} == 'es' %}
Compra hoy y lleva tu aprendizaje de idiomas a niveles más altos. 🚀
{% elsif ${language} == 'en' %}
Purchase today and take your language learning to the next level. 🚀
{% elsif ${language} == 'zh' %}
今天就购买并将您的语言提高到一个新水平吧。🚀
{% else %}
It's Monday, but the language doesn't match
{% endif %}
{% elsif today == 'Tuesday' %}
{% if ${language} == 'zh' %}
不要忘记解锁以获取完整版本哦。🔓
{% elsif ${language} == 'en' %}
Don't forget to unlock the full version of your language. 🔓
{% elsif ${language} == 'ja' %}
すべての機能を使ってみませんか 🔓
{% elsif ${language} == 'es' %}
No te olivides de desbloquear la versión completa del programa de idiomas. 🔓
{% else %}
tuesday default
{% endif %}
{% endif %}
その他
- マーケティングメールをブロックしている顧客へのメール送信を避ける
- 顧客のサブスクリプション状態を使用してメッセージ内のコンテンツをパーソナライズする
- 文字列内のすべての単語の最初の文字を大文字にする
- カスタム属性の値を配列と比較する
- 今後のイベントリマインダーを作成する
- 配列内の文字列を検索する
- 配列内の最大値を見つける
- 配列内の最小値を見つける
- 文字列の末尾をクエリする
- 複数の組み合わせを持つカスタム属性から配列内の値をクエリする
- 文字列を電話番号にフォーマットする
マーケティングメールをブロックしている顧客へのメール送信を避ける
このユースケースでは、コンテンツブロックに保存されたブロック済みユーザーのリストを取得し、それらのブロック済みユーザーが今後のキャンペーンやキャンバスで連絡やターゲティングされないようにします。
この Liquid を使用するには、まずブロック済みメールのリストをコンテンツブロック内に保存してください。リストには、メールアドレス間に余分なスペースや文字を挿入しないでください(例:[email protected],[email protected])。
1
2
3
4
5
6
7
8
{% assign blocked_emails = {{content_blocks.${BlockedEmailList}}} | split: ',' %}
{% for email in blocked_emails %}
{% if {{${email_address}}} == email %}
{% abort_message("Email is blocked") %}
{% break %}
{% endif %}
{% endfor %}
Your message here!
説明: ここでは、ブロック済みメールのコンテンツブロックを参照して、潜在的な受信者のメールがこのリストに含まれているかどうかを確認します。メールが見つかった場合、メッセージは送信されません。
コンテンツブロックのサイズ制限は 5 MB です。
顧客のサブスクリプション状態を使用してメッセージ内のコンテンツをパーソナライズする
このユースケースでは、顧客のサブスクリプション状態を取得してパーソナライズされたコンテンツを送信します。特定のサブスクリプショングループに購読しているユーザーには、メールサブスクリプショングループ向けの限定メッセージが届きます。
1
2
3
4
{% if {{subscribed_state.${subscription_group_id}}} == 'subscribed' %}
This is an exclusive message for subscribed users!
{% else %} This is the default message for other users.
{% endif %}
文字列内のすべての単語の最初の文字を大文字にする
このユースケースでは、単語の文字列を取得し、配列に分割して、各単語の最初の文字を大文字にします。
1
2
3
4
{% assign words_array = {{custom_attribute.${address}}} | split: ' ' %}
{% for words in {{words_array}} %}
{{ words | capitalize | append: ' ' }}
{% endfor %}
説明: ここでは、選択した文字列属性に変数を割り当て、split フィルターを使用して文字列を配列に分割しています。次に for タグを使用して、新しく作成した配列の各項目に変数 words を割り当て、capitalize フィルターと append フィルターで各用語の間にスペースを追加して表示しています。
カスタム属性の値を配列と比較する
このユースケースでは、お気に入りの店舗のリストを取得し、ユーザーのお気に入りの店舗がそのリストに含まれているかどうかを確認し、含まれている場合はそれらの店舗からの特別オファーを表示します。
1
2
3
4
5
6
7
8
9
10
11
{% assign favorite_stores = 'Target,Walmart,Costco' | split: ',' %}
{% for store in favorite_stores %}
{% if {{custom_attribute.${favorited_stores}}} contains {{store}} %}
Today's offer from {{store}}
{% break %}
{% else %}
{% abort_message("No attribute found") %}
{% endif %}
{% endfor %}
このシーケンスには、主要な条件文に break タグがあります。これにより、一致が見つかるとループが停止します。多くの一致またはすべての一致を表示したい場合は、break タグを削除してください。
今後のイベントリマインダーを作成する
このユースケースでは、カスタムイベントに基づいて今後のリマインダーを設定できます。このシナリオ例では、26日以上先のポリシー更新日に対してリマインダーを設定し、ポリシー更新日の26日前、13日前、7日前、または2日前にリマインダーを送信します。
このユースケースでは、以下を Webhook キャンペーンまたはキャンバスステップの本文に配置する必要があります。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{% comment %}
Depending on how the reminder_capture property is passed to Braze, with/without a timestamp, the number of days could impact whether a user falls on either side of the 26/13/7/2-day windows.
Once users have been assigned to a Reminder journey/flow, they are then scheduled to enter a subsequent Canvas.
This 'Event Listener' can be used to split out users into different journeys based on the Custom Event properties sent to Braze.
{% endcomment %}
{% comment %}
When testing, make sure the campaign ID, campaign API endpoint, Canvas ID, Canvas API endpoint are entered correctly. In this example, the Canvas ID and Canvas API endpoint have been set up for sharing with the client. In practice, this can be testing using a campaign ID and Campaign API endpoint.
{% endcomment %}
{% comment %}
The following step calculates how much there is between today's date and the Reminder Date as 'time_to_reminder'.
{% endcomment %}
{% assign today = "now" | date: '%s' %}
{% assign reminder_start_date = {{event_properties.${reminder_date}}} | date: '%s' %}
{% assign time_to_reminder = reminder_start_date | minus: today %}
{% comment %}
The following step checks if the time_to_reminder is more than 26 days away; if this is true, then the user is scheduled to enter the subsequent Canvas 26 days before the reminder_date.
The time is converted from 'seconds from 1970' to the appropriate Reminder Date in the required ISO 8601 format.
N.B. Additional time zones would need to be catered for by adding an additional API Schedule property of "in_local_time"
{% endcomment %}
{% if {{time_to_reminder}} > 2246400 %}
{% assign time_to_first_message = reminder_start_date | plus: 2246400 %}
{{ time_to_first_message | date: '%Y-%m-%dT%H:%M' }}
{
"canvas_id": "954e15bc-af93-9dc8-a863-ad2580f1750e",
"recipients": [
{
"external_user_id": "{{${user_id}}}"
}
],
"trigger_properties" : {
"enquiry_id" : "{{event_properties.${reminder_id}}}",
"reminder_date" : "{{event_properties.${reminder_date} | date: '%Y-%m-%dT%H:%M:%S+0000'}}",
"message_personalisation_X" : "{{event_properties.${property_x}}}",
"message_personalisation_Y" : "{{event_properties.${property_y}}}",
"message_personalisation_Z" : "{{event_properties.${property_z}}}"
},
"schedule": {
"time": "{{ time_to_first_message | date: '%Y-%m-%dT%H:%M:%S+0000' }}"
}
}
{% comment %}
The following step checks if the time_to_reminder is less than 26 days away but more than 13 days away.
Users are scheduled to enter the journey on day 13.
{% endcomment %}
{% elsif 1123200 > {{time_to_reminder}} and {{time_to_reminder}} < 2246399 %}
{% assign time_to_first_message = reminder_start_date | plus: 1123200 %}
{
"canvas_id": "954e15bc-af93-9dc8-a863-ad2580f1750e",
"recipients": [
{
"external_user_id": "{{${user_id}}}"
}
],
"trigger_properties" : {
"enquiry_id" : "{{event_properties.${reminder_id}}}",
"reminder_date" : "{{event_properties.${reminder_date} | date: '%Y-%m-%dT%H:%M:%S+0000'}}",
"message_personalisation_X" : "{{event_properties.${property_x}}}",
"message_personalisation_Y" : "{{event_properties.${property_y}}}",
"message_personalisation_Z" : "{{event_properties.${property_z}}}"
},
"schedule": {
"time": "{{ time_to_first_message | date: '%Y-%m-%dT%H:%M:%S+0000' }}"
}
}
{% comment %}
The following step checks if the time_to_reminder is less than 13 days away but more than seven days away.
Users are scheduled to enter the journey on day 7.
{% endcomment %}
{% elsif 604800 > {{time_to_reminder}} and {{time_to_reminder}} < 1123199 %}
{% assign time_to_first_message = reminder_start_date | plus: 604800 %}
{
"canvas_id": "954e15bc-af93-9dc8-a863-ad2580f1750e",
"recipients": [
{
"external_user_id": "{{${user_id}}}"
}
],
"trigger_properties" : {
"enquiry_id" : "{{event_properties.${reminder_id}}}",
"reminder_date" : "{{event_properties.${reminder_date} | date: '%Y-%m-%dT%H:%M:%S+0000'}}",
"message_personalisation_X" : "{{event_properties.${property_x}}}",
"message_personalisation_Y" : "{{event_properties.${property_y}}}",
"message_personalisation_Z" : "{{event_properties.${property_z}}}"
},
"schedule": {
"time": "{{ time_to_first_message | date: '%Y-%m-%dT%H:%M:%S+0000' }}"
}
}
{% comment %}
The following step checks if the time_to_reminder is less than seven days away but more than two days away.
Users are scheduled to enter the journey on day 2.
{% endcomment %}
{% elsif {{time_to_reminder}} < 604799 and {{time_to_reminder}} > 172860 %}
{% assign time_to_first_message = reminder_start_date | plus: 172800 %}
{
"canvas_id": "954e15bc-af93-9dc8-a863-ad2580f1750e",
"recipients": [
{
"external_user_id": "{{${user_id}}}"
}
],
"trigger_properties" : {
"enquiry_id" : "{{event_properties.${reminder_id}}}",
"reminder_date" : "{{event_properties.${reminder_date} | date: '%Y-%m-%dT%H:%M:%S+0000'}}",
"message_personalisation_X" : "{{event_properties.${property_x}}}",
"message_personalisation_Y" : "{{event_properties.${property_y}}}",
"message_personalisation_Z" : "{{event_properties.${property_z}}}"
},
"schedule": {
"time": "{{ time_to_first_message | date: '%Y-%m-%dT%H:%M:%S+0000' }}"
}
}
{% endif %}
カスタムイベント reminder_capture が必要であり、カスタムイベントプロパティには少なくとも以下を含める必要があります。
reminder-id: カスタムイベントの識別子reminder_date: ユーザーが送信したリマインダーの期日message_personalisation_X: 送信時にメッセージをパーソナライズするために必要なプロパティ
配列内の文字列を検索する
このユースケースでは、カスタム属性の配列に特定の文字列が含まれているかどうかを確認し、存在する場合は特定のメッセージを表示します。
1
2
3
{% if custom_attribute.${PartnershipProgramsNotLinked} contains 'Hertz' %}
Link your Hertz account to use Hertz Fast Lane.
{% endif %}
配列内の最大値を見つける
このユースケースでは、指定されたカスタム属性配列内の最大値を計算し、ユーザーメッセージングで使用します。
たとえば、現在のハイスコアやアイテムの最高入札額をユーザーに表示したい場合があります。
1
2
3
4
5
6
7
8
{% assign maxValue = 0 %}
{% for attribute in {{custom_attribute.${array_attribute}}} %}
{% assign compareValue = {{attribute | plus: 0}} %}
{% if compareValue > maxValue %}
{% assign maxValue = compareValue %}
{% endif %}
{% endfor %}
{{maxValue}}
整数値を持ち、配列(リスト)の一部であるカスタム属性を使用する必要があります。
配列内の最小値を見つける
このユースケースでは、指定されたカスタム属性配列内の最小値を計算し、ユーザーメッセージングで使用します。
たとえば、最低スコアや最安値のアイテムをユーザーに表示したい場合があります。
1
2
3
4
5
6
7
8
{% assign minValue = custom_attribute.${array_attribute}[0] | plus: 0 %}
{% for attribute in {{custom_attribute.${array_attribute}}} %}
{% assign compareValue = {{attribute | plus: 0}} %}
{% if compareValue < minValue %}
{% assign minValue = compareValue %}
{% endif %}
{% endfor %}
{{minValue}}
整数値を持ち、配列(リスト)の一部であるカスタム属性を使用する必要があります。
文字列の末尾をクエリする
このユースケースでは、メッセージングで使用するために文字列の末尾をクエリします。
1
2
3
4
5
6
7
8
9
{% assign interest = {{custom_attribute.${Buyer Interest}}} | first %}
{% assign marketplace = interest | split: "" | reverse | join: "" | truncate: 4, "" %}
{% if {{marketplace}} == '3243' %}
Your last marketplace search was on {{custom_attribute.${Last marketplace buyer interest} | date: '%d.%m.%Y'}}. Check out all of our new offers.
{% else %}
{% abort_message() %}
{% endif %}
複数の組み合わせを持つカスタム属性から配列内の値をクエリする
このユースケースでは、まもなく期限切れになる番組のリストを取得し、ユーザーのお気に入りの番組がそのリストに含まれているかどうかを確認し、含まれている場合はまもなく期限切れになることを通知するメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{% assign expired_shows = 'Modern Family,The Rookie,Body of Proof,Felicity' | split: ',' %}
{% for show in expired_shows %}
{% if {{custom_attribute.${Favorite Shows}}} contains {{show}} %}
{% assign new_shows = new_shows | append: {{show}} | append: '*' %}
{% endif %}
{% endfor %}
{% assign new_shows_clean = new_shows | split: '*' %}
{% if new_shows_clean.size != 0 %}
All episodes of {{new_shows_clean | join: ', ' }} expire on 9/8 - watch them now before they're gone!
{% else %}
{% abort_message("Not found") %}
{% endif %}
まず配列間の一致を見つけ、最後に一致を分割するロジックを構築する必要があります。
文字列を電話番号にフォーマットする
このユースケースでは、phone_number ユーザープロファイルフィールド(デフォルトでは整数の文字列としてフォーマットされています)をインデックスし、ローカルの電話番号標準に基づいて再フォーマットする方法を示します。たとえば、1234567890 を (123)-456-7890 に変換します。
1
2
3
{% assign phone = {{${phone_number}}} | remove: "-" | split: '' %}
({{ phone[0] }}{{ phone[1] }}{{ phone[2] }})-{{ phone[3] }}{{ phone[4] }}{{ phone[5] }}-{{ phone[6] }}{{ phone[7] }}{{ phone[8] }}{{ phone[9] }}
プラットフォームターゲティング
- デバイス OS によってコピーを差別化する
- 特定のプラットフォームのみをターゲットにする
- 特定の OS バージョンの iOS デバイスのみをターゲットにする
- Web ブラウザのみをターゲットにする
- 特定のモバイルキャリアをターゲットにする
デバイス OS によってコピーを差別化する
このユースケースでは、ユーザーがどのプラットフォームを使用しているかを確認し、プラットフォームに応じて特定のメッセージを表示します。
たとえば、モバイルユーザーには短いバージョンのメッセージコピーを表示し、その他のユーザーには通常の長いバージョンのコピーを表示したい場合があります。また、モバイルユーザーに関連するメッセージを表示しつつ、Web ユーザーには関連しないメッセージを表示することもできます。たとえば、iOS のメッセージでは Apple Pay について言及し、Android のメッセージでは Google Pay について言及するなどです。
1
2
3
4
5
6
{% if targeted_device.${platform} == "ios" or targeted_device.${platform} == "android" %}
This is a shorter copy.
{% else %}
This is the regular copy and much longer than the short version.
{% endif %}
Liquid は大文字と小文字を区別します。targeted_device.${platform} はすべて小文字で値を返します。
特定のプラットフォームのみをターゲットにする
このユースケースでは、ユーザーのデバイスプラットフォームを取得し、プラットフォームに応じてメッセージを表示します。
たとえば、Android ユーザーにのみメッセージを送信したい場合があります。これは、セグメンテーションツール内でアプリを選択する代替手段として使用できます。
1
2
3
4
5
6
7
{% if {{targeted_device.${platform}}} == 'android' %}
This is a message for an Android user!
{% else %}
{% abort_message %}
{% endif %}
特定の OS バージョンのデバイスのみをターゲットにする
このユースケースでは、ユーザーの OS バージョンが特定のバージョンセットに該当するかどうかを確認し、該当する場合は特定のメッセージを表示します。
この例では、OS バージョン 10.0 以前のユーザーに、デバイス OS のサポートを段階的に終了することを警告するメッセージを送信しています。
1
2
3
4
5
6
7
{% if {{targeted_device.${os}}} == "10.0" or {{targeted_device.${os}}} == "10.0.1" or {{targeted_device.${os}}} == "10.0.2" or {{targeted_device.${os}}} == "10.0.3" or {{targeted_device.${os}}} == "10.1" or {{targeted_device.${os}}} == "10.2" or {{targeted_device.${os}}} == "10.2.1" or {{targeted_device.${os}}} == "10.3" or {{targeted_device.${os}}} == "10.3.1" or {{targeted_device.${os}}} == "10.3.2" or {{targeted_device.${os}}} == "10.3.3" or {{targeted_device.${os}}} == "10.3.4" or {{targeted_device.${os}}} == "9.3.1" or {{targeted_device.${os}}} == "9.3.2" or {{targeted_device.${os}}} == "9.3.3" or {{targeted_device.${os}}} == "9.3.4" or {{targeted_device.${os}}} == "9.3.5" %}
We are phasing out support for your device's operating system. Be sure to update to the latest software for the best app experience.
{% else %}
{% abort_message %}
{% endif %}
Web ブラウザのみをターゲットにする
このユースケースでは、ユーザーのターゲットデバイスが Mac または Windows で動作しているかどうかを確認し、該当する場合は特定のメッセージを表示します。
1
2
3
4
5
6
7
{% if {{targeted_device.${os}}} == 'Mac' or {{targeted_device.${os}}} == 'Windows' %}
This message will display on your desktop web browser.
{% else %}
{% abort_message %}
{% endif %}
以下のユースケースでは、Web ユーザーが iOS または Android を使用しているかどうかを確認し、該当する場合は特定のメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
{% if {{targeted_device.${os}}} == 'iOS' and {{targeted_device.${platform}}} == 'web' %}
Content for iOS.
{% elsif {{targeted_device.${os}}} == 'android' and {{targeted_device.${platform}}} == 'web' %}
Content for Android.
{% else %}
{% abort_message %}
{% endif %}
特定のモバイルキャリアをターゲットにする
このユースケースでは、ユーザーのデバイスキャリアが Verizon かどうかを確認し、該当する場合は特定のメッセージを表示します。
プッシュ通知とアプリ内メッセージチャネルでは、Liquid を使用してメッセージ本文にデバイスキャリアを指定できます。受信者のデバイスキャリアが一致しない場合、メッセージは送信されません。
1
2
3
4
5
6
7
{% if {{targeted_device.${carrier}}} contains "verizon" or {{targeted_device.${carrier}}} contains "Verizon" %}
This is a message for Verizon users!
{% else %}
{% abort_message %}
{% endif %}
SMS
受信 SMS キーワードに基づいて異なるメッセージで応答する
このユースケースでは、動的な SMS キーワード処理を組み込み、特定の受信メッセージに対して異なるメッセージコピーで応答します。たとえば、「START」とテキスト送信した場合と「JOIN」とテキスト送信した場合で異なる応答を送信できます。
1
2
3
4
5
6
7
8
9
10
11
{% assign inbound_message = {{sms.${inbound_message_body}}} | downcase | strip %}
{% if inbound_message contains 'start' %}
Thanks for joining our SMS program! Make sure your account is up to date for the best deals!
{% elsif inbound_message contains 'join' %}
Thanks for joining our SMS program! Create an account to get the best deals!
{% else %}
Thanks for joining our SMS program!
{% endif %}
タイムゾーン
- ユーザーのタイムゾーンをテンプレートに挿入する
- ユーザーのタイムゾーンに応じてメッセージをパーソナライズする
- カスタム属性に CST タイムゾーンを付加する
- タイムスタンプを挿入する
- ユーザーのローカルタイムゾーンの時間枠内でのみキャンバスプッシュを送信する
- ユーザーのローカルタイムゾーンの時間枠内で繰り返しアプリ内メッセージキャンペーンを送信する
- ユーザーのローカルタイムゾーンで平日と週末に異なるメッセージを送信する
- ユーザーのローカルタイムゾーンの時間帯に基づいて異なるメッセージを送信する
ユーザーのタイムゾーンをテンプレートに挿入する
デフォルトでは、Liquid の日付と時刻は協定世界時(UTC)で表示されます。ユーザーのローカルタイムゾーンで日付と時刻を表示するには、time_zone フィルターを date フィルターと組み合わせて使用します。
ローカルの日付と時刻を割り当てる
ユーザーのローカルタイムゾーンでの現在の日付と時刻を反映する変数を割り当てるには、次の形式を使用します。
1
2
{% assign local_date_time = 'now' | time_zone:{{${time_zone}}} | date: '%B %e, %Y' %}
{{local_date_time}}
now: 現在の日付と時刻を UTC で取得します。time_zone:{{${time_zone}}}パーソナライゼーションタグを使用して、デフォルト属性からユーザーのローカルタイムゾーンを取得します。date: ユーザーのローカルの日付と時刻を指定に従ってフォーマットします。前の例では、「February 26, 2026」のようにフォーマットされた文字列が表示されます。その他のフォーマットオプションについては、strftime.net を参照してください。
カスタム属性にユーザーのタイムゾーンを適用する
次のように、time_zone フィルターをカスタム属性に適用できます。
1
{{custom_attribute.${date_time_attribute} | time_zone: {{${time_zone}}} | date: '%a, %b %e, %Y'}}
これにより、date_time_attribute が曜日の省略形、月の省略形、日、4桁の年の順にフォーマットされて出力されます。
ユーザーのタイムゾーンに応じてメッセージをパーソナライズする
このユースケースでは、ユーザーのタイムゾーンに基づいて異なるメッセージを表示します。
1
2
3
4
5
6
7
{% if {{${time_zone}}} == 'xx' %}
Message for time zone xx.
{% elsif {{${time_zone}}} == 'yy' %}
Message for time zone yy.
{% else %}
{% abort_message("Invalid time zone") %}
{% endif %}
カスタム属性に CST タイムゾーンを付加する
このユースケースでは、指定されたタイムゾーンでカスタム日付属性を表示します。
オプション 1:
1
{{custom_attribute.${application_expires_date} | time_zone: -0005 | date: '%B, %d %Y' }}
オプション 2:
1
{{custom_attribute.${application_expires_date} | time_zone: 'America/Chicago' | date: '%B %d %Y %z' }}
タイムスタンプを挿入する
このユースケースでは、現在のタイムゾーンのタイムスタンプを含むメッセージを表示します。
以下の例では、日付を YYYY-mm-dd HH:MM:SS の形式で表示します(例:2021-05-03 10:41:04)。
1
{{${user_id} | default: 'You'}} received a campaign, rendered at ({{ "now" | time_zone: ${time_zone} | date: "%Y-%m-%d %H:%M:%S" }})
ユーザーのローカルタイムゾーンの時間枠内でのみキャンバスプッシュを送信する
このユースケースでは、ユーザーのローカルタイムゾーンでの時刻を確認し、設定された時間内であれば特定のメッセージを表示します。
1
2
3
4
5
6
7
{% assign time = 'now' | time_zone: ${time_zone} %}
{% assign hour = time | date: '%H' | plus: 0 %}
{% if hour > 20 or hour < 8 %}
{% abort_message("Outside allowed time window") %}
{% endif %}
Here's a message that will send between 8 am and 8 pm!
ユーザーのローカルタイムゾーンの時間枠内で繰り返しアプリ内メッセージキャンペーンを送信する
このユースケースでは、ユーザーの現在の時刻が設定された時間枠内にある場合にメッセージを表示します。
たとえば、以下のシナリオでは、店舗が閉店していることをユーザーに知らせます。
1
2
3
4
5
6
7
8
9
{% assign time = 'now' | time_zone: ${time_zone} %}
{% assign hour = time | date: '%H' | plus: 0 %}
{% if hour > 21 or hour < 10 %}
Store's closed. Come back between 11 am and 9 pm!
{% else %}
{% abort_message("Not sent because the store is open") %}
{% endif %}
ユーザーのローカルタイムゾーンで平日と週末に異なるメッセージを送信する
このユースケースでは、ユーザーの現在の曜日が土曜日か日曜日かを確認し、曜日に応じて異なるメッセージを表示します。
1
2
3
4
5
6
7
{% assign today = 'now' | time_zone: ${time_zone} | date: "%A" %}
{% if {{today}} == 'Saturday' or {{today}} == 'Sunday' %}
It's {{today}}, why don't you open the app for your transactions?
{% else %}
It's {{today}}, why don't you visit the store?
{% endif %}
ユーザーのローカルタイムゾーンの時間帯に基づいて異なるメッセージを送信する
このユースケースでは、ユーザーの現在の時刻が設定された時間枠外にある場合にメッセージを表示します。
たとえば、時間帯に依存する時間限定のオファーについてユーザーに伝えたい場合があります。
1
2
3
4
5
6
7
{% assign time = 'now' | time_zone: ${time_zone} %}
{% assign hour = time | date: '%H' | plus: 0 %}
{% if hour > 20 or hour < 8 %}
{% abort_message("Outside allowed time window") %}
{% endif %}
Check out this new bar after work today. HH specials!
これはクワイエットアワーの逆です。
週/日/月
前月の名前をメッセージに取り込む
このユースケースでは、現在の月を取得し、前月を表示してメッセージングで使用します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{% assign today = 'now' | date: "%m" %}
{% assign last_month = {{today}} | minus: 1 %}
{% if last_month == 1 %}
{% assign month = "January" %}
{% elsif last_month == 2 %}
{% assign month = "February" %}
{% elsif last_month == 3 %}
{% assign month = "March" %}
{% elsif last_month == 4 %}
{% assign month = "April" %}
{% elsif last_month == 5 %}
{% assign month = "May" %}
{% elsif last_month == 6 %}
{% assign month = "June" %}
{% elsif last_month == 7 %}
{% assign month = "July" %}
{% elsif last_month == 8 %}
{% assign month = "August" %}
{% elsif last_month == 9 %}
{% assign month = "September" %}
{% elsif last_month == 10 %}
{% assign month = "October" %}
{% elsif last_month == 11 %}
{% assign month = "November" %}
{% elsif last_month == 0 %}
{% assign month = "December" %}
{% endif %}
Here's an overview of what your spending looked like in {{month}}.
同じ結果を得るために、以下の方法も使用できます。
1
2
3
{% assign last_month_name = 'now' | date: "%Y-%m-01" | date: '%s' | minus: 1 | date: "%B" %}
Here's an overview of what your spending looked like in {{last_month_name}}.
毎月末にキャンペーンを送信する
このユースケースでは、現在の日付が日付リストに含まれているかどうかを確認し、日付に応じて特定のメッセージを表示します。
うるう年(2月29日)は考慮されていません。
1
2
3
4
5
6
7
8
9
{% assign current_date = 'now' | date: '%b %d' %}
{% if current_date == "Jan 31" or current_date == "Feb 28" or current_date == "Mar 31" or current_date == "Apr 30" or current_date == "May 31" or current_date == "Jun 30" or current_date == "Jul 31" or current_date == "Aug 31" or current_date == "Sep 30" or current_date == "Oct 31" or current_date == "Nov 30" or current_date == "Dec 31" %}
The date is correct
{% else %}
{% abort_message("Date is not listed") %}
{% endif %}
月の最後の(平日)にキャンペーンを送信する
このユースケースでは、現在の月と日を取得し、現在の日が月の最後の平日に該当するかどうかを計算します。
たとえば、毎月最後の水曜日にユーザーに製品フィードバックのアンケートを送信したい場合があります。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{% comment %}Pull the day, day name, month, and year from today's date.{% endcomment %}
{% assign current_day = "now" | date: "%d" %}
{% assign current_day_name = "now" | date: "%a" %}
{% assign current_month = "now" | date: "%b" %}
{% assign current_year = "now" | date: "%Y" %}
{% comment %}Assign the correct number of days for the current month.{% endcomment %}
{% if current_month == "Jan" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Mar" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Apr" %}
{% assign last_day_of_month = 30 %}
{% elsif current_month == "May" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Jun" %}
{% assign last_day_of_month = 30 %}
{% elsif current_month == "Jul" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Aug" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Sep" %}
{% assign last_day_of_month = 30 %}
{% elsif current_month == "Oct" %}
{% assign last_day_of_month = 31 %}
{% elsif current_month == "Nov" %}
{% assign last_day_of_month = 30 %}
{% elsif current_month == "Dec" %}
{% assign last_day_of_month = 31 %}
{% endif %}
{% comment %}Assign the correct number of days if the current month is February, taking into account leap years.{% endcomment %}
{% assign leap_year_remainder = current_year | modulo: 4 %}
{% if leap_year_remainder == 0 and current_month == "Feb" %}
{% assign last_day_of_month = 29 %}
{% elsif current_month == "Feb" %}
{% assign last_day_of_month = 28 %}
{% endif %}
{% comment %}Check that today's date is within a week of the last day of the month. If not, abort the message. If so, check that today is Wednesday. If not, abort the message.{% endcomment %}
{% assign diff_in_days = last_day_of_month | minus: current_day | plus: 1%}
{% if diff_in_days <= 7 %}
{% unless current_day_name == "Wed" %}
{% abort_message("Wrong day of the week") %}
{% endunless %}
{% else %}
{% abort_message("Not the last week of the month") %}
{% endif %}
月の各日に異なるメッセージを送信する
このユースケースでは、現在の日付がリスト上の日付と一致するかどうかを確認し、日に応じて異なるメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{% assign today = 'now' | time_zone: {{${time_zone}}} | date: "%Y-%m-%d" %}
{% assign day_1 = "2019-12-01" | time_zone: {{${time_zone}}} | date: "%Y-%m-%d" %}
{% assign day_2 = "2019-12-02" | time_zone: {{${time_zone}}} | date: "%Y-%m-%d" %}
{% assign day_3 = "2019-12-03" | time_zone: {{${time_zone}}} | date: "%Y-%m-%d" %}
{% if today == day_1 %}
Message for 2019-12-01
{% elsif today == day_2 %}
Message for 2019-12-02
{% elsif today == day_3%}
Message for 2019-12-03
{% else %}
{% abort_message("Date not listed") %}
{% endif %}
曜日ごとに異なるメッセージを送信する
このユースケースでは、現在の曜日を確認し、曜日に応じて異なるメッセージを表示します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{% assign today = 'now' | date: "%A" %}
{% case today %}
{% when 'Monday' %}
Monday copy
{% when 'Tuesday' %}
Tuesday copy
{% when 'Wednesday' %}
Wednesday copy
{% when 'Thursday' %}
Thursday copy
{% when 'Friday' %}
Friday copy
{% when 'Saturday' %}
Saturday copy
{% when 'Sunday' %}
Sunday copy
{% else %}
Default copy
{% endcase %}
「Default copy」の行を {% abort_message() %} に置き換えて、曜日が不明な場合にメッセージの送信を防止できます。