--- title: analyticsTargetCreate - GraphQL Admin description: >- Creates an [analytics target](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) that defines a merchant's goal for a specific metric over a date range. For example, a merchant can set a target of $50,000 in total sales for a quarter, or 1,000 orders in a month. Provide the target attributes through the `input` argument. The target's currency is set to the shop's currency. A target is uniquely identified by the combination of `metric`, `startDate`, `endDate`, and `filters` — attempting to create a duplicate returns a user error. Use [`analyticsTargetUpdate`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetUpdate) to modify an existing target, or [`analyticsTargetsDelete`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetsDelete) to remove targets. api_version: unstable api_name: admin source_url: html: >- https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetCreate md: >- https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetCreate.md metadata: domain: admin --- # analytics​Target​Create mutation Requires `write_reports` access scope. Creates an [analytics target](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) that defines a merchant's goal for a specific metric over a date range. For example, a merchant can set a target of $50,000 in total sales for a quarter, or 1,000 orders in a month. Provide the target attributes through the `input` argument. The target's currency is set to the shop's currency. A target is uniquely identified by the combination of `metric`, `startDate`, `endDate`, and `filters` — attempting to create a duplicate returns a user error. Use [`analyticsTargetUpdate`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetUpdate) to modify an existing target, or [`analyticsTargetsDelete`](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/analyticsTargetsDelete) to remove targets. ## Arguments * input [Analytics​Target​Create​Input!](https://shopify.dev/docs/api/admin-graphql/unstable/input-objects/AnalyticsTargetCreateInput) required The input fields for creating an [analytics target](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget). *** ## Analytics​Target​Create​Payload returns * analytics​Target [Analytics​Target](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget) The newly created [analytics target](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTarget). * user​Errors [\[Analytics​Target​Create​User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/AnalyticsTargetCreateUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Create a filtered orders target #### Description Create an analytics target that tracks order count for a specific channel by including a filter expression. #### Query ```graphql mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } } ``` #### Variables ```json { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } } ``` #### 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": "mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } }", "variables": { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = '\''Online Store'\''" } } }' ``` #### 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 mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } }`, { variables: { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } }, }, ); 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 mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } } QUERY variables = { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } }`, "variables": { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } }, }, }); ``` #### Shopify CLI ```bash shopify app execute \ --query \ 'mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } }' \ --variables \ '{ "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } }' ``` #### Direct API Access ```javascript const response = await fetch('shopify:admin/api/unstable/graphql.json', { method: 'POST', body: JSON.stringify({ query: ` mutation CreateFilteredTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric filters expectedValue startDate endDate } userErrors { field message } } } `, variables: { "input": { "metric": "orders", "startDate": "2027-08-01", "endDate": "2027-08-31", "expectedValue": "1000.00", "name": "August Online Orders Target", "filters": "sales_channel = 'Online Store'" } }, }), }); const { data } = await response.json(); console.log(data); ``` #### Response ```json { "analyticsTargetCreate": { "analyticsTarget": { "id": "gid://shopify/AnalyticsTarget/96223882", "name": "August Online Orders Target", "metric": "orders", "filters": "sales_channel = 'Online Store'", "expectedValue": "1000.0", "startDate": "2027-08-01", "endDate": "2027-08-31" }, "userErrors": [] } } ``` * ### Create a monthly sales target #### Description Create an analytics target to track progress toward a total sales goal for a one-month period. #### Query ```graphql mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } } ``` #### Variables ```json { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } } ``` #### 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": "mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } }", "variables": { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } } }' ``` #### 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 mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } }`, { variables: { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } }, }, ); 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 mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } } QUERY variables = { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } }`, "variables": { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } }, }, }); ``` #### Shopify CLI ```bash shopify app execute \ --query \ 'mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } }' \ --variables \ '{ "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } }' ``` #### Direct API Access ```javascript const response = await fetch('shopify:admin/api/unstable/graphql.json', { method: 'POST', body: JSON.stringify({ query: ` mutation CreateAnalyticsTarget($input: AnalyticsTargetCreateInput!) { analyticsTargetCreate(input: $input) { analyticsTarget { id name metric startDate endDate expectedValue } userErrors { field message } } } `, variables: { "input": { "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.00", "name": "July Sales Target" } }, }), }); const { data } = await response.json(); console.log(data); ``` #### Response ```json { "analyticsTargetCreate": { "analyticsTarget": { "id": "gid://shopify/AnalyticsTarget/96223883", "name": "July Sales Target", "metric": "total_sales", "startDate": "2027-07-01", "endDate": "2027-07-31", "expectedValue": "50000.0" }, "userErrors": [] } } ``` * ### analyticsTargetCreate reference