Skip to main content

Creating custom metrics

Creating a LayersQL metric

  1. Go to Metrics in your Layers dashboard
  2. Click Create Metric
  3. Select LayersQL as the metric type
  4. Write your LayersQL query following the syntax: FROM → SHOW → GROUP BY → SINCE
  5. Optionally add WHERE clauses for filtering or SEGMENT BY for dimensional breakdowns
  6. Name your metric and save

Creating an imported metric

  1. Go to Metrics in your Layers dashboard
  2. Click Create Metric
  3. Select Imported (ShopifyQL) as the metric type
  4. Write your ShopifyQL query ensuring it includes product_id
  5. Set the refresh frequency (hourly, daily, or weekly)
  6. Name your metric and save
The system will automatically execute the ShopifyQL query against your Shopify store and refresh the data according to your specified frequency.

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
You can manually trigger a refresh for any Imported metric from the metric details page in your dashboard.

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)
Use Imported metrics when:
  • 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 WHERE clauses 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 typeBest for
TableBrowsing raw metric values with sorting and filtering
CardDisplaying a single aggregate value with period-over-period change
BarComparing values across categories (e.g., sales by country)
Horizontal barCategory comparisons when labels are long
Stacked barShowing composition across categories
LineTracking trends over time
AreaTrend visualization with emphasis on volume
DonutShowing proportional breakdowns

Prior period comparison

Metrics automatically calculate a prior period comparison based on your selected date range. For example, a metric using SINCE -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

  1. Go to Metrics in your Layers dashboard
  2. Open the metric you want to use in sort orders
  3. Click Load Data
  4. A progress indicator shows the loading status in real time
Once loaded, the metric appears as an available option when configuring sort order expressions. You can re-load data at any time to refresh the values used for sorting.
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