---
title: "X Pixel · Nuxt Scripts"
description: "Use X Pixel in your Nuxt app."
canonical_url: "https://scripts.nuxt.com/scripts/v0/tracking/x-pixel"
meta:
  "og:description": "Use X Pixel in your Nuxt app."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_X%2BPixel%2Cdescription_Use%2BX%2BPixel%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Tracking%2Cp_Ii9zY3JpcHRzL3YwL3RyYWNraW5nL3gtcGl4ZWwi%2Cs_Q-OFHUCk9q-AFIfi.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "X Pixel · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_X%2BPixel%2Cdescription_Use%2BX%2BPixel%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Tracking%2Cp_Ii9zY3JpcHRzL3YwL3RyYWNraW5nL3gtcGl4ZWwi%2Cs_Q-OFHUCk9q-AFIfi.png"
---

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

**Tracking**

# **X Pixel**

[Copy for LLMs](https://scripts.nuxt.com/scripts/v0/tracking/x-pixel.md)

[**X Pixel**](https://x.com/) lets you collect, clean, and control your customer data. X helps you to understand your customers and personalize their experience.

Nuxt Scripts provides a registry script composable `**useScriptXPixel**` to easily integrate X Pixel in your Nuxt app.

### Nuxt Config Setup

The simplest way to load Meta Pixel globally in your Nuxt App is to use Nuxt config. Alternatively you can directly use the **useScriptXPixel** composable.

If you don't plan to send custom events you can use the [**Environment overrides**](https://nuxt.com/docs/getting-started/configuration#environment-overrides) to disable the script in development.

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      xPixel: {
        id: 'YOUR_ID'
      }
    }
  }
})
```

#### **With Environment Variables**

If you prefer to configure your id using environment variables.

nuxt.config.ts

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      xPixel: true,
    }
  },
  // you need to provide a runtime config to access the environment variables
  runtimeConfig: {
    public: {
      scripts: {
        xPixel: {
          id: '', // NUXT_PUBLIC_SCRIPTS_X_PIXEL_ID
        },
      },
    },
  },
})
```

.env

```text
NUXT_PUBLIC_SCRIPTS_X_PIXEL_ID=<YOUR_ID>
```

## useScriptXPixel

The `**useScriptXPixel**` composable lets you have fine-grain control over when and how X Pixel is loaded on your site.

```ts
const { proxy } = useScriptXPixel({
  id: 'YOUR_ID'
})
// example
proxy.twq('event', '<EventId>', {
  value: 1,
})
```

Please follow the [**Registry Scripts**](https://scripts.nuxt.com/docs/v0/guides/registry-scripts) guide to learn more about advanced usage.

### XPixelApi

```ts
export interface XPixelApi {
  twq: TwqFns & {
    loaded: boolean
    version: string
    queue: any[]
  }
}
type TwqFns =
  ((event: 'event', eventId: string, data?: EventObjectProperties) => void)
  & ((event: 'config', id: string) => void)
  & ((event: string, ...params: any[]) => void)
interface ContentProperties {
  content_type?: string | null
  content_id?: string | number | null
  content_name?: string | null
  content_price?: string | number | null
  num_items?: string | number | null
  content_group_id?: string | number | null
}
interface EventObjectProperties {
  value?: string | number | null
  currency?: string | null
  conversion_id?: string | number | null
  email_address?: string | null
  phone_number?: string | null
  contents: ContentProperties[]
}
```

### Config Schema

You must provide the options when setting up the script for the first time.

```ts
export const XPixelOptions = object({
  id: string(),
  version: optional(string()),
})
```

## Example

Using X Pixel only in production while using `**twq**` to send a conversion event.

```vue
<script setup lang="ts">
const { proxy } = useScriptXPixel()

// noop in development, ssr
// just works in production, client
function sendConversion() {
  proxy.twq('event', 'Purchase', {
    value: 1,
    currency: 'USD'
  })
}
</script>

<template>
  <div>
    <button @click="sendConversion">
      Send Conversion
    </button>
  </div>
</template>
```

[Edit this page](https://github.com/nuxt/scripts/edit/0.x/docs/content/tracking/x-pixel.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/v0/tracking/x-pixel.md)

[**Snapchat Pixel** Use Snapchat Pixel in your Nuxt app.](https://scripts.nuxt.com/scripts/v0/tracking/snapchat-pixel) [**NPM** Load IIFE scripts from NPM in your Nuxt app.](https://scripts.nuxt.com/scripts/v0/utility/npm)

**On this page **

- [Nuxt Config Setup](#nuxt-config-setup)
- [useScriptXPixel](#usescriptxpixel)
- [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/scripts/v0/tracking/x-pixel#webpage","@type":"WebPage","description":"Use X Pixel in your Nuxt app.","name":"X Pixel","url":"https://scripts.nuxt.com/scripts/v0/tracking/x-pixel","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/v0/tracking/x-pixel#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/v0/tracking/x-pixel"]}],"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/scripts/v0/tracking/x-pixel#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"V0","item":"https://scripts.nuxt.com/scripts/v0","position":3},{"@type":"ListItem","name":"Tracking","item":"https://scripts.nuxt.com/scripts/v0/tracking","position":4},{"@type":"ListItem","name":"X Pixel","item":"https://scripts.nuxt.com/scripts/v0/tracking/x-pixel","position":5}]},{"@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.
