Skip to content
analytics and metrics integration for Django
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
pinax Converting to Django 2.0 and CircleCI Dec 4, 2017
AUTHORS Converting to Django 2.0 and CircleCI Dec 4, 2017

Pinax Web Analytics

CircleCI Codecov

Table of Contents

About Pinax

Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at



pinax-webanalytics provides analytics and metrics integration for Django.

Current analytics services supported:

  • Google Analytics
  • Mixpanel
  • Google AdWords Conversion Tracking

Supported Django and Python versions

Django \ Python 2.7 3.4 3.5 3.6
1.11 * * * *
2.0 * * *



  • To install pinax-webanalytics:
$ pip install pinax-webanalytics
  • Add pinax-webanalytics to your INSTALLED_APPS setting::
    # other apps
  • See the list of settings to modify pinax-webanalytics's default behavior and make adjustments for your website.


Integrating pinax-webanalytics quite simple::

    {% load pinax_webanalytics_tags %}

and then toward the bottom of the body where you put your scripts:

    {% analytics %}

If you want to add certain specific activities you can use the activity API in pinax-webanalytics like so:

from pinax.webanalytics import activity

activity.add(request, "mixpanel", "track", "Node Viewed", {
    "node": self.get_object().title,
    "user": request.user.username

You would typically want to call this within a view where you had some activity you wanted to track that was more transactional than could be determined by simply a certain page view.

The parameters for this are the request, the kind, then the method that is used on the kind's javascript API, followed by a list of args that will be passed to that javascript API.

AdWords Conversion Tracking

Load the template tags as above:

    {% load pinax_webanalytics_tags %}

then toward the bottom of the body, include:

    {% adwords_conversion "waitinglist" %}

where the argument passed to adwords_conversion is the key used in PINAX_WEBANALYTICS_ADWORDS_SETTINGS to provide the conversion id, label and format.



This sets the conversion identifiers for AdWords for the conversions you want to track indexed by page specific keys:

    "waitinglist": {
        "conversion_id": "",
        "conversion_label": "",
        "conversion_format": ""


This is a data structure defining your analytics and metrics settings indexed by settings.SITE_ID (or request.pwa_site_id.) Example:

    "mixpanel": {
        1: "", # production
        2: "", # beta
    "google": {
        1: "", # production
        2: "", # beta
    "gauges": {
        1: "",

where the values you would supply for each service and SITE_ID (or request.pwa_site_id) node is the identifier code for that service.

Note that, as of 1.1, the site ID keys must be integers, not strings.


pinax-webanalytics ships with templates for three services out of the box,, Google Analytics and Mixpanel. This can be overridden in your project for customizations and likewise if there are other services you wish to use, just create a similar template under the pinax-webanalytics folder in your templates directory. The format is "_%s.html" % slug where the slug is what index the PINAX_WEBANALYTICS_SETTINGS dict with.


This snippet is used for


This snippet is used for Google Analytics


This snippet is used for Mixpanel


This snippet is used by the adwords_conversion template tag

Change Log


  • Add django>=1.11 requirement
  • Update CI configuration
  • Improve documentation markup




  • Add Django 2.0 compatibility testing
  • Drop Django 1.8, 1.9, 1.10 and Python 3.3 support
  • Convert CI and coverage to CircleCi and CodeCov
  • Add PyPi-compatible long description
  • Move documentation to


  • use plain dict instead of template.Context


  • updated this change log


  • fixed typo in installation instructions


  • corrected broken doc link in README


  • fixed import path


  • renamed to pinax-webanalytics


  • template fragments now reside in pinax/webanalytics/
  • settings prefixes changed from METRON_ to PINAX_WEBANALYTICS_
  • request.metron_site_id changed to request.pwa_site_id, but still defaults to settings.SITE_ID if not on request object
  • the session key name now defaults to _pwa_activity instead of _metron_activity


  • site ID keys in METRON_SETTINGS can reference the value stored in request.metron_site_id (useful for multi-tenancy setups)


  • Upgraded mixpanel


  • SITE_ID is now always treated as an int on lookup so the keys in METRON_SETTINGS must be ints
  • analytics template tag now bails out silently if user or request are missing from context


  • same as 0.2


  • added activity tracking
  • added adwords conversion tracking (per page template tag)


  • initial release


For an overview on how contributing to Pinax works read this blog post and watch the included video, or read our How to Contribute section. For concrete contribution ideas, please see our Ways to Contribute/What We Need Help With section.

In case of any questions we recommend you join our Pinax Slack team and ping us there instead of creating an issue on GitHub. Creating issues on GitHub is of course also valid but we are usually able to help you faster if you ping us in Slack.

We also highly recommend reading our blog post on Open Source and Self-Care.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a code of conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.

Connect with Pinax

For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.


Copyright (c) 2012-2019 James Tauber and contributors under the MIT license.

You can’t perform that action at this time.