Auto-tag new online orders by web browser, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Auto-tag new online orders by web browser

This task monitors incoming orders, and tags them with information about the customer's web browser.

Runs Occurs whenever an order is created and Occurs when a user manually triggers the task. Configuration includes include browser version.

15-day free trial – unlimited tasks

Documentation

This task monitors incoming orders, and tags them with information about the customer's web browser.

This task will monitor incoming orders, and tag them if the browser name can be derived from the order information.

Run this task manually to scan your existing orders, and tag them as appropriate.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, 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.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/orders/create
mechanic/user/trigger
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
include browser version (boolean)
Code
{% assign orders = array %}
{% if event.preview %}
  {% assign orders[0] = '{"admin_graphql_api_id":"gid://shopify/Order/1234567890"}' | parse_json %}
{% elsif event.topic contains "shopify/orders/" %}
  {% assign orders[0] = order %}
{% elsif event.topic == "mechanic/user/trigger" %}
  {% assign orders = shop.orders.any %}
{% endif %}

{% for order in orders %}
  {% assign user_agent = order.client_details.user_agent %}

  {% if event.preview and user_agent == blank %}
    {% assign user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" %}
  {% elsif user_agent == blank %}
    {% continue %}
  {% endif %}

  {% assign browser = user_agent | browser %}
  {% assign order_tags = order.tags | split: ", " %}
  {% assign tag_to_add = browser.name %}
  {% if options.include_browser_version__boolean %}
    {% assign tag_to_add = tag_to_add | append: " " | append: browser.version | strip %}
  {% endif %}

  {% unless order_tags contains tag_to_add %}
    {% action "shopify" %}
      mutation {
        tagsAdd(
          id: {{ order.admin_graphql_api_id | json }}
          tags: {{ tag_to_add | json }}
        ) {
          userErrors {
            field
            message
          }
        }
      }
    {% endaction %}
  {% endunless %}
{% endfor %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more