Creating custom metrics
Creating a LayersQL metric
- Go to Metrics in your Layers dashboard
- Click Create Metric
- Select LayersQL as the metric type
- Write your LayersQL query following the syntax:
FROM → SHOW → GROUP BY → SINCE - Optionally add
WHEREclauses for filtering orSEGMENT BYfor dimensional breakdowns - Name your metric and save
Creating an imported metric
- Go to Metrics in your Layers dashboard
- Click Create Metric
- Select Imported (ShopifyQL) as the metric type
- Write your ShopifyQL query ensuring it includes
product_id - Set the refresh frequency (hourly, daily, or weekly)
- Name your metric and save
Metric refresh and updates
LayersQL metrics update in real-time as behavioral data flows through the Layers analytics pipeline. There is no manual refresh required. Imported metrics refresh automatically based on their configured schedule:- Hourly: Updated every hour for time-sensitive metrics
- Daily: Updated once per day, ideal for most sales metrics
- Weekly: Updated weekly for slower-moving or historical metrics
Best practices
Choosing between metric types
Use LayersQL metrics when:- You need real-time behavioral data from search and browse interactions
- Segmentation by marketing channel or geography is important
- The metric is based on user engagement (views, clicks, searches)
- You need Shopify’s authoritative sales and financial data
- Return rates, refunds, or detailed order information is required
- Daily or periodic updates are sufficient
Query optimization
- Keep time windows reasonable (7-30 days) to balance freshness with data volume
- Use
WHEREclauses to pre-filter data before aggregation - For Imported metrics, avoid queries that return excessive rows
- Test queries on a subset of data before deploying to production
Naming conventions
- Include the time window in the metric name (e.g., “Sales 7d”, “Returns 30d”)
- Use clear, descriptive names that indicate the metric’s purpose
- Distinguish between LayersQL and Imported metrics in naming when helpful
Visualization
LayersQL metrics include built-in charting so you can visualize trends and distributions directly in the dashboard. When creating or editing a metric, you can choose a chart type and configure how data is displayed.Chart types
| Chart type | Best for |
|---|---|
| Table | Browsing raw metric values with sorting and filtering |
| Card | Displaying a single aggregate value with period-over-period change |
| Bar | Comparing values across categories (e.g., sales by country) |
| Horizontal bar | Category comparisons when labels are long |
| Stacked bar | Showing composition across categories |
| Line | Tracking trends over time |
| Area | Trend visualization with emphasis on volume |
| Donut | Showing proportional breakdowns |
Prior period comparison
Metrics automatically calculate a prior period comparison based on your selected date range. For example, a metric usingSINCE -7d compares the current 7-day window against the previous 7 days. The comparison appears as a percentage change indicator, helping you spot trends without creating separate metrics.
Prior period comparison is available for all LayersQL metrics and displays alongside your primary metric value. It is most useful with the Card chart type for at-a-glance trend monitoring.
Loading metric data for sort orders
Before a LayersQL metric can be used in a sort order, its computed results need to be loaded into the platform’s sorting engine. This step makes the metric values available for real-time product ranking.How to load metric data
- Go to Metrics in your Layers dashboard
- Open the metric you want to use in sort orders
- Click Load Data
- A progress indicator shows the loading status in real time
Only LayersQL metrics support data loading for sort orders. Imported (ShopifyQL) metrics are available for display and analysis but cannot be loaded into the sorting engine directly.
Where metrics show up
- Search Ranking: Product metrics like views, sales, and cart sessions power the engagement signal group in ranking relevancy, directly influencing how products are scored in search results
- Sort Orders: Add metric-based conditions and weights to control product ranking
- Merchandising Rules: View per-product metric values directly on product cards while you pin, boost, or group products. Configure which metrics appear through Customize UI in the merchandising toolbar. See Metrics in merchandising rules for eligibility requirements and configuration details.
- Analytics Dashboard: Track metric trends over time with built-in charts and prior period comparisons
- Product Details: View individual product metric values for manual merchandising
Learn more
- Metrics Overview - Metric types, segmented metrics, and use cases
- Metric Recipes - Pre-configured metric templates
- LayersQL overview
- LayersQL syntax
- LayersQL functions
- LayersQL datasets
- Sort Orders
- Merchandising