---
title: "Subscribe to page events"
slug: "subscribe-to-page-events"
abstract: "How to receive real-time updates when the SitecoreAI user opens a different page or a different version of the current one."
---
# Subscribe to page events

*Required extension points: any SitecoreAI Page builder extension point*

*Required SDK packages: client*

*Required API access: none*

> [!note]
> **Before you begin**
> -   Complete the [SDK quick start](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/quick-start--manual-.html "Quick start (manual)").

When you [query the page context](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/query-the-page-context.html "Query the page context"), you retrieve details about the current page and site. You can also subscribe to page-related events. This way, your app receives real-time updates when the SitecoreAI user changes to a different version or language of the current page, or opens a different page.

To subscribe to page events:

1. Find the code where you queried the page context, typically `client.query("pages.context")`, and replace it with the following code, then save your changes:

    ```typescript
    client.query("pages.context", {
      subscribe: true,
      onSuccess: (data) => {
        console.log("Page has been updated:", data);
      },
    })
    ```

    This script adds a second parameter to your query to enable subscriptions. Every time a current page detail changes, the updates are logged to the console.

2. In the SitecoreAI Page builder, open your web browser's console, refresh the page, then open your Marketplace app.
3. In the console, filter your logs for `Page has been updated`.
4. In the site tree, click a different page. A new log appears in the console, containing the details of the page you opened.