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

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