-
Notifications
You must be signed in to change notification settings - Fork 35
/
record-judge-me-customer-review-counts.json
23 lines (23 loc) · 3.29 KB
/
record-judge-me-customer-review-counts.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"docs": "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.\n\nAfter installing this task, activate Judge.me's Mechanic integration: Settings > Integrations > Admin Backend > Mechanic.\r\n\r\nNotes:\r\n\r\n* This task will start counting reviews for each customer, as each review comes in. It will not scan reviews that existed beforehand.\r\n* 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.",
"halt_action_run_sequence_on_error": false,
"name": "Record Judge.me customer review counts",
"online_store_javascript": null,
"options": {
"metafield_namespace_required": null,
"metafield_key__required": null,
"tags_to_apply_for_review_counts__keyval": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign metafield_namespace = options.metafield_namespace__required %}\n{% assign metafield_key = options.metafield_key__required %}\n\n{% assign customer = shop.customers[review.reviewer.external_id] %}\n\n{% if event.preview %}\n {% capture customer_json %}\n {\n \"admin_graphql_api_id\": \"gid://shopify/Customer/1234567890\",\n \"metafields\": [\n {\n \"namespace\": {{ metafield_namespace | json }},\n \"key\": {{ metafield_key | json }},\n \"value\": 0\n }\n ]\n }\n {% endcapture %}\n\n {% assign customer = customer_json | parse_json %}\n{% endif %}\n\n{% if customer %}\n {% assign current_review_count = customer.metafields[metafield_namespace][metafield_key].value | default: 0 %}\n {% assign next_review_count = current_review_count | plus: 1 %}\n {% assign next_review_count_as_string = next_review_count | append: \"\" %}\n {% assign tag = options.tags_to_apply_for_review_counts__keyval[next_review_count_as_string] %}\n\n {% action \"shopify\" %}\n mutation {\n metafieldsSet(\n metafields: [\n {\n ownerId: {{ customer.admin_graphql_api_id | json }}\n namespace: {{ metafield_namespace | json }}\n key: {{ metafield_key | json }}\n value: {{ next_review_count_as_string | json }}\n type: \"number_integer\"\n }\n ]\n ) {\n metafields {\n id\n namespace\n key\n type\n value\n owner {\n ... on Customer {\n id\n }\n }\n }\n userErrors {\n code\n field\n message\n }\n }\n {% if tag != blank %}\n tagsAdd(\n id: {{ customer.admin_graphql_api_id | json }}\n tags: {{ tag | json }}\n ) {\n node {\n id\n }\n userErrors {\n field\n message\n }\n }\n {% endif %}\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"judgeme/review/created"
],
"subscriptions_template": "judgeme/review/created",
"tags": [
"Customers",
"Judge.me",
"Reviews"
]
}