Skip to main content

Reusable Django app to track Meta/Facebook CAPI events server-side.

Project description

Django Facebook CAPI Dashboard

A reusable Django package to track Facebook (Meta) Conversions API events server-side, with built-in logging and admin dashboard.


📦 Installation

pip install django-facebook-capi

⚙️ Setup

1. Add to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'django_facebook_capi',
]

2. Add Required Settings

In your settings.py, add:

FACEBOOK_PIXEL_ID = 'your_facebook_pixel_id'
FACEBOOK_CAPI_ACCESS_TOKEN = 'your_capi_access_token'

You can generate these from your Meta Events Manager.

3. Migrate Database

python manage.py migrate django_facebook_capi

This will create a model to log all tracked events in the admin.

4. Optional: Enable Django Admin

Ensure django.contrib.admin is enabled and your superuser is created:

python manage.py createsuperuser

Visit /admin/ and look for Facebook Event Logs.


🚀 Usage

Import utilities into your views

from django_facebook_capi.capi_utils import (
    fb_page_view,
    fb_view_content,
    fb_lead_form,
    fb_add_to_cart,
    fb_initiate_checkout,
    fb_purchase,
    fb_custom_event,
)

📝 Event Tracking Examples

✅ PageView

track_page_view(request)

👀 ViewContent

track_view_content(
    request,
    content_name="Red T-Shirt",
    content_category="Apparel",
    content_ids=["sku123"]
)

📝 Lead Form Submission

track_lead_form_submission(request)

🛒 Add to Cart

track_add_to_cart(
    request,
    content_ids=["sku123"],
    value=799,
    currency='INR'
)

💳 Initiate Checkout

track_initiate_checkout(
    request,
    content_ids=["sku123", "sku124"],
    value=1598,
    currency='INR'
)

💰 Purchase

track_purchase(
    request,
    content_ids=["sku123", "sku124"],
    value=1598,
    currency='INR',
    transaction_id='txn_001'
)

⚙️ Custom Event

track_custom_event(
    request,
    event_name="StartTrial",
    custom_data={"plan": "Pro", "value": 0}
)

📊 Logging & Admin Panel

All events sent via this package are logged into your database and can be viewed in the Django Admin dashboard. Each log includes:

  • Event name
  • Response status code
  • Response from Meta
  • Source URL
  • Timestamp

🧠 Notes

  • You must share your Meta Pixel's Business Settings with your CAPI token if using a system user.
  • Make sure _fbc and _fbp cookies are available in requests for optimal matching.
  • Email and phone values will be hashed with SHA256 before sending.

💡 Roadmap

  • Retry failed events
  • Custom signal support
  • Admin filtering by status code
  • Retry/resend via admin actions

🧑‍💻 Contributing

  1. Fork the repo
  2. Make changes
  3. Submit a PR

📝 License

MIT @ 2025

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_facebook_capi-1.1.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_facebook_capi-1.1.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file django_facebook_capi-1.1.5.tar.gz.

File metadata

  • Download URL: django_facebook_capi-1.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for django_facebook_capi-1.1.5.tar.gz
Algorithm Hash digest
SHA256 5dfdca195e6187cc34a500d34ac3701da5c6cd1c3f6891010e8a346129467f0e
MD5 0b078b879183df844f303ff8344a23c7
BLAKE2b-256 0f5d9ae61dfc35d2894c7b9ff0da688c0ccf576faf40e6abde3435ad15e14b75

See more details on using hashes here.

File details

Details for the file django_facebook_capi-1.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_facebook_capi-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bf405d51207f2f36b6b616f2578c7257f0fb3e9834e0fe7a7101f5d354f11160
MD5 bd0202c0172bfcd6ffdbe34d35673058
BLAKE2b-256 73b03ca4035edee5e8a09af6fba47b48cf844c1eb75da3e5478d5c9d54103dd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page