add show_downloads config option

This commit is contained in:
Seb Bacon 2011-04-05 15:28:27 +01:00
parent 8c0e9c2072
commit 5a1150f4c7
3 changed files with 26 additions and 10 deletions

View File

@ -21,17 +21,25 @@ Installation
googleanalytics.id = UA-1010101-1
googleanalytics.username = googleaccount@gmail.com
googleanalytics.password = googlepassword
googleanalytics.show_downloads = true
# the following *must* match profile name in GA dashboard
googleanalytics.profile_name = mydomain.com
That last comment is worth emphasising. Due to the strange
relationship between tracking IDs and profiles, you need to get that
right. It's the relevant value in the "Name" column for the list of
"Website Profiles" that you see when you click on an Analytics Account
link in the Google Analytics homepage. E.g. you'll need two clicks
from the analytics home page to see the profile name. Sometimes your
profile name might have a trailing slash; you need to include that,
too, if so.
That last comment is worth emphasising. Due to the strange
relationship between tracking IDs and profiles, you need to get that
right. It's the relevant value in the "Name" column for the list of
"Website Profiles" that you see when you click on an Analytics Account
link in the Google Analytics homepage. E.g. you'll need two clicks
from the analytics home page to see the profile name. Sometimes your
profile name might have a trailing slash; you need to include that,
too, if so.
Note also that your password will probably be readable by other
people; so you may want to set up a new gmail account specifically
for accessing your gmail profile.
If ``show_downloads`` is set, a download count for resources will be
displayed on individual package pages.
3. Wait a day or so for some stats to be recorded in Google

View File

@ -1,6 +1,7 @@
import logging
import urllib
import os
from paste.deploy.converters import asbool
from genshi.filters import Transformer
from genshi import HTML
from genshi.core import START, TEXT, END
@ -40,6 +41,8 @@ class GoogleAnalyticsPlugin(SingletonPlugin):
stream = stream | Transformer('head').append(code)
resource_url = config.get('googleanalytics.resource_prefix',
DEFAULT_RESOURCE_URL_TAG)
show_downloads = asbool(config.get('googleanalytics.show_downloads',
False))
# add download tracking link
def js_attr(name, event):
@ -69,8 +72,11 @@ class GoogleAnalyticsPlugin(SingletonPlugin):
# perform the stream transform
stream = stream | Transformer(
'//div[@id="package"]//td/a')\
.apply(download_adder).attr('onclick', js_attr)
.attr('onclick', js_attr)
if show_downloads:
stream = stream | Transformer(
'//div[@id="package"]//td/a')\
.apply(download_adder)
return stream
def after_map(self, map):

View File

@ -51,6 +51,8 @@ class TestLoadCommand:
= 'borf'
config.local_conf['googleanalytics.profile_name'] \
= 'borf'
config.local_conf['googleanalytics.show_downloads'] \
= 'true'
cls.config = config.local_conf
wsgiapp = make_app(config.global_conf, **config.local_conf)
env = {'HTTP_ACCEPT': ('text/html;q=0.9,text/plain;'