TikTok Pixel
TikTok Pixel lets you measure, optimize and build audiences for your TikTok ad campaigns.
Nuxt Scripts provides a registry script composable useScriptTikTokPixel() to easily integrate TikTok Pixel in your Nuxt app.
Nuxt Config Setup
Add this to your nuxt.config.ts to load TikTok Pixel globally. Alternatively you can use the useScriptTikTokPixel composable for more control.
export default defineNuxtConfig({
scripts: {
registry: {
tiktokPixel: {
id: 'CXXXXXXXXXXXXXX',
trigger: 'onNuxtReady',
}
}
}
})This config automatically enables first-party mode (bundle + proxy). See below to customise.
useScriptTikTokPixel()
The useScriptTikTokPixel composable lets you have fine-grain control over when and how TikTok Pixel is loaded on your site.
const { proxy } = useScriptTikTokPixel()
proxy.ttq.track('CompletePayment', { 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 TikTok Pixel, works with ad blockers). Learn more.
export default defineNuxtConfig({
scripts: {
// ✅ First-party mode: bundled + proxied
registry: {
tiktokPixel: {
id: 'CXXXXXXXXXXXXXX',
trigger: 'onNuxtReady',
},
},
},
})Example
Using TikTok Pixel in a component with the proxy to send events .
<script setup lang="ts">
const { proxy } = useScriptTikTokPixel()
// noop in development, ssr
// just works in production, client
function handleAction() {
proxy.ttq.track('CompletePayment', { value: 1, currency: 'USD' })
}
</script>
<template>
<div>
<button @click="handleAction">
Send Event
</button>
</div>
</template>Identifying Users
You can identify users for advanced matching:
const { proxy } = useScriptTikTokPixel()
proxy.ttq('identify', {
email: '[email protected]',
phone_number: '+1234567890'
})
Disabling Auto Page View
By default, TikTok Pixel tracks page views automatically. To disable:
export default defineNuxtConfig({
scripts: {
registry: {
tiktokPixel: {
id: 'YOUR_PIXEL_ID',
trackPageView: false
}
}
}
})
idstring required Your TikTok Pixel ID.
trackPageViewboolean = trueWhether to automatically track a page view on initialization.