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
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: Preview live metrics as you pin, boost, or group products
- Analytics Dashboard: Track metric trends over time for performance monitoring
- 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