GraphiQL order query filter by utm parameters

Topic summary

Filtering Shopify orders via GraphQL by UTM parameters to retrieve only referral orders from a specific site. The app passes UTM parameters (campaign tracking tags like source, medium, campaign) from landing to completed order and can read them in the order’s customerJourney.

Problem: The GraphQL Admin API query filter does not appear to filter on nested fields within customerJourney (e.g., customerJourney.moments.utmParameters.source). A sample query combining created_at and a nested UTM source field returns unfiltered results.

Goal: Restrict access to only orders attributed to the app’s referrals to avoid viewing all store orders (data privacy concern).

Ask: Whether GraphiQL/GraphQL supports filtering orders by nested customerJourney UTM parameters. If not, guidance on alternative approaches to safely retrieve only relevant orders.

Technical context: GraphiQL (query tool for Shopify GraphQL Admin API); customerJourney captures visit moments that include utmParameters; UTM parameters are standard marketing tracking fields. The provided code snippet is central to understanding the issue.

Status: No responses or resolution yet; the question remains open.

Summarized with AI on January 4. AI used: gpt-5.

Hi there,

I am creating an app where I will query the orders at a shopify website from my backend to detect the orders that were referred by my site.

I use utm parameters at the initial page that I direct users to and they are passed properly all the way to order completed. I can get the utm parameters at the customerJourney of an order.

The challenge is that I only want to get orders related to me as seeing all orders of a store would cause data breach. Is there a way to achieve that at GraphiQL filter? If not, what would be your guidance to achieve this in other ways?

Something like below but the query does not seem to filter properly:

{
  orders(
    first: 100
    query: "created_at:>='2024-02-21' AND customerJourney.moments.utmParameters.source:test_keyword"
    reverse: true
  ) {
    edges {
      node {
        name
        id
        createdAt
        channelInformation {
          id
        }
        currentTotalPriceSet {
          presentmentMoney {
            amount
          }
        }
        customer {
          id
        }
        customerJourneySummary {
          firstVisit {
            landingPage
          }
          lastVisit {
            landingPage
          }
        }
        customerJourney {
          moments {
            ... on CustomerVisit {
              utmParameters {
                source
                campaign
                content
                medium
                term
              }
            }
          }
        }
      }
    }
  }
}

Thanks