mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Merge branch 'master' of github.com:jcassee/django-analytical
This commit is contained in:
commit
31ffca4c2f
5 changed files with 47 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
The django-analytical package was written by `Joost Cassee`_, with
|
||||
contributions from `Eric Davis`_, `Paul Oswald`_ and others.
|
||||
contributions from `Eric Davis`_, `Paul Oswald`_, `Uros Trebec`_ and
|
||||
others.
|
||||
|
||||
Included Javascript code snippets for integration of the analytics
|
||||
services were written by the respective service providers.
|
||||
|
|
@ -12,5 +13,6 @@ The work on Crazy Egg was made possible by `Bateau Knowledge`_.
|
|||
.. _`Joost Cassee`: mailto:joost@cassee.net
|
||||
.. _`Eric Davis`: https://github.com/edavis
|
||||
.. _`Paul Oswald`: https://github.com/poswald
|
||||
.. _`Uros Trebec`: https://github.com/failedguidedog
|
||||
.. _Analytical: https://github.com/jkrall/analytical
|
||||
.. _`Bateau Knowledge`: http://www.bateauknowledge.nl/
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ Version 0.11.0
|
|||
--------------
|
||||
* Added support for the Spring Metrics service.
|
||||
* Allow sending events and properties to KISSmetrics (Paul Oswald).
|
||||
* Add support for the Site Speed report in Google Analytics (Uros
|
||||
Trebec).
|
||||
|
||||
Version 0.10.0
|
||||
--------------
|
||||
|
|
@ -20,8 +22,8 @@ Version 0.9.1
|
|||
Version 0.9.0
|
||||
-------------
|
||||
* Updated Clicky tracking code to support multiple site ids.
|
||||
* Fixed Chartbeat auto-domain bug when the Sites framework is not used (Eric
|
||||
Davis).
|
||||
* Fixed Chartbeat auto-domain bug when the Sites framework is not used
|
||||
(Eric Davis).
|
||||
* Improved testing code (Eric Davis).
|
||||
|
||||
Version 0.8.1
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ NO_ALLOW_HASH_CODE = "_gaq.push(['_setAllowHash', false]);"
|
|||
ALLOW_LINKER_CODE = "_gaq.push(['_setAllowLinker', true]);"
|
||||
CUSTOM_VAR_CODE = "_gaq.push(['_setCustomVar', %(index)s, '%(name)s', " \
|
||||
"'%(value)s', %(scope)s]);"
|
||||
SITE_SPEED_CODE = "_gaq.push(['_trackPageLoadTime']);"
|
||||
|
||||
|
||||
register = Library()
|
||||
|
|
@ -76,6 +77,7 @@ class GoogleAnalyticsNode(Node):
|
|||
def render(self, context):
|
||||
commands = self._get_domain_commands(context)
|
||||
commands.extend(self._get_custom_var_commands(context))
|
||||
commands.extend(self._get_other_commands(context))
|
||||
html = SETUP_CODE % {'property_id': self.property_id,
|
||||
'commands': " ".join(commands)}
|
||||
if is_internal_ip(context, 'GOOGLE_ANALYTICS'):
|
||||
|
|
@ -91,8 +93,8 @@ class GoogleAnalyticsNode(Node):
|
|||
else:
|
||||
domain = get_domain(context, 'google_analytics')
|
||||
if domain is None:
|
||||
raise AnalyticalException("tracking multiple domains with Google"
|
||||
" Analytics requires a domain name")
|
||||
raise AnalyticalException("tracking multiple domains with"
|
||||
" Google Analytics requires a domain name")
|
||||
commands.append(DOMAIN_CODE % domain)
|
||||
commands.append(NO_ALLOW_HASH_CODE)
|
||||
if tracking_type == TRACK_MULTIPLE_DOMAINS:
|
||||
|
|
@ -114,6 +116,11 @@ class GoogleAnalyticsNode(Node):
|
|||
commands.append(CUSTOM_VAR_CODE % locals())
|
||||
return commands
|
||||
|
||||
def _get_other_commands(self, context):
|
||||
commands = []
|
||||
if getattr(settings, 'GOOGLE_ANALYTICS_SITE_SPEED', False):
|
||||
commands.append(SITE_SPEED_CODE)
|
||||
return commands
|
||||
|
||||
def contribute_to_analytical(add_node):
|
||||
GoogleAnalyticsNode() # ensure properly configured
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from django.http import HttpRequest
|
|||
from django.template import Context
|
||||
|
||||
from analytical.templatetags.google_analytics import GoogleAnalyticsNode, \
|
||||
TRACK_SINGLE_DOMAIN, TRACK_MULTIPLE_DOMAINS, TRACK_MULTIPLE_SUBDOMAINS
|
||||
TRACK_SINGLE_DOMAIN, TRACK_MULTIPLE_DOMAINS, TRACK_MULTIPLE_SUBDOMAINS,\
|
||||
SCOPE_VISITOR, SCOPE_SESSION, SCOPE_PAGE
|
||||
from analytical.tests.utils import TestCase, TagTestCase, override_settings, \
|
||||
without_apps, SETTING_DELETED
|
||||
from analytical.utils import AnalyticalException
|
||||
|
|
@ -54,14 +55,27 @@ class GoogleAnalyticsTagTestCase(TagTestCase):
|
|||
self.assertTrue("_gaq.push(['_setAllowLinker', true]);" in r, r)
|
||||
|
||||
def test_custom_vars(self):
|
||||
context = Context({'google_analytics_var1': ('test1', 'foo'),
|
||||
'google_analytics_var5': ('test2', 'bar', 1)})
|
||||
context = Context({
|
||||
'google_analytics_var1': ('test1', 'foo'),
|
||||
'google_analytics_var2': ('test2', 'bar', SCOPE_VISITOR),
|
||||
'google_analytics_var4': ('test4', 'baz', SCOPE_SESSION),
|
||||
'google_analytics_var5': ('test5', 'qux', SCOPE_PAGE),
|
||||
})
|
||||
r = GoogleAnalyticsNode().render(context)
|
||||
self.assertTrue("_gaq.push(['_setCustomVar', 1, 'test1', 'foo', 3]);"
|
||||
in r, r)
|
||||
self.assertTrue("_gaq.push(['_setCustomVar', 5, 'test2', 'bar', 1]);"
|
||||
self.assertTrue("_gaq.push(['_setCustomVar', 2, 'test2', 'bar', 1]);"
|
||||
in r, r)
|
||||
self.assertTrue("_gaq.push(['_setCustomVar', 4, 'test4', 'baz', 2]);"
|
||||
in r, r)
|
||||
self.assertTrue("_gaq.push(['_setCustomVar', 5, 'test5', 'qux', 3]);"
|
||||
in r, r)
|
||||
|
||||
@override_settings(GOOGLE_ANALYTICS_SITE_SPEED=True)
|
||||
def test_track_page_load_time(self):
|
||||
r = GoogleAnalyticsNode().render(Context())
|
||||
self.assertTrue("_gaq.push(['_trackPageLoadTime']);" in r, r)
|
||||
|
||||
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
|
||||
def test_render_internal_ip(self):
|
||||
req = HttpRequest()
|
||||
|
|
|
|||
|
|
@ -99,6 +99,19 @@ or set it in the project :file:`settings.py` file using
|
|||
:const:`GOOGLE_ANALYTICS_DOMAIN` (fallback: :const:`ANALYTICAL_DOMAIN`).
|
||||
|
||||
|
||||
Tracking site speed
|
||||
-------------------
|
||||
|
||||
You can view page load times in the `Site Speed report`_ by setting the
|
||||
:const:`GOOGLE_ANALYTICS_SITE_SPEED` configuration setting::
|
||||
|
||||
GOOGLE_ANALYTICS_SITE_SPEED = True
|
||||
|
||||
By default, page load times are not tracked.
|
||||
|
||||
.. _`Site Speed report`: http://www.google.com/support/analyticshelp/bin/answer.py?answer=1205784&topic=1282106
|
||||
|
||||
|
||||
.. _google-analytics-internal-ips:
|
||||
|
||||
Internal IP addresses
|
||||
|
|
|
|||
Loading…
Reference in a new issue