You have been using customer segmentation in your email marketing tool as a way to personalize the emails you send to your subscribers based on activity they perform like cart abandon, account created, what they have bought in the past, and much more.
This email segmentation secret sauce assists in sending relevant emails to customers that are packed with information that they actually want. That personalization leads to more conversions, more purchases, and happier customers.

But did you know, you could further improve this experience by creating these segments in your loyalty program as well? Think about encouraging your cart abandoned customers to make a purchase with you at a favourable discount.
You can create the segment you have in your email marketing tools in your loyalty program as well using ‘custom attributes.’ Using these attributes, you can apply business rules, run campaigns, customize your rewards, etc., as per the segment you select.

Know more about custom attributes.
import jwt
secret = 'your-api-key'
user_info = {
'sub': 'api-key-identifier'
# REQUIRED: Pass API key identifier.
'member_id' : 'Unique-ID',
# REQUIRED: Pass members unique identifier in this field when user is Logged in. For Non-Logged in users, pass an empty string ('')
'email_address' : 'useremail@gmail.com',
# Optional: Please provide the email address of the member to whom you would like to send the loyalty email notifications.
'first_name' : 'First Name',
# Optional
'last_name' : 'Last Name',
# Optional
'member_status' : 'active',
# Optional
'member_tags' : ['Frequent buyer', 'Loyal'],
# 'append__member_tags': ['test','Test1','campaign_e342f'],
# 'remove__member_tags': ['test','Test1','campaign_e342f'],
# Optional: Please see the note below for more details. Select the member tags parameter as per the requirement.
'phone_number' : '+1-7203332525',
# Optional
'birthdate' : '12/06/2020',
# Optional (Format : <MM/DD/YYYY HH:MM:SS>)
'anniversary_date' : '12/06/2020',
# Optional (Format : <MM/DD/YYYY HH:MM:SS>)
'preferred_language': 'english',
# Optional: If you have a multi-language store, refer SUPPORTED_LANGUAGES_LIST = ['english', 'french', 'italian', 'german', 'spanish', 'custom language one', 'custom language two']
'twitter_handle':'www.twitter.com/john',
# Optional
'instagram_handle':'www.instagram.com/john',
# Optional
'referrer_code':'JOH3TNLY',
# Optional
'current_tier_id':'zrl_silver',
# Optional: Pass valid tier_id.
'custom_attributes': {
"City_Name": "Paris",
# String field
"Age_In_Years": 37,
# Integer field
"last_visit_date": "03/16/2022 00:00:00",
# Date field (Format: < MM/DD/YYYY HH:MM:SS>)
"visited_cities": ["Paris", "London"]
# List field
}
# Optional: To create custom_attributes, contact your account manager at support@zinrelo.com.
'address': {
'line1': '530 Lytton Ave',
'line2': 'Suite #200',
'city': 'Palo Alto',
'state': 'CA',
'country': 'US',
'postal_code': '94301',
},
# Optional
'exp': '',
# Epoch timestamp (seconds), after which the token will expire
# Optional: While this field is optional, but we recommend to set the token expiry after 30 minutes.
}
encoded_jwt = jwt.encode(user_info, secret, algorithm='HS256')
print(encoded_jwt)
{% capture current_time_seconds %}{{ "now" | date: "%s" }}{% endcapture %}
// Please don't make any changes to the tag logic. This is the logic for "Enter Shopify Tags" for your Shopify store.
{% assign tags_list = "" %}
{% for tag in customer.tags %}
{% if block.settings.check_tag contains tag %}
{% assign tags_list = tags_list | append: '"' | append: tag | append: '",' %}
{% endif %}
{% endfor %}
{% assign len = tags_list | size | minus: 1 %}
{% assign last_char = tags_list | slice: len, 1 %}
{% if last_char == "," %}
{% assign tags_list = tags_list | slice: 0, len %}
{% endif %}
{%- comment -%}
// Member info
{%- endcomment -%}
{% assign member_id = customer.email %}
{% assign email_address = customer.email %}
{% assign exp_seconds = 1200 %}
{% assign custom_attributes = '{"shopify_customer_id":"' | append: customer.id | append: '"}' %}
{% assign member_tags = '[]' %}
{%- comment -%}
{%- endcomment -%}
{% if member_tags == '[]' and tags_list != "" %}
{% assign member_tags = '[' | append: tags_list | append: ']' %}
{% endif %}
{% assign exp = current_time_seconds | plus: exp_seconds %}
{% assign zinrelo_api_key = '"' | append: shop.metafields.Zinrelo.zinrelo_api_configuration.value.api_key[0] | append: '"' %}
{% capture user_info %}
// Update member info
// Assign member tags. For more details, refer to the notes below.
{
"member_id": "{{ member_id }}",
"email_address": "{{ email_address }}",
"exp": {{ exp }},
"first_name": "{{ customer.first_name }}",
{% if member_tags != '[]' and member_tags != '' %}
"append__member_tags": {{ member_tags }},
{% endif %}
"custom_attributes": {{ custom_attributes }},
"last_name": "{{ customer.last_name }}"
}
{% endcapture %}
{%- comment -%}
// Capture store details
// Make sure to not make any changes to the snippet below. Keep it as it is.
{%- endcomment -%}
{% assign zinrelo_api_key = zinrelo_api_key | replace: '"', "" %}
{% assign header = '{"alg": "HS256", "typ": "JWT"}' %}
{% assign encodedHeader = header | base64_encode | replace: '+', '-' | replace: '/', '_' | replace: '=', '' %}
{% assign encodedUserInfo = user_info | base64_encode %}
{% assign encodedPayload = encodedHeader | append: "." | append: encodedUserInfo %}
{% assign encodedPayload = encodedPayload | replace: "+", "-" | replace: "/", "_" | replace: "=", "" %}
{% assign hexSignature = encodedPayload | hmac_sha256: zinrelo_api_key %}
jwtPayload = "{{ encodedPayload }}";
jwtHexSignature = "{{ hexSignature }}";
base64JWTSignature = Base64EncodeUrl(hexToBase64(jwtHexSignature));
jwt_token = jwtPayload + "." + base64JWTSignature;
window._zrl = window._zrl || [];
var init_data = {
"server": "https://docker.shopsocially.com",
"version": 'v2',
"jwt_token": jwt_token,
"partner_id": "{{ shop.metafields.Zinrelo.zinrelo_api_configuration.value['partner_id'] }}"
};
console.log(init_data);
_zrl.push(['init', init_data]);
Please Note:
You can append, overwrite, or remove member tags. For more details on member tags, refer to the snippet here.
If you want to pass the customer ID in your Shopify store, please include the ID in the member info. Otherwise, the details will not be stored.
To add and update more member information, refer to the snippet here.
Comments
Please sign in to leave a comment.