Auto-tag new customers by staff member, with Mechanic.

Mechanic is a development platform for Shopify. :)

Auto-tag new customers by staff member

Use this task to easily keep track of who's responsible for manually creating new customers.

Runs when a customer is created. Configuration includes staff names and tags.

15-day free trial – unlimited tasks

Documentation

Use this task to easily keep track of who's responsible for manually creating new customers.

To use this task, fill in the "Staff names and tags" option with staff names on the left, and the tags you'd like to apply on the right. Make sure to use each staff member's exact full name – it's case-sensitive! Tags will be applied as soon as the customer is created.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

Open source
View on GitHub to contribute to this task
Events
when a customer is created (shopify/customers/create)
Options
staff names and tags (keyval, required)
Script
{% capture query %}
  query {
    customer(id: {{ customer.admin_graphql_api_id | json }}) {
      id
      events(first: 250) {
        edges {
          node {
            attributeToUser
            message
          }
        }
      }
    }
  }
{% endcapture %}

{% assign result = query | shopify %}

{% assign placed_event = result.data.first.last.events.edges | map: "node" | where: "attributeToUser" | first %}
{% assign name = placed_event.message | split: " created this " | first %}
{% assign tag_to_add = options.staff_names_and_tags__keyval_required[name] %}

{% if event.preview %}
  {% assign name = options.staff_names_and_tags__keyval_required.first.first %}
  {% assign tag_to_add = options.staff_names_and_tags__keyval_required.first.last %}
{% endif %}

{% if name == blank %}
  {% log message: "No staff member detected.", customer: result.data.first.last %}
{% elsif tag_to_add == blank %}
  {% log message: "No tag applicable for staff member.", staff_member: name %}
{% else %}
  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ customer.admin_graphql_api_id | json }}
        tags: {{ tag_to_add | json }}
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Staff names and tags
{"Jane Doe"=>"created-by-jane", "Zhang Wei"=>"created-by-zhang"}