---
title: "Meta Pixel · Nuxt Scripts"
description: "Load Meta Pixel, send events through fbq, and manage its binary consent state."
canonical_url: "https://scripts.nuxt.com/scripts/meta-pixel"
meta:
  "og:description": "Load Meta Pixel, send events through fbq, and manage its binary consent state."
  "og:image": "https://scripts.nuxt.com/_og/s/o_f05ab398aaa522d8.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Meta Pixel · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_f05ab398aaa522d8.png"
---

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

**Scripts**

# **Meta Pixel**

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

[**Meta Pixel**](https://www.facebook.com/business/tools/meta-pixel) sends conversion and audience events to Meta Ads.

[`**useScriptMetaPixel()**`](https://scripts.nuxt.com/scripts/meta-pixel) loads the pixel and exposes the `**fbq**` queue.

**Meta Pixel**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/meta-pixel.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Meta Pixel globally. Alternatively you can use the **useScriptMetaPixel** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      metaPixel: {
        id: '123456789012345',
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

This config automatically enables **first-party mode ** (bundle + proxy). See below to customise.

## useScriptMetaPixel()

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

```
const { proxy } = useScriptMetaPixel()

proxy.fbq('track', 'Purchase', { 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 from your domain (faster loads, no extra DNS lookup) and runtime requests are reverse-proxied through your server with automatic anonymisation (user IPs stay hidden from Meta Pixel, works with ad blockers). [**Learn more. **](https://scripts.nuxt.com/docs/guides/first-party)

**Mode**

Bundle Proxy Partytown

**Privacy**

All identifying data is stripped: IP, user agent, language, screen size, timezone, and hardware fingerprints.

```
export default defineNuxtConfig({
  scripts: {
    // ✅ First-party mode: bundled + proxied
    registry: {
      metaPixel: {
        id: '123456789012345',
        trigger: 'onNuxtReady',
      },
    },
  },
})
```

## Example

Using Meta Pixel in a component with the proxy to send events .

ConversionButton.vue

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

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

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
```

`**id**``string | number`** required **

Your Meta (Facebook) Pixel ID.

`**defaultConsent**``'granted' | 'denied'`

Default consent state. \`'granted'\` fires \`fbq('consent', 'grant')\`, \`'denied'\` fires \`fbq('consent', 'revoke')\`, both called before \`fbq('init', id)\`.

## Disabling automatic page views

By default, Meta Pixel tracks a page view during initialization. Disable it when you send your own `**PageView**` with an `**eventID**` for Conversions API deduplication:

```ts
useScriptMetaPixel({
  id: 'YOUR_PIXEL_ID',
  trackPageView: false,
})
```

Then send the page view yourself and share the `**eventID**` with the Conversions API call:

```ts
const { proxy } = useScriptMetaPixel({ id: 'YOUR_PIXEL_ID', trackPageView: false })
proxy.fbq('track', 'PageView', {}, { eventID: 'shared-with-capi' })
```

## Consent Mode

Meta Pixel exposes a binary consent toggle. Set the initial state with `**defaultConsent**` (fires `**fbq('consent', 'grant'|'revoke')**` before `**fbq('init', id)**`) and call `**consent.grant()**` / `**consent.revoke()**` at runtime:

```vue
<script setup lang="ts">
const { consent } = useScriptMetaPixel({
  id: 'YOUR_PIXEL_ID',
  defaultConsent: 'denied',
})

function acceptAds() {
  consent.grant()
}
function rejectAds() {
  consent.revoke()
}
</script>
```

`**defaultConsent: 'denied'**` queues a revoke command before pixel initialization, but it does not delay the SDK request. If your consent policy requires no request to Meta before opt-in, use a [**binary load gate**](https://scripts.nuxt.com/docs/guides/consent#binary-load-gate) for the script itself.

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

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

[**Matomo Analytics** Track Matomo page views and events with built-in consent controls.](https://scripts.nuxt.com/scripts/matomo-analytics) [**Mixpanel** Load Mixpanel and track product events, identities, profiles, and consent.](https://scripts.nuxt.com/scripts/mixpanel-analytics)

**On this page **

- [Disabling automatic page views](#disabling-automatic-page-views)
- [Consent Mode](#consent-mode)

```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/meta-pixel#webpage","@type":"WebPage","description":"Load Meta Pixel, send events through fbq, and manage its binary consent state.","name":"Meta Pixel","url":"https://scripts.nuxt.com/scripts/meta-pixel","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/meta-pixel#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/meta-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/meta-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":"Meta Pixel","item":"https://scripts.nuxt.com/scripts/meta-pixel","position":3}]},{"@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.
