pinax / pinax-webanalytics

analytics and metrics integration for Django
MIT License
124 stars 22 forks source link

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 http://pinaxproject.com.

Important Links

Where you can find what you need:

pinax-webanalytics

Overview

pinax-webanalytics provides analytics and metrics integration for Django.

Current analytics services supported:

Supported Django and Python Versions

Django / Python 3.6 3.7 3.8
2.2 * * *
3.0 * * *

Documentation

Installation

To install pinax-webanalytics:

$ pip install pinax-webanalytics

Add pinax.webanalytics to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    # other apps
    "pinax.webanalytics",
]

See the list of settings to modify pinax-webanalytics's default behavior and make adjustments for your website.

Usage

Integrating pinax-webanalytics is 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.

Settings

PINAX_WEBANALYTICS_ADWORDS_SETTINGS

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

PINAX_WEBANALYTICS_ADWORDS_SETTINGS = {
    "waitinglist": {
        "conversion_id": "",
        "conversion_label": "",
        "conversion_format": ""
    }
}

PINAX_WEBANALYTICS_SETTINGS

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

PINAX_WEBANALYTICS_SETTINGS = {
    "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.

Templates

pinax-webanalytics ships with templates for three services out of the box, gaug.es, 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.

_gauges.html

This snippet is used for gaug.es

_google.html

This snippet is used for Google Analytics

_mixpanel.html

This snippet is used for Mixpanel

_adwords_conversion.html

This snippet is used by the adwords_conversion template tag

Change Log

5.0.0

4.0.2

4.0.1

4.0.0

3.0.0

2.0.4

2.0.3

2.0.2

2.0.1

2.0

BI

1.3

1.2

1.1

1.0

0.2

0.1

Contribute

Contributing information can be found in the Pinax community health file repo.

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.

License

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