Skip to main content

Using segmented metrics in sort orders

Segmented metrics personalize rankings by visitor context (location, channel, device). For per-shopper personalization based on individual behavior, User Affinity is the cart/purchase-based counterpart — it lifts products matching a shopper’s learned tastes on collection/browse pages.
Segmented metrics enable automatic personalization of product rankings based on each visitor’s context. When you include a segmented metric in a sort order, the system intelligently selects the most relevant metric value for each visitor without requiring separate sort orders for different audiences.

How it works

When you add a segmented metric to a sort order, the system automatically uses the visitor’s context to select the appropriate metric value. For a visitor from the United States, the system uses US-specific performance data when available. For a visitor from Canada, it uses Canadian data. If segment-specific data isn’t available, the system falls back to the overall value, ensuring all visitors see ranked results. This happens transparently at query time. You configure the segmentation once in your metric and sort order, and the system handles all the complexity of matching visitor context to the right data.

Smoothing factor

The smoothing factor controls how segment-specific and global performance data are blended when ranking products. This parameter helps balance the responsiveness of segment-specific rankings with the stability of global trends. How it works: When a segmented metric is used in a sort order, the system calculates a weighted blend of segment-specific data and global data for each product:
final_score = (segment_value × segment_weight) + (global_value × global_weight)
The smoothing factor (default: 50) determines these weights. Lower values prioritize segment-specific performance, making rankings more responsive to local trends. Higher values blend in more global data, providing stability when segment data is sparse or noisy. Choosing a value:
  • 1-50 (Segment-focused): Use when you have sufficient data in each segment and want rankings to closely reflect segment-specific performance. Best for high-traffic stores with established regional patterns.
  • 50-100 (Balanced): The default range balances segment-specific insights with global trends. Suitable for most use cases where you want personalization without excessive volatility.
  • 100-200 (Global-focused): Use when segment data is sparse or when you want rankings to remain stable across segments. Best for new stores, low-traffic segments, or when testing segmentation.
Example scenarios:
  • Geographic segmentation with high traffic: Set smoothing factor to 25-50 to prioritize country-specific performance data
  • Marketing channel segmentation with limited data: Set smoothing factor to 100-150 to blend channel-specific trends with overall performance
  • New segment with minimal data: Set smoothing factor to 150-200 to rely primarily on global performance until segment data accumulates
You can configure the smoothing factor when adding a segmented metric to a sort order. The system applies this blending automatically at query time for each visitor.

Benefits

Segmented metrics in sort orders deliver more relevant product rankings to different audiences:
  • Geographic relevance: Products that perform well in a visitor’s country or region rank higher for that visitor
  • Channel optimization: Visitors from paid ads see rankings optimized for paid traffic, while organic visitors see organic-optimized rankings
  • Automatic adaptation: Rankings adjust to each visitor without manual intervention or duplicate sort orders

Works with other features

Segmented metrics integrate seamlessly with other sort order capabilities:
  • Weighted sorting: Combine multiple segmented metrics with different weights to create sophisticated ranking algorithms
  • Conditional rules: Apply segmented metrics only when specific conditions are met
  • Priority rules: Use segmented metrics alongside boost and demote logic for fine-tuned control

Learn more

Conditional sort expressions

Conditional sort expressions let you apply sorting rules only when specific contextual conditions are met. Instead of creating separate sort orders for different audiences, you attach conditions directly to individual sort expressions so they activate dynamically based on visitor context.

How it works

Each sort expression in a sort order can include a conditions object. When conditions are present, the expression is only applied if the visitor’s contextual data matches. If conditions are not met, the expression is skipped and the next expression in the list takes effect. Conditions use a combinator (and / or) with one or more rules that evaluate against contextual data fields such as geographic location, marketing channel, or customer segment.

When to use conditional expressions

  • Regional sorting: Sort by price ascending for one country and by popularity for another, all within a single sort order
  • Channel-specific ranking: Apply different sorting logic for visitors arriving from paid ads vs. organic traffic
  • Seasonal targeting: Activate promotional sorting expressions only for visitors in specific regions during local events

How conditions are evaluated

Conditions follow a combinator + rules structure:
  • combinator: and (all rules must match) or or (any rule must match)
  • rules: Each rule specifies a field, operator, and value
Available fields correspond to the contextual data passed with each request. See Contextual information for the full list of supported fields. Common condition fields:
FieldDescriptionExample values
geo.countryVisitor’s country codeUS, CA, GB
geo.provinceVisitor’s province or stateCalifornia, Ontario
geo.cityVisitor’s cityLos Angeles, Toronto
When you pick values for geo.country or geo.province in the dashboard, Layers shows the full country or state name next to the ISO code (for example, United States of America (US) or California (CA)). You can search by either the code or the name, so both united and US match the same option. Conditions still evaluate against the ISO code, so rules and contextual payloads stay unchanged.
Supported operators:
OperatorDescription
eqEquals
neqNot equals
inMatches any value in a list
notInDoes not match any value in a list

Example: geographic-based sorting

