Configuration
Facebook Pixel and Conversion API Setup
Configure Facebook tracking for your ShadcnKit project
ShadcnKit integrates Facebook Pixel for client-side tracking and Facebook Conversion API for server-side tracking. This guide will walk you through the setup process.
1. Obtain Facebook Pixel ID and Access Token
- Go to your Facebook Business Manager.
- Create a new Pixel or use an existing one.
- Note down your Pixel ID.
- Generate an access token with permissions for the Conversion API.
2. Add Environment Variables
Add the following to your .env
file:
3. Facebook Pixel Setup (Client-side)
ShadcnKit implements Facebook Pixel in app/layout.tsx
:
This setup automatically tracks page views and allows you to track custom events using fbq('track', 'EventName')
in your client-side code.
4. Facebook Conversion API Setup (Server-side)
ShadcnKit implements the Conversion API in two key files:
a. app/api/logto-webhook/route.ts
This file handles user registration events:
b. app/api/stripe-webhook/route.ts
This file handles purchase events:
5. Testing Your Setup
- Use Facebook’s Event Testing Tool to verify Pixel events.
- Use the Test Events feature in Facebook’s Event Manager to verify Conversion API events.
- Make test purchases and registrations to ensure events are being sent correctly.
Benefits of This Setup
- Improved Tracking Accuracy: By using both Pixel and Conversion API, you ensure more accurate event tracking, even with ad blockers or cookie restrictions.
- Better Ad Performance: More accurate data leads to better ad targeting and performance.
- Compliance: Server-side tracking can help with privacy compliance by giving you more control over what data is sent to Facebook.
Remember to always comply with data protection regulations and obtain necessary user consents for tracking.