Get analytics data

The Get analytics data action runs a ShopifyQL query and returns the results for use in your workflow. ShopifyQL is a query language built for commerce analytics. You can use it to aggregate metrics across time periods, apply filters, and group by dimensions such as product, collection, or customer. The data returned by this action is available to conditions and actions that follow the step.

Triggers

The Get analytics data action is only compatible with the Scheduled time trigger. Analytics data isn't included by event-based triggers.

Configuration

Fields

The Get analytics data action contains the following field:

Fields used in the Get analytics data action.
FieldDescription
ShopifyQL QueryRequired. The ShopifyQL query to run against your store's analytics data.

ShopifyQL query

You can write any valid ShopifyQL query using supported schemas, such as sales, sessions, inventory, and payments. For example, the following query returns total sales and the number of customers for the day that the workflow runs:

FROM sales
  SHOW total_sales, customers
  SINCE today

For the full language reference, including supported schemas, functions, and syntax, refer to the ShopifyQL documentation.

The query is validated when you save the workflow. The workflow can't be activated until the query runs successfully against your store.

Returned data

The Get analytics data action returns the rows that match your query, available as a variable named getAnalyticsData. The rows are stored in getAnalyticsData.rows, where each row is an object keyed by the column names in your query.

You can use this variable in both conditions and actions that follow the step. For example, to send an internal email that lists each row, you can use Liquid similar to this:

{% for row in getAnalyticsData.rows %}
* {{ row.total_sales }} in sales from {{ row.customers }} customers
{% endfor %}

To work with each row individually, such as to apply an action for each row, you can use the For each loop (iterate) action with getAnalyticsData.rows. To aggregate values, such as count rows or sum a column, you can use the Count and Sum actions.

API reference

For more information about the API used in this action, refer to the shopifyqlQuery query in the GraphQL Admin API.

Query complexity

Each ShopifyQL query has a complexity cost that's calculated from the schemas, columns, filters, and time range that the query uses. If a query exceeds the complexity limit, then the action fails and the workflow can't be activated. To reduce the cost of a query, you can shorten the time range, remove columns, or remove joins.

For details on how query cost is calculated and the current limits, refer to Rate limiting in the ShopifyQL Admin API.