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.
Where you can find what you need:
pinax-webanalytics
provides analytics and metrics integration for Django.
Current analytics services supported:
Django / Python | 3.6 | 3.7 | 3.8 |
---|---|---|---|
2.2 | * | * | * |
3.0 | * | * | * |
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.
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.
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:
PINAX_WEBANALYTICS_ADWORDS_SETTINGS = {
"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:
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.
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
dict
instead of template.Context
pinax-webanalytics
pinax/webanalytics/
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_pwa_activity
instead of _metron_activity
request.metron_site_id
(useful for multi-tenancy setups)SITE_ID
is now always treated as an int on lookup so the keys in
METRON_SETTINGS
must be intsuser
or request
are
missing from contextContributing information can be found in the Pinax community health file repo.
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.
For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.
Copyright (c) 2012-present James Tauber and contributors under the MIT license.