Skip to main content

A/B testing plugin for django CMS with round-robin assignment, cookie-based persistence, event tracking, and an admin dashboard.

Project description

djangocms-ab-testing

PyPI version Python versions Django versions License: MIT

A full-featured A/B testing (split testing) plugin for django CMS. Run conversion optimization experiments directly in the CMS page editor with round-robin variant assignment, cookie-based persistence, client-side event tracking, and a built-in admin dashboard with Chart.js visualizations.

Features

  • CMS plugin-based setup - Add A/B test containers and variants directly in the django CMS page editor
  • Round-robin assignment - Fair variant distribution using an atomic database counter
  • Cookie persistence - Visitors see the same variant for 30 days (ab_variant_<slug>)
  • Event tracking API - POST events to /api/ab-event/ with CSRF protection
  • Auto "view" tracking - Fires automatically when a variant is rendered
  • Bootstrap modal tracking - Tracks shown.bs.modal, hidden.bs.modal, and CTA button clicks
  • Configurable actions - Define custom tracking events via AB_TESTING_VALID_ACTIONS setting
  • Admin dashboard - Chart.js-powered visualizations with summary cards, per-variant stats, daily trends, and conversion rate charts
  • Distribution breakdowns - Analyze results by device type, browser, OS, and screen size
  • Filtering - Filter dashboard data by date range and device properties
  • CSV export - Export event data via django-import-export
  • Cache control - Pages with A/B tests automatically get Cache-Control: private, no-store

Screenshots

Light theme

Dashboard - Light theme

Dark theme

Dashboard - Dark theme

Installation

pip install djangocms-ab-testing

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "djangocms_ab_testing",
]

Add the middleware (after SessionMiddleware):

MIDDLEWARE = [
    # ...
    "django.contrib.sessions.middleware.SessionMiddleware",
    "djangocms_ab_testing.middleware.ABCookieMiddleware",
    # ...
]

Add the URL config:

from django.urls import include, path

urlpatterns = [
    # ...
    path("api/", include("djangocms_ab_testing.urls")),
]

Run migrations:

python manage.py migrate djangocms_ab_testing

Usage

1. Create an AB Test

Go to Django Admin > AB Tests and create a test with a name and slug.

2. Add CMS Plugins

In the django CMS page editor:

  1. Add an A/B Test Container plugin and link it to your test
  2. Inside the container, add A/B Test Variant plugins (e.g. variant key A, B)
  3. Add your content inside each variant

3. Track Events

Include the tracking script in your template:

<script src="{% static 'djangocms_ab_testing/js/ab_tracking.js' %}"></script>

The script auto-initializes, fires a view event when the variant is rendered, and tracks Bootstrap modal events (shown.bs.modal, hidden.bs.modal). Add the ab-request-btn class to CTA buttons inside modals to track conversion clicks.

For custom tracking, call window.initABTracking() after dynamic content loads.

4. View Results

Open any AB Test in the admin to see the dashboard with:

  • Summary cards (total events, unique sessions, counter)
  • Per-variant stats table (views, opens, requests, closes, conversion rate)
  • Daily trends and conversion rate charts
  • Distribution breakdowns by device, browser, OS, screen size
  • Filterable by date range and device properties
  • CSV export via django-import-export

Configuration

Custom Tracking Actions

By default, the following actions are tracked: view, opened, closed, requested.

To define custom actions, add AB_TESTING_VALID_ACTIONS to your Django settings:

AB_TESTING_VALID_ACTIONS = {"view", "opened", "closed", "requested", "submitted", "purchased"}

The event tracking API will only accept actions in this set. The admin dashboard and seed command will also use these actions automatically.

How It Works

  • Variant assignment: Round-robin via atomic database counter
  • Persistence: 30-day cookie per test (ab_variant_<slug>)
  • Cache: Pages with A/B tests get Cache-Control: private, no-store
  • Events: Tracked via POST to /api/ab-event/ with CSRF protection

Management Commands

python manage.py seed_ab_data --events 500 --days 30

Generates dummy event data for dashboard testing.

Publishing to PyPI

  1. Install build tools:
pip install build twine
  1. Build the package:
python -m build
  1. Upload to TestPyPI first:
twine upload --repository testpypi dist/*
  1. Upload to PyPI:
twine upload dist/*

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

MIT

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

djangocms_ab_testing-0.2.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

djangocms_ab_testing-0.2.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_ab_testing-0.2.0.tar.gz.

File metadata

  • Download URL: djangocms_ab_testing-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for djangocms_ab_testing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3fbe42d241e1796b0a0870d691d87eb46cf72618c53895206ad518f46a89ad57
MD5 aa21cb19b637d68b5a9077ce5190bd66
BLAKE2b-256 c97ee927baa203b78bc1e02c5aac20234723b94370cc3d9cf6fadbeac7daf9d1

See more details on using hashes here.

File details

Details for the file djangocms_ab_testing-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_ab_testing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 073e141aef11040b0da058095f9a9609379abf35a7addb78f273e8cd3d4b6fea
MD5 5cbc26d7f67a4bf860f104749f74a546
BLAKE2b-256 143a6fe371bec6c69005df25381a70bedee57ccf7550e51df0e46c7826b96f2d

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