---
title: "useScriptEventPage() · Nuxt Scripts"
description: "React to changes in the current page title or path."
canonical_url: "https://scripts.nuxt.com/docs/api/use-script-event-page"
meta:
  "og:description": "React to changes in the current page title or path."
  "og:image": "https://scripts.nuxt.com/_og/s/o_2bf5be15e4e56e6f.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "useScriptEventPage() · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_2bf5be15e4e56e6f.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Api**

# **useScriptEventPage()**

[Copy for LLMs](https://scripts.nuxt.com/docs/api/use-script-event-page.md)

Track the current page title and full route path, with an optional client-side callback.

## Signature

```ts
function useScriptEventPage(onChange?: (payload: TrackedPage) => void): Ref<TrackedPage> {}
```

`**TrackedPage**` is `**{ title?: string, path: string }**`.

## Arguments

- `**onChange**` (optional): Called in the browser after a `**page:finish**` hook when the title or path differs from the last emitted value. It is not called during SSR.

If you register the composable before the initial `**page:finish**` hook, as you normally would in `**app.vue**`, the callback receives the first hydrated page as well as later navigations. A composable created after that hook waits for the next page finish; it does not backfill a callback.

## Returns

A ref containing the current page title and full path, including its query string and hash. During SSR, `**title**` starts as an empty string because the document has not rendered yet.

## Example

Log each page change:

```vue
<script setup lang="ts">
useScriptEventPage((ctx) => {
  console.log(ctx.title, ctx.path)
})
</script>
```

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/3.api/4.use-script-event-page.md)

[Markdown For LLMs](https://scripts.nuxt.com/docs/api/use-script-event-page.md)

[**useScriptTriggerInteraction()** Load a script after a configured user interaction.](https://scripts.nuxt.com/docs/api/use-script-trigger-interaction) [**Nuxt Config** Configure registry scripts, defaults, proxying, privacy, and bundled assets.](https://scripts.nuxt.com/docs/api/nuxt-config)

**On this page **

- [Signature](#signature)
- [Arguments](#arguments)
- [Returns](#returns)
- [Example](#example)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/docs/api/use-script-event-page#webpage","@type":"WebPage","description":"React to changes in the current page title or path.","name":"useScriptEventPage()","url":"https://scripts.nuxt.com/docs/api/use-script-event-page","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/api/use-script-event-page#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/api/use-script-event-page"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/docs/api/use-script-event-page#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Documentation","item":"https://scripts.nuxt.com/docs","position":2},{"@type":"ListItem","name":"API","item":"https://scripts.nuxt.com/docs/api","position":3},{"@type":"ListItem","name":"useScriptEventPage()","item":"https://scripts.nuxt.com/docs/api/use-script-event-page","position":4}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
