# Shopify Admin Customer Spend Tier Tagger

> Calculates lifetime spend per customer and applies tier tags (Bronze/Silver/Gold/Platinum) based on configurable thresholds.

- **Type:** Skill
- **Install:** `agentstack add skill-40rty-ai-shopify-admin-skills-shopify-admin-customer-spend-tier-tagger`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [40RTY-ai](https://agentstack.voostack.com/s/40rty-ai)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [40RTY-ai](https://github.com/40RTY-ai)
- **Source:** https://github.com/40RTY-ai/shopify-admin-skills/tree/main/skills/customer-ops/shopify-admin-customer-spend-tier-tagger
- **Website:** http://skills.40rty.ai

## Install

```sh
agentstack add skill-40rty-ai-shopify-admin-skills-shopify-admin-customer-spend-tier-tagger
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

## Purpose
Queries all customers, calculates their lifetime spend using order history, and assigns a spend-tier tag (Bronze/Silver/Gold/Platinum by default). Enables VIP segmentation for loyalty programs, exclusive offers, and CX prioritization without a third-party loyalty app. Extends the existing `loyalty-segment-export` skill with a write step.

## Prerequisites
- Authenticated Shopify CLI session: `shopify store auth --store  --scopes read_customers,read_orders,write_customers`
- API scopes: `read_customers`, `read_orders`, `write_customers`

## Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| store | string | yes | — | Store domain (e.g., mystore.myshopify.com) |
| tiers | object | no | see below | Spend thresholds per tier (in store currency) |
| tag_prefix | string | no | tier | Tag prefix (e.g., `tier:bronze`, `tier:silver`) |
| remove_old_tiers | bool | no | true | Remove existing tier tags before applying new ones |
| dry_run | bool | no | true | Preview without executing mutations |
| format | string | no | human | Output format: `human` or `json` |

Default tiers (store currency):
```
bronze:   $0–$249
silver:   $250–$999
gold:     $1,000–$4,999
platinum: $5,000+
```

## Safety

> ⚠️ `tagsAdd` adds tags to customer records visible to staff and used by marketing segments. If `remove_old_tiers: true`, existing tier tags matching `tag_prefix` are removed before new ones are applied. Run with `dry_run: true` to review the tier distribution before committing.

## Workflow Steps

1. **OPERATION:** `customers` — query
   **Inputs:** `first: 250`, select `id`, `amountSpent`, pagination cursor
   **Expected output:** All customers with lifetime spend; paginate until `hasNextPage: false`

2. Assign tier to each customer based on `amountSpent.amount` vs. `tiers` thresholds

3. **OPERATION:** `orders` — query (optional — for verification of spend figures)

4. **OPERATION:** `tagsAdd` — mutation
   **Inputs:** Customer `id`, `tags: [":"]`
   **Expected output:** Updated customer tags; `userErrors`

## GraphQL Operations

```graphql
# customers:query — validated against api_version 2025-01
query CustomerSpendLevels($after: String) {
  customers(first: 250, after: $after) {
    edges {
      node {
        id
        displayName
        defaultEmailAddress {
          emailAddress
        }
        amountSpent {
          amount
          currencyCode
        }
        numberOfOrders
        tags
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

```graphql
# orders:query — validated against api_version 2025-01
query CustomerOrderHistory($customerId: String!, $after: String) {
  orders(first: 250, after: $after, query: $customerId) {
    edges {
      node {
        id
        totalPriceSet {
          shopMoney {
            amount
            currencyCode
          }
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

```graphql
# tagsAdd:mutation — validated against api_version 2025-01
mutation TagsAdd($id: ID!, $tags: [String!]!) {
  tagsAdd(id: $id, tags: $tags) {
    node {
      id
    }
    userErrors {
      field
      message
    }
  }
}
```

## Session Tracking

**Claude MUST emit the following output at each stage. This is mandatory.**

**On start**, emit:
```
╔══════════════════════════════════════════════╗
║  SKILL: Customer Spend Tier Tagger           ║
║  Store:                        ║
║  Started:              ║
╚══════════════════════════════════════════════╝
```

**After each step**, emit:
```
[N/TOTAL]   
          → Params: 
          → Result: 
```

If `dry_run: true`, prefix every mutation step with `[DRY RUN]` and do not execute it.

**On completion**, emit:

For `format: human` (default):
```
══════════════════════════════════════════════
OUTCOME SUMMARY
  Customers processed:  
  Bronze:      (%)
  Silver:      (%)
  Gold:        (%)
  Platinum:    (%)
  Tags applied: 
  Errors:       
  Output:       tier_tagging_.csv
══════════════════════════════════════════════
```

For `format: json`, emit:
```json
{
  "skill": "customer-spend-tier-tagger",
  "store": "",
  "started_at": "",
  "dry_run": true,
  "tier_distribution": { "bronze": 0, "silver": 0, "gold": 0, "platinum": 0 },
  "tags_applied": 0,
  "errors": 0,
  "output_file": "tier_tagging_.csv"
}
```

## Output Format
CSV file `tier_tagging_.csv` with columns:
`customer_id`, `name`, `email`, `lifetime_spend`, `currency`, `tier`, `previous_tags`, `new_tags`

## Error Handling
| Error | Cause | Recovery |
|-------|-------|----------|
| `THROTTLED` | API rate limit exceeded | Wait 2 seconds, retry up to 3 times |
| `userErrors` on tagsAdd | Invalid customer ID | Log error, skip customer, continue |
| No customers | Empty store | Exit with 0 results |

## Best Practices
- Run monthly to keep tier assignments current — customers who increase their spend will move up tiers automatically.
- Use `remove_old_tiers: true` to ensure each customer has exactly one tier tag at any time.
- Adjust `tiers` thresholds to your store's AOV and LTV distribution — the defaults work for stores with $50–100 AOV.
- After tagging, create Shopify Customer Segments using tag filters to target each tier in email campaigns.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [40RTY-ai](https://github.com/40RTY-ai)
- **Source:** [40RTY-ai/shopify-admin-skills](https://github.com/40RTY-ai/shopify-admin-skills)
- **License:** MIT
- **Homepage:** http://skills.40rty.ai

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-40rty-ai-shopify-admin-skills-shopify-admin-customer-spend-tier-tagger
- Seller: https://agentstack.voostack.com/s/40rty-ai
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
