Auto-tag customers based on email domain with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Auto-tag customers based on email domain

by Isaac Bowen (team@usemechanic.com)

Useful in a million scenarios. The merchant who requested this task has discounts set up based on customer tag, and they're using this task to guarantee that qualifying customers see their discount immediately – even if they just signed up!

Runs when a customer is created. Configuration includes customer email domains and customer tag to apply.

15-day free trial – unlimited tasks

Developer details

Events
when a customer is created (shopify/customers/create)
Options
customer email domains (required, multiline), customer tag to apply (required)
Script
{% comment %}
  This task works with shopify/customers/update, should the merchant
  be interested in that event as well. :)
{% endcomment %}

{% assign customer_email_domain = customer.email | split: "@" | last %}
{% assign customer_tags = customer.tags | split: ", " %}
{% assign customer_qualifies = false %}

{% capture newline %}
{% endcapture %}

{% assign qualified_email_domains = options.customer_email_domains__required_multiline | split: newline %}
{% if qualified_email_domains contains customer_email_domain %}
  {% assign customer_qualifies = true %}
{% endif %}

{% if customer_tags contains options.customer_tag_to_apply__required %}
  {% assign customer_qualifies = false %}
{% endif %}

{% if event.preview or customer_qualifies %}
  {% capture customer_tags_to_apply %}{% if customer.tags != blank %}{{ customer.tags }}, {% endif %}{{ options.customer_tag_to_apply__required }}{% endcapture %}

  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "customer",
          {{ customer.id | json }}
        ],
        {
          "tags": {{ customer_tags_to_apply | json }}
        }
      ]
    }
  }
{% endif %}
Yep, that’s just Liquid! If this is interesting to you, check out our documentation! Mechanic is hugely developer-friendly. :)