--- title: analyticsTargets - GraphQL Admin description: >- Returns a paginated list of [analytics targets](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) for the shop. Each target represents a merchant-defined goal for a specific metric over a date range. Results can be filtered by metric, name, date range, or filter expression, and sorted by fields such as `start_date`, `expected_value`, or `metric`. Use the [`analyticsTargetCreate`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetCreate) mutation to add new targets. api_version: unstable api_name: admin source_url: html: 'https://shopify.dev/docs/api/admin-graphql/unstable/queries/analyticsTargets' md: >- https://shopify.dev/docs/api/admin-graphql/unstable/queries/analyticsTargets.md --- # analytics​Targets query Requires `read_reports` access scope. Returns a paginated list of [analytics targets](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) for the shop. Each target represents a merchant-defined goal for a specific metric over a date range. Results can be filtered by metric, name, date range, or filter expression, and sorted by fields such as `start_date`, `expected_value`, or `metric`. Use the [`analyticsTargetCreate`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetCreate) mutation to add new targets. ## AnalyticsTargetConnection arguments [AnalyticsTargetConnection!](https://shopify.dev/docs/api/admin-graphql/unstable/connections/AnalyticsTargetConnection) * after [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) The elements that come after the specified [cursor](https://shopify.dev/api/usage/pagination-graphql). * before [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) The elements that come before the specified [cursor](https://shopify.dev/api/usage/pagination-graphql). * first [Int](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Int) The first `n` elements from the [paginated list](https://shopify.dev/api/usage/pagination-graphql). * last [Int](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Int) The last `n` elements from the [paginated list](https://shopify.dev/api/usage/pagination-graphql). * query [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) A filter made up of terms, connectives, modifiers, and comparators. You can apply one or more filters to a query. Learn more about [Shopify API search syntax](https://shopify.dev/api/usage/search-syntax). * * default string * end\_date date * filters string * id id * metric string * name string * start\_date date - Filter by a case-insensitive search of multiple fields in a document. - Example: * `query=Bob Norman` * `query=title:green hoodie` Filter by the end date of the target period. - Example: * `end_date:2026-03-31` * `end_date:<=2026-03-31` Filter by the WHERE clause filters of the target. - Example: * `filters:"WHERE country = 'US'"` Filter by `id` range. - Example: * `id:1234` * `id:>=1234` * `id:<=1234` Filter by metric identifier. - Example: * `metric:total_sales` Filter by target name. - Example: * `name:Q1 Sales Target` Filter by the start date of the target period. Example: * `start_date:2026-01-01` * `start_date:>=2026-01-01` * reverse [Boolean](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Boolean) Default:false Reverse the order of the underlying list. * sort​Key [Analytics​Target​Sort​Keys](https://shopify.dev/docs/api/admin-graphql/unstable/enums/AnalyticsTargetSortKeys) Default:ID Sort the underlying list using a key. If your query is slow or returns an error, then [try specifying a sort key that matches the field used in the search](https://shopify.dev/api/usage/pagination-graphql#search-performance-considerations). *** ## Possible returns * edges [\[Analytics​Target​Edge!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTargetEdge) non-null The connection between the node and its parent. Each edge contains a minimum of the edge's cursor and the node. * nodes [\[Analytics​Target!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) non-null A list of nodes that are contained in AnalyticsTargetEdge. You can fetch data about an individual node, or you can follow the edges to fetch data about a collection of related nodes. At each node, you specify the fields that you want to retrieve. * page​Info [Page​Info!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/PageInfo) non-null An object that’s used to retrieve [cursor information](https://shopify.dev/api/usage/pagination-graphql) about the current page. *** ## Examples * ### Filter analytics targets by metric #### Description Retrieve analytics targets that track a specific metric using the \`query\` filter. #### Query ```graphql query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { analyticsTargets(first: 10, query: \"metric:total_sales\") { nodes { id name metric startDate endDate expectedValue } } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } }`, }); ``` #### Shopify CLI ```bash shopify app execute \ --query \ 'query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } }' ``` #### Direct API Access ```javascript const response = await fetch('shopify:admin/api/unstable/graphql.json', { method: 'POST', body: JSON.stringify({ query: ` query { analyticsTargets(first: 10, query: "metric:total_sales") { nodes { id name metric startDate endDate expectedValue } } } `, }), }); const { data } = await response.json(); console.log(data); ``` #### Response ```json { "analyticsTargets": { "nodes": [ { "id": "gid://shopify/AnalyticsTarget/96223881", "name": "Q1 Sales Target", "metric": "total_sales", "startDate": "2026-01-01", "endDate": "2026-03-31", "expectedValue": "1000.0" }, { "id": "gid://shopify/AnalyticsTarget/96223936", "name": "January Sales Target", "metric": "total_sales", "startDate": "2025-01-01", "endDate": "2025-01-31", "expectedValue": "5000.0" } ] } } ``` * ### Query analytics targets for the shop #### Description Retrieve the first 10 analytics targets for the shop, sorted by start date, with the expected value converted to a presentment currency. #### Query ```graphql query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } }`, }); ``` #### Shopify CLI ```bash shopify app execute \ --query \ 'query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } }' ``` #### Direct API Access ```javascript const response = await fetch('shopify:admin/api/unstable/graphql.json', { method: 'POST', body: JSON.stringify({ query: ` query { analyticsTargets(first: 10, sortKey: START_DATE) { nodes { id name metric startDate endDate expectedValue currencyCode presentmentExpectedValue(currencyCode: CAD) { amount currencyCode } } } } `, }), }); const { data } = await response.json(); console.log(data); ``` #### Response ```json { "analyticsTargets": { "nodes": [ { "id": "gid://shopify/AnalyticsTarget/96223938", "name": "January Sales Target", "metric": "total_sales", "startDate": "2025-01-01", "endDate": "2025-01-31", "expectedValue": "5000.0", "currencyCode": "USD", "presentmentExpectedValue": { "amount": "6756.76", "currencyCode": "CAD" } }, { "id": "gid://shopify/AnalyticsTarget/96223881", "name": "Q1 Sales Target", "metric": "total_sales", "startDate": "2026-01-01", "endDate": "2026-03-31", "expectedValue": "1000.0", "currencyCode": "USD", "presentmentExpectedValue": { "amount": "1351.35", "currencyCode": "CAD" } }, { "id": "gid://shopify/AnalyticsTarget/96223939", "name": "Weekly Orders Target", "metric": "orders", "startDate": "2027-06-01", "endDate": "2027-06-07", "expectedValue": "100.0", "currencyCode": "CAD", "presentmentExpectedValue": null } ] } } ```