HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Querying Real-Time Segments

This topic describes how to query real-time segments via Optimizely Data Platform's (ODP's) GraphQL API.

The GraphQL API allows you to view the results of existing segments. There is a public version (safe for your customers to explore) and a private version (for your eyes only).

  • Public GraphiQL: (Requires you to paste your public API token into the API Key box) You can use this to explore your public schema. This is a limited view that is safe to access from the browser to create personalized experiences.

  • Private GraphiQL: You can use this to explore your full schema and gain experience writing GraphQL queries

This document focuses on the public GraphQL API. With this API, you can view both the results of segments that we have created for you as well as segments that you have created yourself via the RealtimeSegments API.

On-site personalization often begins with a query for a customer's segment membership. We must use the customer's anonymous identifier to make this query:

query {
  customer(vuid: "7bfa54185ffe45dda85d739a3133e94f") {
    audiences {
      edges {
        node {
          name
        }
      }
    }
  }
}

In response, we get the set of segments that the customer has matched:

{
  "data": {
    "customer": {
      "audiences": {
        "edges": [
          {
            "node": {
              "name": "active_visitors"
            }
          },
          {
            "node": {
              "name": "dc_customer"
            }
          },
          {
            "node": {
              "name": "email_engaged"
            }
          }
        ]
      }
    }
  }
}

If you are using the private API, you can also query the events that ODP has processed to make this segment membership determination. Note that this API can only classify a customer using data that has made it through the ODP ingest pipeline. Typically, it takes a few seconds for an event sent to ODP to impact segment membership.

Access the VUID property on the zaius object (which is installed on your site by the zaius tag) to determine the VUID in the above Query. The value retrieved from zaius.VUID contains hyphens, which you must remove before issuing the query.


Did this page help you?