Auto-invite customers when tagged
This task watches for tags being added to customers, and sends invites for any customer who gets the tag you choose, who hasn't previously been invited. If you'd like to run this task in bulk, you can find that version of the task here.
Try this taskWhen it runs
Triggers when tags are added to a customer
What you choose
- Tag to watch for
- Invitation email subject
- Invitation email body
Documentation
This task watches for tags being added to customers, and sends invites for any customer who gets the tag you choose, who hasn't previously been invited. If you'd like to run this task in bulk, you can find that version of the task here.
Invitation emails are sent using your store's account invite notification email template. Learn how to update this template.
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
shopify/customer/tags_added
How task subscriptions work
Option types and flags
- Tag to watch for (required)
- Invitation email subject (required)
- Invitation email body (multiline, required)
Task code
{% assign tag_to_watch_for = options.tag_to_watch_for__required | downcase %}
{% assign invitation_email_subject = options.invitation_email_subject__required %}
{% assign invitation_email_body = options.invitation_email_body__multiline_required %}
{% if event.topic == "shopify/customer/tags_added" %}
{% comment %}
-- check tags before querying the customer with GraphQL, so we know if the monitored tag was just added
-- note: this webhook uses a tags array, unlike most other webhooks with tags
{% endcomment %}
{% if event.preview %}
{% capture customer_json %}
{
"customerId": "gid://shopify/Customer/1234567890",
"tags": {{ array | push: tag_to_watch_for | json }}
}
{% endcapture %}
{% assign customer = customer_json | parse_json %}
{% endif %}
{% assign added_tags = customer.tags | json | downcase | parse_json %}
{% unless added_tags contains tag_to_watch_for %}
{% break %}
{% endunless %}
{% comment %}
-- get customer data
{% endcomment %}
{% capture query %}
query {
customer(id: {{ customer.customerId | json }}) {
id
displayName
defaultEmailAddress {
emailAddress
}
state
tags
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"customer": {
"id": "gid://shopify/Customer/1234567890",
"state": "DISABLED"
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign customer = result.data.customer %}
{% unless event.preview %}
{% log customer: customer %}
{% endunless %}
{% unless customer.state == "DISABLED" %}
{% log "Customer state is not 'DISABLED', so an account invite will not be sent." %}
{% break %}
{% endunless %}
{% action "shopify" %}
mutation {
customerSendAccountInviteEmail(
customerId: {{ customer.id | json }}
email: {
subject: {{ invitation_email_subject | json }}
customMessage: {{ invitation_email_body | json }}
}
) {
customer {
id
displayName
defaultEmailAddress {
emailAddress
}
state
}
}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference
Default option values
- Tag to watch for
invite- Invitation email subject
Your account is ready!- Invitation email body
Your account for {{ shop.name }} has been pre-approved! Use the button below to get started.