A single sort order can apply different sorting strategies based on visitor location:
Expression 1: Sort by price descending
  Condition: geo.country equals "US"

Expression 2: Sort by price ascending
  Condition: geo.country equals "CA"

Expression 3: Sort by title ascending
  (No condition — always applies as fallback)
Result:
  • Visitors from the US see products sorted by price, highest first
  • Visitors from Canada see products sorted by price, lowest first
  • Visitors from all other countries see products sorted alphabetically

Fallback behavior

When a conditional expression does not match, it is skipped entirely. Always include at least one unconditional expression at the end of your sort order to ensure all visitors receive sorted results. Without a fallback, visitors who don’t match any condition see default ordering.

Works with other features

Conditional expressions combine with all other sort order capabilities:
  • Priority rules: Attach conditions to priority rules to promote or demote products only for specific audiences
  • Soft boost: Apply conditional soft boosts that activate based on visitor context
  • Segmented metrics: Use conditional expressions alongside segmented metrics for layered personalization
  • Sequences: Conditional expressions respect product sequences when enabled

Best practices

  • Always include a fallback: End your sort order with an unconditional expression so every visitor sees sorted results
  • Keep conditions simple: Use one or two rules per condition to maintain readability and predictability
  • Test with preview: Use the sort order preview with different contextual data to verify each condition produces the expected results
  • Avoid overlapping conditions: When using multiple conditional expressions, ensure the conditions are mutually exclusive or ordered by priority to avoid unexpected results

Per-product “Only when” conditions Beta

While contextual conditions gate a sort expression by visitor context, an Only when condition gates the expression by per-product data — a product’s own metric value or attribute. Products that don’t match still appear in results; they just fall through to the next expression for ranking. Use “Only when” on a metric or attribute row to say things like “rank by conversion rate — but only for products with enough orders to trust the number.” Products that don’t meet the threshold fall through to the next sort expression instead of being ranked by a noisy metric.

When to use it

  • Confidence thresholds: Rank by conversion rate or return rate only for products with enough traffic or orders for the number to be meaningful.
  • New-product handling: Rank recently published products by newness, then let established products rank by sales.
  • Tiered ranking: Stack multiple gated expressions to build implicit confidence tiers — high-signal products first, everyone else by a stable fallback.

How it works

Every metric and attribute row in the sort order editor has an Only when affordance. Click it to attach a per-product condition:
  • Field — a product attribute (from the attribute picker) or a sortable metric.
  • Operator — standard comparison operators for the field type (equals, greater than, in, is not null, and so on).
  • Value — the threshold or match value.
Products that satisfy the condition are ranked by the expression as normal. Products that fail the condition are treated as if they had no value for that expression — they tie at the bottom of that ordering step and fall through to the next sort expression in the list for ranking. This means the ordering of expressions matters. Put the most trusted, condition-gated expression first, then a broader fallback below it.

Example: rank by conversion rate, only when trustworthy

Rank products by conversion rate — but only for products that have enough orders for the number to be reliable. Everything else falls back to revenue.
1. Metric: Conversion rate (descending)
   Only when: orders_count >= 20
2. Metric: Revenue (descending)
Result:
  • Products with 20 or more orders rank by conversion rate at the top.
  • Products with fewer than 20 orders fall through and rank by revenue among themselves, mixed in below the confident cohort.

Example: newness for new arrivals, sales for the rest

Give recently published products a chance to rank on freshness, and let the rest of the catalog rank by sales.
1. Metric: Published date (descending)
   Only when: published_at is in the last 30 days
2. Metric: Sales (7d) - descending
Result:
  • Products published in the last 30 days appear first, ordered newest first.
  • Everything else ranks by 7-day sales after that cohort.

”Only when” vs. contextual conditions vs. priority rules

FeatureGated byEffect on non-matching products
Only when (per-product)A product’s own attributes or metric valuesSkipped for this expression; ranked by the next expression
Contextual conditionsVisitor context (geo, channel, device)The whole expression is skipped for the request
Priority rulesA product conditionPromoted to top or demoted to bottom of results
Use Only when when you want products that don’t match to still appear, just ranked by a different signal. Use priority rules when you want matching products clustered at the top or bottom regardless of other sorting.

Compatibility

  • Available on metric and attribute sort expressions.
  • Not available on priority rules (use the rule’s own condition), soft boost matched-cohort conditions (use the boost’s condition), or product family diversity.
  • Compatible with segmented metrics, contextual conditions, sequences, and soft boost. An expression can carry both a contextual condition and an “Only when” condition — both must be satisfied for the expression to apply.

Best practices

  • Order matters: Put the gated expression above its fallback. Products that fail the gate fall through to the next expression, so there must be a next one.
  • Always end with an unconditional expression: A metric or attribute with no “Only when” gate at the bottom of the list guarantees every product gets ranked.
  • Preview after changes: Use the sort order preview to confirm that gated products land where you expect and unmatched products fall through cleanly.
  • Keep thresholds meaningful: Set the condition value where the underlying signal actually becomes trustworthy (for example, at the order count where your conversion-rate estimate stabilizes).

See also