integration-django

Integrates PostHog analytics into Django applications via middleware and AppConfig.

58|5|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/PostHog/skills --skill integration-django
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integration-django
Source: https://github.com/PostHog/skills/tree/main/skills/posthog/integration/skills/django
Command: npx skills add https://github.com/PostHog/skills --skill integration-django

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Django integration enables PostHog analytics within Django apps by configuring server-side tracking, context enrichment, and reliable event capture without modifying existing business logic.

Core Features & Use Cases

  • Automatic context-aware event tracking via PostHogContextMiddleware that attaches session and user context to events.
  • Server-side initialization and configuration of PostHog in AppConfig using environment variables, ensuring consistent access across modules.
  • User identification and property tagging on login/logout, plus event capture for key workflows such as login, dashboard access, and error scenarios.
  • Feature flags, group analytics, and error tracking to drive product decisions and reliability.
  • Lightweight reference and example files to guide integration and troubleshooting.

Quick Start

Configure POSTHOG_PROJECT_TOKEN and POSTHOG_HOST in your settings, add PosthogContextMiddleware to MIDDLEWARE, and verify a sample event captures correctly.

Frequently Asked Questions about integration-django

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up PostHog analytics in a Django application?

Set up PostHog analytics in Django by initializing PostHog in AppConfig with environment variables, adding PosthogContextMiddleware to MIDDLEWARE, and configuring POSTHOG_PROJECT_TOKEN and POSTHOG_HOST in settings for reliable server-side event capture.

How does Django middleware track user context for analytics events?

Django middleware tracks user context via PosthogContextMiddleware, which automatically attaches session and user context to server-side analytics events, ensuring accurate user identification without modifying business logic.

Can I track Django login and dashboard events server-side with PostHog?

Track Django login and dashboard events server-side with PostHog by capturing context-aware events during key workflows, identifying users on login and logout, and tagging properties for product analytics.

Does PostHog Django integration support feature flags and error tracking?

PostHog Django integration supports feature flags, group analytics, and error tracking, enabling product decisions and reliability monitoring by capturing error scenarios alongside standard event data.

What is the best way to separate user identifiable data from event properties in Django?

Separate user identifiable data from event properties in Django by enforcing proper data separation during PostHog event capture, keeping identifiable user information distinct from general event context.

Do I need environment variables to configure PostHog in Django settings?

Environment variables are required to configure PostHog in Django settings, enforcing environment-based configuration for POSTHOG_PROJECT_TOKEN and POSTHOG_HOST to ensure consistent access across modules.