Meta Pixel
Meta Pixel lets you measure, optimise and build audiences for your Facebook ad campaigns.
Nuxt Scripts provides a registry script composable useScriptMetaPixel() to easily integrate Meta Pixel in your Nuxt app.
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 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.
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 .
<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>idstring | number required Your Meta (Facebook) Pixel ID.