add show_downloads config option
This commit is contained in:
parent
8c0e9c2072
commit
5a1150f4c7
24
README.txt
24
README.txt
|
@ -21,17 +21,25 @@ Installation
|
||||||
googleanalytics.id = UA-1010101-1
|
googleanalytics.id = UA-1010101-1
|
||||||
googleanalytics.username = googleaccount@gmail.com
|
googleanalytics.username = googleaccount@gmail.com
|
||||||
googleanalytics.password = googlepassword
|
googleanalytics.password = googlepassword
|
||||||
|
googleanalytics.show_downloads = true
|
||||||
# the following *must* match profile name in GA dashboard
|
# the following *must* match profile name in GA dashboard
|
||||||
googleanalytics.profile_name = mydomain.com
|
googleanalytics.profile_name = mydomain.com
|
||||||
|
|
||||||
That last comment is worth emphasising. Due to the strange
|
That last comment is worth emphasising. Due to the strange
|
||||||
relationship between tracking IDs and profiles, you need to get that
|
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
|
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
|
"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
|
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
|
from the analytics home page to see the profile name. Sometimes your
|
||||||
profile name might have a trailing slash; you need to include that,
|
profile name might have a trailing slash; you need to include that,
|
||||||
too, if so.
|
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
|
3. Wait a day or so for some stats to be recorded in Google
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
import urllib
|
||||||
import os
|
import os
|
||||||
|
from paste.deploy.converters import asbool
|
||||||
from genshi.filters import Transformer
|
from genshi.filters import Transformer
|
||||||
from genshi import HTML
|
from genshi import HTML
|
||||||
from genshi.core import START, TEXT, END
|
from genshi.core import START, TEXT, END
|
||||||
|
@ -40,6 +41,8 @@ class GoogleAnalyticsPlugin(SingletonPlugin):
|
||||||
stream = stream | Transformer('head').append(code)
|
stream = stream | Transformer('head').append(code)
|
||||||
resource_url = config.get('googleanalytics.resource_prefix',
|
resource_url = config.get('googleanalytics.resource_prefix',
|
||||||
DEFAULT_RESOURCE_URL_TAG)
|
DEFAULT_RESOURCE_URL_TAG)
|
||||||
|
show_downloads = asbool(config.get('googleanalytics.show_downloads',
|
||||||
|
False))
|
||||||
|
|
||||||
# add download tracking link
|
# add download tracking link
|
||||||
def js_attr(name, event):
|
def js_attr(name, event):
|
||||||
|
@ -69,8 +72,11 @@ class GoogleAnalyticsPlugin(SingletonPlugin):
|
||||||
# perform the stream transform
|
# perform the stream transform
|
||||||
stream = stream | Transformer(
|
stream = stream | Transformer(
|
||||||
'//div[@id="package"]//td/a')\
|
'//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
|
return stream
|
||||||
|
|
||||||
def after_map(self, map):
|
def after_map(self, map):
|
||||||
|
|
|
@ -51,6 +51,8 @@ class TestLoadCommand:
|
||||||
= 'borf'
|
= 'borf'
|
||||||
config.local_conf['googleanalytics.profile_name'] \
|
config.local_conf['googleanalytics.profile_name'] \
|
||||||
= 'borf'
|
= 'borf'
|
||||||
|
config.local_conf['googleanalytics.show_downloads'] \
|
||||||
|
= 'true'
|
||||||
cls.config = config.local_conf
|
cls.config = config.local_conf
|
||||||
wsgiapp = make_app(config.global_conf, **config.local_conf)
|
wsgiapp = make_app(config.global_conf, **config.local_conf)
|
||||||
env = {'HTTP_ACCEPT': ('text/html;q=0.9,text/plain;'
|
env = {'HTTP_ACCEPT': ('text/html;q=0.9,text/plain;'
|
||||||
|
|
Loading…
Reference in New Issue