Skip to main content

Overview

The getAnalytics query provides comprehensive business intelligence data across multiple dimensions including sales performance, inventory levels, customer behavior, order status, and shipping metrics.

GraphQL Query

query GetAnalytics($timeframe: String) {
  getAnalytics(timeframe: $timeframe)
}
timeframe
String
Time period for analytics data. Options: “24h”, “7d”, “30d”, “90d”. Default: “7d”

Response Structure

Returns a comprehensive JSON object with analytics across multiple categories:

Sales Metrics

sales
object
Overall sales performance metrics
total
number
Total revenue including all fees
subtotal
number
Revenue from products only (excluding tax and shipping)
shipping
number
Total shipping charges
tax
number
Total tax collected
discount
number
Total discounts applied
refunds
number
Total amount refunded
count
number
Number of orders
averageOrderValue
number
Average order value (total / count)
timeline
array
Daily breakdown of sales metrics
date
string
Date in YYYY-MM-DD format
total
number
Total sales for the day
count
number
Number of orders for the day

Inventory Metrics

inventory
object
Product inventory and performance data
total
number
Total number of products
outOfStock
number
Number of products completely out of stock
lowStock
number
Number of products with low inventory (< 10 units)
totalValue
number
Total inventory value (quantity × price)
totalStock
number
Total units in stock across all products
topProducts
array
Top 10 products by revenue
id
string
Product unique identifier
title
string
Product name
quantity
number
Total units sold
revenue
number
Total revenue from product
orderCount
number
Number of orders containing this product
averageOrderValue
number
Average revenue per order

Customer Metrics

customers
object
Customer acquisition and behavior data
total
number
Total number of registered customers
new
number
New customers in selected timeframe
active
number
Customers who made purchases in timeframe
averageLifetimeValue
number
Average customer lifetime value
timeline
array
Daily customer acquisition
date
string
Date in YYYY-MM-DD format
newUsers
number
New customers on this date

Order Metrics

orders
object
Order status and processing data
total
number
Total number of orders
byStatus
object
Order count by status (pending, processing, completed, canceled, etc.)
byFulfillmentStatus
object
Order count by fulfillment status (unfulfilled, fulfilled, etc.)
byPaymentStatus
object
Order count by payment status (pending, captured, refunded, etc.)
timeline
array
Daily order metrics (same structure as sales.timeline)

Shipping Metrics

shipping
object
Shipping performance and provider data
total
number
Total shipping revenue
methods
array
Breakdown by shipping method, sorted by usage
provider
string
Fulfillment provider ID
name
string
Shipping method name
count
number
Number of times used
total
number
Total revenue from this method

Example Query

query {
  getAnalytics(timeframe: "30d")
}

Example Response

{
  "data": {
    "getAnalytics": {
      "sales": {
        "total": 125000,
        "subtotal": 110000,
        "shipping": 5000,
        "tax": 10000,
        "discount": 2000,
        "refunds": 1500,
        "count": 250,
        "averageOrderValue": 500,
        "timeline": [
          {
            "date": "2024-02-01",
            "total": 5000,
            "subtotal": 4400,
            "shipping": 200,
            "tax": 400,
            "discount": 100,
            "refunds": 50,
            "count": 10
          }
        ]
      },
      "inventory": {
        "total": 500,
        "outOfStock": 15,
        "lowStock": 45,
        "totalValue": 250000,
        "totalStock": 5000,
        "topProducts": [
          {
            "id": "product_123",
            "title": "Premium Widget",
            "quantity": 150,
            "revenue": 15000,
            "orderCount": 75,
            "averageOrderValue": 200
          }
        ]
      },
      "customers": {
        "total": 1200,
        "new": 85,
        "active": 300,
        "averageLifetimeValue": 750,
        "timeline": [
          {
            "date": "2024-02-01",
            "newUsers": 5
          }
        ]
      },
      "orders": {
        "total": 250,
        "byStatus": {
          "pending": 20,
          "processing": 50,
          "completed": 175,
          "canceled": 5
        },
        "byFulfillmentStatus": {
          "unfulfilled": 30,
          "fulfilled": 220
        },
        "byPaymentStatus": {
          "pending": 10,
          "captured": 235,
          "refunded": 5
        }
      },
      "shipping": {
        "total": 5000,
        "methods": [
          {
            "provider": "shippo_123",
            "name": "Standard Shipping",
            "count": 180,
            "total": 3600
          },
          {
            "provider": "shippo_123",
            "name": "Express Shipping",
            "count": 70,
            "total": 1400
          }
        ]
      }
    }
  }
}

Use Cases

Dashboard Overview

Retrieve key metrics for a business dashboard:
query DashboardMetrics {
  getAnalytics(timeframe: "7d")
}

Monthly Report

Generate a comprehensive monthly business report:
query MonthlyReport {
  getAnalytics(timeframe: "30d")
}

Real-time Monitoring

Monitor today’s performance:
query TodayPerformance {
  getAnalytics(timeframe: "24h")
}

Data Source

The analytics query aggregates data from:
  • Orders: Status, totals, line items, dates
  • Products: Inventory, pricing, variants
  • Users: Registration dates, order history
  • Payments: Payment status and amounts
  • Returns: Refund amounts
  • Shipping Methods: Provider usage and costs

Performance Considerations

  • Analytics queries can be resource-intensive for large datasets
  • Use appropriate timeframes to limit data volume
  • Consider caching analytics results for frequently accessed data
  • Longer timeframes (90d) may require additional processing time

Additional Analytics Queries

For more granular analytics, use the GraphQL queries in the platform’s analytics module:
# Sales overview with detailed line items
query GetSalesOverview($startDate: DateTime!, $endDate: DateTime!) {
  orders(
    where: {
      createdAt: { gte: $startDate, lte: $endDate }
      status: { notIn: [canceled] }
    }
  ) {
    id
    displayId
    total
    lineItems {
      quantity
      formattedTotal
      productVariant {
        product {
          title
        }
      }
    }
  }
}

# Top performing products
query GetProductPerformance($startDate: DateTime!, $endDate: DateTime!) {
  orderLineItems(
    where: {
      order: {
        createdAt: { gte: $startDate, lte: $endDate }
        status: { notIn: [canceled] }
      }
    }
  ) {
    quantity
    formattedTotal
    productVariant {
      product {
        title
      }
    }
  }
}

Build docs developers (and LLMs) love