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,6 +21,7 @@ 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
@ -33,6 +34,13 @@ 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
4. Import Google stats by running the following command from

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;'