Record Judge.me customer review counts, with Mechanic.

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

Record Judge.me customer review counts

Using Judge.me for reviews? Use this task to keep a counter for each customer's reviews, stored as a metafield on the customer record. And, auto-tag customers as they reach different levels of review counts - useful for granting discounts or special access to repeat reviewers.

Runs Occurs when a Judge.me review is created. Configuration includes metafield namespace, metafield key, and tags to apply for review counts.

15-day free trial – unlimited tasks

Documentation

Using Judge.me for reviews? Use this task to keep a counter for each customer's reviews, stored as a metafield on the customer record. And, auto-tag customers as they reach different levels of review counts - useful for granting discounts or special access to repeat reviewers.

After installing this task, activate Judge.me's Mechanic integration: Settings > Integrations > Admin Backend > Mechanic.

Notes:

  • This task will start counting reviews for each customer, as each review comes in. It will not scan reviews that existed beforehand.
  • Reviews will only be attributed to a customer account if (a) the customer is already registered, and (b) the reviewer submits the correct customer email address in the review form.

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
judgeme/review/created
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
metafield namespace (required), metafield key (required), tags to apply for review counts (keyval)
Code
{% assign metafield_namespace = options.metafield_namespace__required %}
{% assign metafield_key = options.metafield_key__required %}

{% assign customer = shop.customers[review.reviewer.external_id] %}

{% if event.preview %}
  {% capture customer_json %}
    {
      "admin_graphql_api_id": "gid://shopify/Customer/1234567890",
      "metafields": [
        {
          "namespace": {{ metafield_namespace | json }},
          "key": {{ metafield_key | json }},
          "value": 0
        }
      ]
    }
  {% endcapture %}

  {% assign customer = customer_json | parse_json %}
{% endif %}

{% if customer %}
  {% assign current_review_count = customer.metafields[metafield_namespace][metafield_key].value | default: 0 %}
  {% assign next_review_count = current_review_count | plus: 1 %}
  {% assign next_review_count_as_string = next_review_count | append: "" %}
  {% assign tag = options.tags_to_apply_for_review_counts__keyval[next_review_count_as_string] %}

  {% action "shopify" %}
    mutation {
      metafieldsSet(
        metafields: [
          {
            ownerId: {{ customer.admin_graphql_api_id | json }}
            namespace: {{ metafield_namespace | json }}
            key: {{ metafield_key | json }}
            value: {{ next_review_count_as_string | json }}
            type: "number_integer"
          }
        ]
      ) {
        metafields {
          id
          namespace
          key
          type
          value
          owner {
            ... on Customer {
              id
            }
          }
        }
        userErrors {
          code
          field
          message
        }
      }
      {% if tag != blank %}
        tagsAdd(
          id: {{ customer.admin_graphql_api_id | json }}
          tags: {{ tag | json }}
        ) {
          node {
            id
          }
          userErrors {
            field
            message
          }
        }
      {% endif %}
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more