Skip to main content
Version: 2.0.0

Customer Segments

Navigate to yStore → Customers → Segments.

Segments group customers for reporting, storefront personalisation, and Flow Manager automations — separate from customer groups, which drive pricing (see Customers → Customer groups). A customer can belong to any number of segments regardless of their group.

Segments vs. customer groups

Use a customer group when you need group-specific pricing (wholesale vs. retail). Use a segment when you need to identify or target a set of customers by behaviour or attributes — e.g. "VIP customers", "inactive 90+ days" — without affecting what they pay.


Segment types

TypeHow membership works
StaticCustomers are added or removed manually, or via the Flow Manager's Add to segment / Remove from segment actions. Membership does not change on its own.
DynamicMembership is computed from a rule (a native Craft customer condition — the same condition builder used elsewhere in the CP). yStore evaluates the rule and updates membership automatically.

Dynamic evaluation modes

When creating a dynamic segment, choose how it re-evaluates:

ModeBehaviour
EventRe-evaluated for a customer whenever that customer is saved (e.g. after checkout, profile update).
CronRe-evaluated for all customers on a fixed interval, driven by the console command below.
BothCombines event-based and cron-based evaluation.

The evaluation interval (in hours, 1–8760) controls how often the cron sweep re-checks a cron/both-mode segment.


Managing segments

From Customers → Segments:

  1. Click New Segment.
  2. Set a name — the handle is generated automatically (editable, snake_case).
  3. Choose Static or Dynamic.
  4. For dynamic segments, build the condition using the customer condition rule builder and pick an evaluation mode/interval.
  5. Save.

From the segment's edit screen you can also:

  • Evaluate now — re-run the segment's rule immediately (dynamic segments) instead of waiting for the next event or cron sweep.
  • Add / remove members — for static segments, or to manually override a dynamic segment's computed membership.
  • View the current member count, kept on the segment record and refreshed on each evaluation.

Export

The Segments list can be exported from the list toolbar in three formats:

  • CSV
  • JSON
  • XLSX (Excel)

Each export row includes ID, name, handle, type, member count, enabled state, description, evaluation mode/interval, and last-evaluated timestamp.


Automation with the Flow Manager

Segments integrate with the Flow Manager as a trigger, two actions, and a branching condition:

NodeKindWhat it does
Customer enters segmentTriggerStarts a flow when a customer enters or exits a dynamic segment (configurable: entered / exited / both), identified by segment handle. Supports a re-entry cooldown in hours to avoid re-firing the same flow repeatedly for one customer.
Add to segmentActionAdds the customer in context to a segment (typically a static one).
Remove from segmentActionRemoves the customer in context from a segment.
Customer in segmentConditionBranches the flow depending on whether the customer currently belongs to the specified segment — useful for VIP routing or personalised paths inside a larger flow.

Typical uses: welcome a newly-tagged VIP segment with a drip campaign, notify an account manager when a shopper enters a high-value segment, or branch an existing flow so segment members get different messaging.


Developer / integrator

Console command

Dynamic segments in Cron or Both mode are re-evaluated by a queue job that must be triggered on a schedule:

# Queues evaluation of all dynamic segments whose cron interval has elapsed
php craft yui/segments/evaluate-dynamic

Add this to your server crontab (e.g. every minute — the command only queues work for segments whose interval has actually elapsed):

* * * * * php /path/to/craft yui/segments/evaluate-dynamic >> /dev/null 2>&1

GraphQL

query {
allSegments {
id
handle
name
type
}
customerSegments {
id
handle
name
}
}
  • allSegments returns every segment, including disabled ones.
  • customerSegments returns the segments the logged-in customer belongs to (or a given customerId, restricted to the authenticated customer unless the query is run with elevated access).

Storefront REST endpoint

GET /shop/customer/segments

Requires an authenticated customer session. Returns the current customer's segment memberships as JSON:

{ "segments": [{ "id": 12, "name": "VIP customers", "handle": "vip_customers", "type": "dynamic" }] }

Use this to drive storefront personalisation (banners, offers) without exposing GraphQL.

PHP service API

Plugin::getInstance()->getCustomerSegments() exposes the segment service, notably:

  • getAllSegments() / getSegmentsForCustomer(int $customerId)
  • addCustomer(int $segmentId, int $customerId, string $source = 'manual') / removeCustomer(int $segmentId, int $customerId)
  • evaluateSegment(int $segmentId) — re-runs a dynamic segment's rule
  • evaluateCustomerForEventSegments(int $customerId) — called on customer save for event/both-mode segments

A SegmentMembershipChangedEvent (CustomerSegmentService::EVENT_AFTER_SEGMENT_MEMBERSHIP_CHANGED) fires whenever a customer enters or exits a segment, exposing segmentId, segmentHandle, customerId, and action ('entered' or 'exited') — use this to sync membership changes to an external CRM or loyalty system.

Extending with custom condition types

The plugin repository ships a docs/segments-extending.md file describing a EVENT_REGISTER_SEGMENT_TYPES hook and a custom JSON condition schema for registering third-party segment condition types. That event does not exist in the shipped CustomerSegmentService as of v2.5.0 — dynamic segment rules are evaluated exclusively through Craft's native customer condition system (conditionRules). Do not build against the extending guide until it has been corrected against the implementation; use EVENT_AFTER_SEGMENT_MEMBERSHIP_CHANGED for integrations in the meantime.