Reddit Pixel
Reddit Pixel helps you track conversions and build audiences for your Reddit advertising campaigns.
Nuxt Scripts provides a registry script composable useScriptRedditPixel() to easily integrate Reddit Pixel in your Nuxt app.
Script Stats
Nuxt Config Setup
The simplest way to load Reddit Pixel globally in your Nuxt App is to use Nuxt config. Alternatively you can directly use the useScriptRedditPixel composable.
export default defineNuxtConfig({
scripts: {
registry: {
redditPixel: {
id: 't2_abc123defg'
}
}
}
})useScriptRedditPixel
The useScriptRedditPixel composable lets you have fine-grain control over when and how Reddit Pixel is loaded on your site.
const { proxy } = useScriptRedditPixel()
proxy.rdt('track', 'Purchase', { value: 1, currency: 'USD' })Please follow the Registry Scripts guide to learn more about advanced usage.
First-Party Mode
This script supports First-Party Mode which routes all traffic through your domain for improved privacy and ad blocker bypass.
export default defineNuxtConfig({
scripts: {
firstParty: true,
registry: {
redditPixel: { id: 't2_abc123defg'}
}
}
})To opt-out for this specific script:
useScriptRedditPixel({
id: 't2_abc123defg',
scriptOptions: {
firstParty: false
}
})Example
Using Reddit Pixel only in production while using the proxy to send events.
<script setup lang="ts">
const { proxy } = useScriptRedditPixel()
// noop in development, ssr
// just works in production, client
function handleAction() {
proxy.rdt('track', 'Purchase', { value: 1, currency: 'USD' })
}
</script>
<template>
<div>
<button @click="handleAction">
Send Event
</button>
</div>
</template>RedditPixelApi
export interface RedditPixelApi {
rdt: RdtFns & {
sendEvent: (rdt: RedditPixelApi['rdt'], args: unknown[]) => void
callQueue: unknown[]
}
}
type RdtFns
= & ((event: 'init', id: string) => void)
& ((event: 'track', eventName: string) => void)
Config Schema
You must provide the options when setting up the script for the first time.
export const RedditPixelOptions = object({
id: string(),
})