Querying Analytics & Reports

Topic summary

A developer is building a Shopify app to pull analytics and reports data using GraphQL’s shopifyqlQuery. Their query returns empty rowData and unformattedData arrays, though the column structure appears correct.

Current Issue:

  • The developer suspects their test dev store lacks analytics data, though sample reports exist
  • They’re receiving valid JSON responses with proper cost/throttle information but no actual data

Developer’s Goals:

  • Pull comprehensive merchant analytics/reports data (not just specific fields)
  • Capture traffic sessions, checkout conversions, and orders
  • Send this data to OpenAI API for cross-analysis

Discussion Progress:

  • A community member confirmed the query might be correct but there’s simply no valid data to retrieve from the test store
  • The developer has since pivoted to trying different data sources (orders, abandoned carts) but encountered a TypeError with the REST client in Remix
  • They’ve created a separate post in the proper forum category for the new REST client issue

Status: The original analytics query issue appears unresolved; the developer is exploring alternative approaches and seeking guidance on best practices for comprehensive data retrieval.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

Hello! I am building a shopify app that can pull a connected store’s analytics and reports data. I have set up the request and fetch functions with my remix app.

Currently, I am getting this response in my app frontend when I preview in my browser from the query:

{
  "data": {
    "shopifyqlQuery": {
      "tableData": {
        "unformattedData": [],
        "rowData": [],
        "columns": [
          {
            "name": "month",
            "dataType": "month",
            "displayName": "Month"
          },
          {
            "name": "monthly_net_sales",
            "dataType": "price",
            "displayName": "Monthly net sales"
          }
        ]
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 3,
      "actualQueryCost": 3,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 997,
        "restoreRate": 50
      }
    }
  }
}

I believe I am getting this response because my test dev store does not have any dummy analytics, but there are sample reports with information.

Here is a snippet of my code in my app_index.jsx:

export const loader = async ({ request }) => {
  const { admin } = await authenticate.admin(request);
  const reportsData = await fetchShopifyReports(admin);
  return json({ reports: reportsData });
};

export const action = async ({ request }) => {
  const { admin } = await authenticate.admin(request);
  const color = ["Red", "Orange", "Yellow", "Green"][
    Math.floor(Math.random() * 4)
  ];
  const response = await admin.graphql(
    `#graphql
      mutation populateProduct($input: ProductInput!) {
        productCreate(input: $input) {
          product {
            id
            title
            handle
            status
            variants(first: 10) {
              edges {
                node {
                  id
                  price
                  barcode
                  createdAt
                }
              }
            }
          }
        }
      }`,
    {
      variables: {
        input: {
          title: `${color} Snowboard`,
          variants: [{ price: Math.random() * 100 }],
        },
      },
    }
  );
  const responseJson = await response.json();

  return json({
    product: responseJson.data.productCreate.product,
  });
};

export default function Index() {
  const nav = useNavigation();
  const actionData = useActionData();
  const { reports } = useLoaderData(); // Retrieve reports from loader
  const submit = useSubmit();
  const isLoading =
    ["loading", "submitting"].includes(nav.state) && nav.formMethod === "POST";
  const productId = actionData?.product?.id.replace(
    "gid://shopify/Product/",
    ""
  );

My question is how can I properly query to pull all data from analytics holistically, and properly display that information on the frontend.

Note: i am a novice engineer! Learning as I build, any guidance and constructive advice for next steps is greatly appreciated. Also happy to provide more code for context if needed.

Thanks! :grin:

Hi Mike,

Just to confirm - are you expecting to see some traffic data being returned in the first code snippet, but there’s missing data?

Hi Liam, yes correct! This was my attempt to just get the API communication working, but wondering if there is a better method than what I’m doing to pull a merchant’s total analytics/report data, rather than specified fields. Any clarification on how this can work better with what I’m attempting would be super helpful :slightly_smiling_face:

Edit: For more clarification, if it is easier to capture orders, traffic sessions, and checkout conversion outside of the reports query – that would also work too. My goal is to get this data and send to the openAI API for cross-analysis.

When you say “my test dev store does not have any dummy analytics, but there are sample reports with information” - how are these sample reports set up? It’s possible the query is correct and there’s simply no valid data to receive?

Hey! This seems to be the case, and since then I have tried pulling different data such as orders and abandoned carts, but running into a TypeError issue with the REST client in remix. I have made a new post in the proper forum category (i hope), linking here if you have any advice for this issue.