Record Judge.me customer review counts, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Record Judge.me customer review counts

by Isaac Bowen (team@usemechanic.com)

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 when a Judge.me review is created. Configuration includes metafield namespace required, metafield key, and tags to apply for review counts.

15-day free trial – unlimited tasks

Documentation

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, 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.

Events
when a Judge.me review is created (judgeme/review/created)
Options
metafield namespace required, metafield key (required), tags to apply for review counts (keyval)
Script
{% assign customer = shop.customers[review.reviewer.external_id] %}

{% if customer or event.preview %}
  {% assign current_review_count = customer.metafields[options.metafield_namespace_required][options.metafield_key__required] | default: 0 %}
  {% assign next_review_count = current_review_count | plus: 1 %}

  {% assign metafield = hash %}
  {% assign metafield["namespace"] = options.metafield_namespace_required %}
  {% assign metafield["key"] = options.metafield_key__required %}
  {% assign metafield["value_type"] = "integer" %}
  {% assign metafield["value"] = next_review_count %}
  {% assign params = hash %}
  {% assign params["metafield"] = metafield %}

  {% if event.preview %}
    {% assign metafield_url = "/admin/customers/1234567890/metafields.json" %}
  {% else %}
    {% assign metafield_url = "/admin/customers/" | append: customer.id | append: "/metafields.json" %}
  {% endif %}

  {% action "shopify" "post", metafield_url, params %}

  {% 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] %}

  {% if tag != blank %}
    {% capture query %}
      mutation {
        tagsAdd(
          id: {% if event.preview %}"gid://shopify/Customer/1234567890"{% else %}{{ customer.admin_graphql_api_id | json }}{% endif %}
          tags: {{ tag | json }}
        ) {
          node {
            id
          }
          userErrors {
            field
            message
          }
        }
      }
    {% endcapture %}

    {% action "shopify" query %}
  {% endif %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.