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.1.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.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djangocms_ab_testing-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 5ae9364e28e63c2527dd9dab106576ab1ea6b2ec6dae139febcaac3289a1ba7f
MD5 1dc25084030f220e5a1b10664317c246
BLAKE2b-256 0a163795769e16fc0e80410b9b32a0bb2665192eb30db594cc6e6dd05a4a38ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for djangocms_ab_testing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f62ce67e5b0baeee62c96f5323cb6230322f588c456f09c80871ad72d3a7951
MD5 5fcc3093303ccf8598e96acf1e328f47
BLAKE2b-256 9ede1158672c2713a18aea1d6f80140c5986be90cfcf33a022dc66fe7d5f3434

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