UNPKG

c15t

Version:

Headless JavaScript consent management platform for cookie banners, privacy preferences, consent storage, and script gating.

242 lines (188 loc) 6.84 kB
--- title: Reddit Pixel description: Track conversions and build retargeting audiences for Reddit advertising campaigns. group: integrations icon: reddit --- Reddit Pixel is Reddit's conversion tracking tool for ads and remarketing. It seeds the standard `rdt` queue before the vendor bundle loads, initializes your pixel, and by default records a `PageVisit` event once consent for `marketing` is available. ## Integrate with c15t **React** ```tsx import { type ReactNode } from 'react'; import { ConsentManagerProvider } from '@c15t/react'; import { redditPixel } from '@c15t/scripts/reddit-pixel'; const scripts = [redditPixel({ pixelId: 't2_abcdef' })]; export function ConsentProvider({ children }: { children: ReactNode }) { return ( <ConsentManagerProvider options={{ mode: 'hosted', backendURL: 'https://your-instance.c15t.dev', scripts, }} > {children} </ConsentManagerProvider> ); } ``` **Next.js** ```tsx 'use client'; import { type ReactNode } from 'react'; import { ConsentManagerProvider } from '@c15t/nextjs'; import { redditPixel } from '@c15t/scripts/reddit-pixel'; const scripts = [redditPixel({ pixelId: 't2_abcdef' })]; export function ConsentProvider({ children }: { children: ReactNode }) { return ( <ConsentManagerProvider options={{ mode: 'hosted', backendURL: '/api/c15t', scripts, }} > {children} </ConsentManagerProvider> ); } ``` **JavaScript** ```ts import { getOrCreateConsentRuntime } from 'c15t'; import { redditPixel } from '@c15t/scripts/reddit-pixel'; getOrCreateConsentRuntime({ mode: 'hosted', backendURL: 'https://your-instance.c15t.dev', scripts: [redditPixel({ pixelId: 't2_abcdef' })], }); ``` ## How c15t loads it * **Category:** `marketing` (Ads & Pixels) * **Loads when:** marketing consent is granted * **On revocation:** retained in the DOM so c15t can call Reddit's first-party-cookie controls. c15t calls `rdt('disableFirstPartyCookies')` when marketing consent is denied and `rdt('enableFirstPartyCookies')` when it is granted again. If you prefer to control page-view tracking yourself, disable the default `PageVisit` call: ```ts redditPixel({ pixelId: 't2_abcdef', trackPageVisit: false, }) ``` ## Tracking events in your app c15t gates the Reddit Pixel script from loading until `marketing` consent is granted. Your application code that calls Reddit's runtime API (`window.rdt(...)`) is **not** automatically gated - `window.rdt` does not exist until the script is loaded, so unguarded calls before consent throw. Guard event calls by checking consent state. From React: ```tsx import { useCallback } from 'react'; import { useConsentManager } from '@c15t/react'; import { redditPixelEvent } from '@c15t/scripts/reddit-pixel'; function CheckoutExample() { const { has } = useConsentManager(); const trackPurchase = useCallback(() => { if (has('marketing')) { redditPixelEvent('Purchase', { currency: 'USD', value: 99, conversionId: 'order-123', }); } }, [has]); // Call trackPurchase() from your conversion success path. } ``` From plain JavaScript: ```ts import { getOrCreateConsentRuntime } from 'c15t'; const { consentStore } = getOrCreateConsentRuntime(); if (consentStore.getState().has('marketing')) { window.rdt?.('track', 'Purchase', { currency: 'USD', value: 99, conversionId: 'order-123', }); } ``` When you use Reddit Pixel and Conversions API together, send the same `conversionId` in the browser event and the server event so Reddit can deduplicate them. ## Consent and privacy c15t keeps Reddit Pixel behind `marketing` consent. Before marketing consent, the Reddit script is not loaded. After marketing consent is granted, c15t loads the script and queues the Reddit `init` call. For stricter first-party-cookie behavior, disable Reddit first-party cookies during initialization: ```ts redditPixel({ pixelId: 't2_abcdef', disableFirstPartyCookies: true, }) ``` You can also pass Reddit's initialization options directly: ```ts redditPixel({ pixelId: 't2_abcdef', initOptions: { optOut: true, disableFirstPartyCookies: true, }, }) ``` Reddit supports a Limited Data Use flag through data processing fields. Use the values required by your policy and jurisdiction: ```ts redditPixel({ pixelId: 't2_abcdef', initOptions: { dpm: ['LDU'], dpcc: 'US', dprc: 'CA', }, }) ``` Reddit can also receive attribution matching signals such as `email`, `phoneNumber`, `externalId`, `aaid`, and `idfa`. Only pass those fields after you have the right consent or legal basis for your use case: ```ts redditPixel({ pixelId: 't2_abcdef', initOptions: { email: 'person@example.com', externalId: 'customer-123', aam: { email: false, phone_number: false, }, }, }) ``` See Reddit's docs for [Limited Data Use](https://business.reddithelp.com/s/article/Limited-Data-Use), [event metadata](https://business.reddithelp.com/s/article/about-event-metadata), and [event deduplication](https://business.reddithelp.com/s/article/event-deduplication). ## Types ### RedditPixelOptions |Property|Value| |:--|:--| |Type Name|\`RedditPixelOptions\`| |Source Path|\`./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts\`| \*ExtractedTypeTable: Could not extract "RedditPixelOptions" from "./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\* ### RedditPixelInitOptions |Property|Value| |:--|:--| |Type Name|\`RedditPixelInitOptions\`| |Source Path|\`./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts\`| \*ExtractedTypeTable: Could not extract "RedditPixelInitOptions" from "./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\* ### RedditPixelEventMetadata |Property|Value| |:--|:--| |Type Name|\`RedditPixelEventMetadata\`| |Source Path|\`./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts\`| \*ExtractedTypeTable: Could not extract "RedditPixelEventMetadata" from "./packages/scripts/src/vendors/ads-and-pixels/reddit-pixel.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\* ### Script |Property|Value| |:--|:--| |Type Name|\`Script\`| |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`| \*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*