(Last Updated 12/17/19 for Wagtail v2.x)
This module provides a simple dashboard of Google Analytics data, integrated into the Wagtail admin UI. Tested on Wagtail 2.0+.
pip install wagalytics
Update your settings:
GA_KEY_FILEPATH = '/path/to/secure/directory/your-key.json'
or when using environment variables (e.g. Heroku):
GA_KEY_CONTENT = 'content_of_your_key.json'
GA_VIEW_ID = 'ga:xxxxxxxx'
If you get CryptoUnavailableError errors, you probably need to pip install PyOpenSSL
and/or pip install pycrypto
. See StackOverflow.
Ensure that your code snippet is included on each page you want to be tracked (likely by putting it in your base.html template.) (Admin > Property > Tracking Code)
To enable multisite support you'll need to update your Wagalytics settings and have wagtail.contrib.settings
installed. Sites can use a GA_KEY_FILEPATH
or a GA_KEY_CONTENT
key, but it's best not to use both.
In the snippet below, you'll see site_id
. This is the ID (Primary Key) of your Wagtail Site.
# Use either the GA_KEY_FILEPATH or the GA_KEY_CONTENT setting on your sites,
# but don't use both
WAGALYTICS_SETTINGS = {
site_id: {
'GA_VIEW_ID': 'ga:xxxxxxxx',
'GA_KEY_FILEPATH': '/path/to/secure/directory/your-key.json',
},
site_id: {
'GA_VIEW_ID': 'ga:xxxxxxxx',
'GA_KEY_CONTENT': 'content_of_your_key.json',
}
}
For every Wagalytics site you add in your multisite WAGALYTICS_SETTINGS
you'll need to make sure you have the proper GA View ID and API Key. One View ID and API Key won't work for all your sites automatically.
Here's a working example of multisite WAGALYTICS_SETTINGS:
WAGALYTICS_SETTINGS = {
# My default site. 2 is the site ID. This one uses GA_KEY_FILEPATH.
2: {
'GA_VIEW_ID': 'ga:xxxxxxxx',
'GA_KEY_FILEPATH': '/path/to/secure/directory/your-key.json',
},
# The secondary site. 3 is the Site ID. This one uses GA_KEY_CONTENT.
3: {
'GA_KEY_CONTENT': 'content_of_your_key.json',
'GA_VIEW_ID': 'ga:xxxxxxxx',
}
}
Developers will need to carry out the following steps after cloning wagalytics:
npm install
then npm run build
in the top level wagalytics directoryYou will need to run npm run build
anytime the javascript source is updated.
This module doesn't help with recording user activity. See the Wagtail docs and StackOverflow for pointers on how to avoid gathering data during preview and testing.