See More

--- title: "Segment · Nuxt Scripts" meta: 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." "og: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." "og:title": "Segment · Nuxt Scripts" --- ``` Nuxt Scripts on GitHub **Scripts**# **Segment**[Copy for LLMs](https://scripts.nuxt.com/scripts/segment.md) [**~~Segment~~**](https://segment.com/) lets you collect, clean, and control your customer data. Segment helps you to understand your customers and personalize their experience. Nuxt Scripts provides a registry script composable [`useScriptSegment()`](https://scripts.nuxt.com/scripts/segment) to easily integrate Segment in your Nuxt app.**Segment**[**~~View source ~~**](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/segment.ts) ## Nuxt Config Setup Add this to your `nuxt.config.ts` to load Segment globally. Alternatively you can use the **~~useScriptSegment~~** composable for more control.``` export default defineNuxtConfig({ scripts: { registry: { segment: { writeKey: 'YOUR_WRITE_KEY', trigger: 'onNuxtReady', } } } }) ``` This config automatically enables **~~first-party mode ~~** (bundle). See below to customise. ## useScriptSegment() The `useScriptSegment` composable lets you have fine-grain control over when and how Segment is loaded on your site.``` const { proxy } = useScriptSegment() proxy.track('conversion', { value: 1, currency: 'USD' }) ``` Please follow the [**~~Registry Scripts ~~**](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage. ## First-Party Mode: Privacy Focused Proxy No extra config needed. The script is bundled and served from your domain instead of a third-party CDN, eliminating an extra DNS lookup and improving load times. [**~~Learn more. ~~**](https://scripts.nuxt.com/docs/guides/first-party)**Mode**Bundle Partytown``` export default defineNuxtConfig({ scripts: { // ✅ First-party mode: bundled registry: { segment: { writeKey: 'YOUR_WRITE_KEY', trigger: 'onNuxtReady', }, }, }, }) ```## Example Using Segment in a component.``` ````**writeKey**``string`** required ** Your Segment write key.`**analyticsKey**``string` = 'analytics' The global variable name for the analytics instance. [~~Edit this page~~](https://github.com/nuxt/scripts/edit/main/docs/content/scripts/segment.md) [~~Markdown For LLMs~~](https://scripts.nuxt.com/scripts/segment.md) [**Rybbit Analytics** Use Rybbit Analytics in your Nuxt app.](https://scripts.nuxt.com/scripts/rybbit-analytics) [**Snapchat Pixel** Use Snapchat Pixel in your Nuxt app.](https://scripts.nuxt.com/scripts/snapchat-pixel)