From 255dd4f3873e3be1df4b634813ce12201321d89f Mon Sep 17 00:00:00 2001 From: xthepoet Date: Mon, 16 Jul 2012 01:12:52 -0400 Subject: [PATCH 01/18] added alias tag for kissmetrics --- analytical/templatetags/kiss_metrics.py | 8 ++++++++ analytical/tests/test_tag_kiss_metrics.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/analytical/templatetags/kiss_metrics.py b/analytical/templatetags/kiss_metrics.py index 40c1859..5803d4b 100644 --- a/analytical/templatetags/kiss_metrics.py +++ b/analytical/templatetags/kiss_metrics.py @@ -35,9 +35,11 @@ TRACKING_CODE = """ IDENTIFY_CODE = "_kmq.push(['identify', '%s']);" EVENT_CODE = "_kmq.push(['record', '%(name)s', %(properties)s]);" PROPERTY_CODE = "_kmq.push(['set', %(properties)s]);" +ALIAS_CODE = "_kmq.push(['alias', '%s', '%s']);" EVENT_CONTEXT_KEY = 'kiss_metrics_event' PROPERTY_CONTEXT_KEY = 'kiss_metrics_properties' +ALIAS_CONTEXT_KEY = 'kiss_metrics_alias' register = Library() @@ -67,6 +69,12 @@ class KissMetricsNode(Node): identity = get_identity(context, 'kiss_metrics') if identity is not None: commands.append(IDENTIFY_CODE % identity) + try: + properties = context[ALIAS_CONTEXT_KEY] + key, value = properties.popitem() + commands.append(ALIAS_CODE % (key,value)) + except KeyError: + pass try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, diff --git a/analytical/tests/test_tag_kiss_metrics.py b/analytical/tests/test_tag_kiss_metrics.py index b92aacc..36831d1 100644 --- a/analytical/tests/test_tag_kiss_metrics.py +++ b/analytical/tests/test_tag_kiss_metrics.py @@ -64,6 +64,12 @@ class KissMetricsTagTestCase(TagTestCase): self.assertTrue("_kmq.push(['set', " '{"prop1": "val1", "prop2": "val2"}]);' in r, r) + def test_alias(self): + r = KissMetricsNode().render(Context({'kiss_metrics_alias': + {'test': 'test_alias'}})) + self.assertTrue("_kmq.push(['alias', 'test', 'test_alias']);" in r,r) + + @override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1']) def test_render_internal_ip(self): req = HttpRequest() From d38d30c846c62fb0c4ec3339983107890df38b89 Mon Sep 17 00:00:00 2001 From: Piet Delport Date: Thu, 2 Aug 2012 12:14:21 +0200 Subject: [PATCH 02/18] Fix typo. --- docs/services/google_analytics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/services/google_analytics.rst b/docs/services/google_analytics.rst index cfebdd0..7e2d892 100644 --- a/docs/services/google_analytics.rst +++ b/docs/services/google_analytics.rst @@ -151,7 +151,7 @@ Constant Value Description ================= ====== ============================================= ``SCOPE_VISITOR`` 1 Distinguishes categories of visitors across multiple sessions. -``SCOPE_SESSION`` 2 Ddistinguishes different visitor experiences +``SCOPE_SESSION`` 2 Distinguishes different visitor experiences across sessions. ``SCOPE_PAGE`` 3 Defines page-level activity. ================= ====== ============================================= From 5a1cceced4a23d1f4759fb77d40a8382bbb71942 Mon Sep 17 00:00:00 2001 From: Piet Delport Date: Thu, 2 Aug 2012 12:23:21 +0200 Subject: [PATCH 03/18] Tox: Update for Django 1.4. --- tox.ini | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 1585489..d4581a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = - py2.6-django1.2,py2.6-django1.3, - py2.7-django1.2,py2.7-django1.3 + py2.6-django1.2,py2.6-django1.3,py2.6-django1.4, + py2.7-django1.2,py2.7-django1.3,py2.7-django1.4, [testenv] commands = python -Wall setup.py test @@ -12,7 +12,11 @@ deps = Django>=1.2,<1.3 [testenv:py2.6-django1.3] basepython = python2.6 -deps = Django>=1.3 +deps = Django>=1.3,<1.4 + +[testenv:py2.6-django1.4] +basepython = python2.6 +deps = Django>=1.4,<1.5 [testenv:py2.7-django1.2] basepython = python2.7 @@ -20,4 +24,8 @@ deps = Django>=1.2,<1.3 [testenv:py2.7-django1.3] basepython = python2.7 -deps = Django>=1.3 +deps = Django>=1.3,<1.4 + +[testenv:py2.7-django1.4] +basepython = python2.7 +deps = Django>=1.4,<1.5 From 9b83ef1c3ed24000db17cc5df0ec3320da937eab Mon Sep 17 00:00:00 2001 From: Piet Delport Date: Mon, 13 Aug 2012 12:30:47 +0200 Subject: [PATCH 04/18] Fix name: django-analytics -> django-analytical --- docs/index.rst | 2 +- docs/install.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 54d4448..c0704fb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -18,7 +18,7 @@ Overview :start-after: Django_ project. :end-before: Currently supported services: -To get a feel of how django-analytics works, check out the +To get a feel of how django-analytical works, check out the :doc:`tutorial`. diff --git a/docs/install.rst b/docs/install.rst index 2d3e24f..f058c40 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -160,6 +160,6 @@ settings required to enable each service are listed here: ---- -The django-analytics application is now set-up to track visitors. For +The django-analytical application is now set-up to track visitors. For information about further configuration and customization, see :doc:`features`. From 1c9e478cc9235195d831508e13b7169dda2303ac Mon Sep 17 00:00:00 2001 From: Piet Delport Date: Mon, 13 Aug 2012 13:09:35 +0200 Subject: [PATCH 05/18] Add SECRET_KEY to the test settings. Running without a SECRET_KEY becomes a DeprecationWarning in Django 1.4, and will start raising an ImproperlyConfigured error in Django 1.5. Details: https://docs.djangoproject.com/en/1.4/releases/1.4/#secret-key-setting-is-required --- analytical/tests/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analytical/tests/settings.py b/analytical/tests/settings.py index 05b2b6c..9c86335 100644 --- a/analytical/tests/settings.py +++ b/analytical/tests/settings.py @@ -12,3 +12,5 @@ DATABASES = { INSTALLED_APPS = [ 'analytical', ] + +SECRET_KEY = 'testing' From f96df3d8c649b0d1b569492e666539b27091ecf3 Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Mon, 13 Aug 2012 14:43:47 +0200 Subject: [PATCH 06/18] Update changelog --- AUTHORS.rst | 5 +++-- CHANGELOG.rst | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 7b93fa8..a97c052 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,6 +1,6 @@ The django-analytical package was written by `Joost Cassee`_, with contributions from `Eric Davis`_, `Paul Oswald`_, `Uros Trebec`_, -`Steven Skoczen`_ and others. +`Steven Skoczen`_ `Piet Delport`_ and others. Included Javascript code snippets for integration of the analytics services were written by the respective service providers. @@ -14,6 +14,7 @@ The work on Crazy Egg was made possible by `Bateau Knowledge`_. .. _`Eric Davis`: https://github.com/edavis .. _`Paul Oswald`: https://github.com/poswald .. _`Uros Trebec`: https://github.com/failedguidedog -.. _`Steven Skoczen`: https://github.com/https://github.com/skoczen +.. _`Steven Skoczen`: https://github.com/skoczen +.. _`Piet Delport`: https://github.com/pjdelport .. _Analytical: https://github.com/jkrall/analytical .. _`Bateau Knowledge`: http://www.bateauknowledge.nl/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 32903c0..e4f68ad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,7 @@ +Development +----------- +* Update testing code for Django 1.4 (Piet Delport) + Version 0.12.0 -------------- * Add support for the UserVoice service. From d12bb6de2dacbe445980eb99458ea483e987261b Mon Sep 17 00:00:00 2001 From: xthepoet Date: Mon, 13 Aug 2012 08:17:56 -0700 Subject: [PATCH 07/18] Update docs/services/kiss_metrics.rst --- docs/services/kiss_metrics.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/services/kiss_metrics.rst b/docs/services/kiss_metrics.rst index 91932e5..7b98895 100644 --- a/docs/services/kiss_metrics.rst +++ b/docs/services/kiss_metrics.rst @@ -110,6 +110,26 @@ context processor, the latter clobbers the former. .. _kiss-metrics-event: +Alias +----- + +Alias is used to associate one identity with another. +This most likely will occur if a user is not signed in yet, +you assign them an anonymous identity and record activity for them +and they later sign in and you get a named identity. + +For example:: + context = RequestContext({ + 'kiss_metrics_alias': {'my_registered@email' : 'my_user_id'}, + }) + return some_template.render(context) + +The output script tag will then include the corresponding properties as +documented in the `KISSmetrics alias API`_ docs. + + +.. _`KISSmetrics set API`: http://support.kissmetrics.com/apis/common-methods#alias + Recording events ---------------- From 9031022553c682c33c3d19efe128217aa27b4f23 Mon Sep 17 00:00:00 2001 From: xthepoet Date: Mon, 13 Aug 2012 08:21:46 -0700 Subject: [PATCH 08/18] Update docs/services/kiss_metrics.rst --- docs/services/kiss_metrics.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/services/kiss_metrics.rst b/docs/services/kiss_metrics.rst index 7b98895..7ed8590 100644 --- a/docs/services/kiss_metrics.rst +++ b/docs/services/kiss_metrics.rst @@ -119,6 +119,7 @@ you assign them an anonymous identity and record activity for them and they later sign in and you get a named identity. For example:: + context = RequestContext({ 'kiss_metrics_alias': {'my_registered@email' : 'my_user_id'}, }) @@ -128,7 +129,7 @@ The output script tag will then include the corresponding properties as documented in the `KISSmetrics alias API`_ docs. -.. _`KISSmetrics set API`: http://support.kissmetrics.com/apis/common-methods#alias +.. _`KISSmetrics alias API`: http://support.kissmetrics.com/apis/common-methods#alias Recording events ---------------- From 652a0845324df80ba8003262bc5d6d791b38c3a5 Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Tue, 14 Aug 2012 08:46:35 +0200 Subject: [PATCH 09/18] Update changelog --- AUTHORS.rst | 3 ++- CHANGELOG.rst | 1 + docs/services/kiss_metrics.rst | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index a97c052..c95192b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,6 +1,6 @@ The django-analytical package was written by `Joost Cassee`_, with contributions from `Eric Davis`_, `Paul Oswald`_, `Uros Trebec`_, -`Steven Skoczen`_ `Piet Delport`_ and others. +`Steven Skoczen`_, `Piet Delport`_, `Sandra Mau`_ and others. Included Javascript code snippets for integration of the analytics services were written by the respective service providers. @@ -16,5 +16,6 @@ The work on Crazy Egg was made possible by `Bateau Knowledge`_. .. _`Uros Trebec`: https://github.com/failedguidedog .. _`Steven Skoczen`: https://github.com/skoczen .. _`Piet Delport`: https://github.com/pjdelport +.. _`Sandra Mau`: https://github.com/xthepoet .. _Analytical: https://github.com/jkrall/analytical .. _`Bateau Knowledge`: http://www.bateauknowledge.nl/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e4f68ad..b752682 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,6 @@ Development ----------- +* Add support for the KISSmetrics alias feature (Sandra Mau) * Update testing code for Django 1.4 (Piet Delport) Version 0.12.0 diff --git a/docs/services/kiss_metrics.rst b/docs/services/kiss_metrics.rst index 7ed8590..629709a 100644 --- a/docs/services/kiss_metrics.rst +++ b/docs/services/kiss_metrics.rst @@ -108,7 +108,8 @@ Just remember that if you set the same context variable in the :class:`~django.template.context.RequestContext` constructor and in a context processor, the latter clobbers the former. -.. _kiss-metrics-event: + +.. _kiss-metrics-alias: Alias ----- @@ -128,9 +129,9 @@ For example:: The output script tag will then include the corresponding properties as documented in the `KISSmetrics alias API`_ docs. - .. _`KISSmetrics alias API`: http://support.kissmetrics.com/apis/common-methods#alias + Recording events ---------------- From 60f32daf0790c7e4d4b4a0c1df88cb848230e16a Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Tue, 14 Aug 2012 08:48:21 +0200 Subject: [PATCH 10/18] Update Sphinx link to Django docs to 1.4 --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 19932ef..47f1ef6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ pygments_style = 'sphinx' intersphinx_mapping = { 'http://docs.python.org/2.6': None, - 'http://docs.djangoproject.com/en/1.3': 'http://docs.djangoproject.com/en/1.3/_objects/', + 'http://docs.djangoproject.com/en/1.3': 'http://docs.djangoproject.com/en/1.4/_objects/', } From d89b9f56afcc946717dd3a314adf59b36bd99b1c Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Tue, 14 Aug 2012 08:51:13 +0200 Subject: [PATCH 11/18] Bump version --- CHANGELOG.rst | 4 ++-- analytical/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b752682..a5597eb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,5 @@ -Development ------------ +Version 0.13.0 +-------------- * Add support for the KISSmetrics alias feature (Sandra Mau) * Update testing code for Django 1.4 (Piet Delport) diff --git a/analytical/__init__.py b/analytical/__init__.py index 9b6827f..51e07df 100644 --- a/analytical/__init__.py +++ b/analytical/__init__.py @@ -10,6 +10,6 @@ Django_ project. See the ``docs`` directory for more information. __author__ = "Joost Cassee" __email__ = "joost@cassee.net" -__version__ = "0.12.1" -__copyright__ = "Copyright (C) 2011 Joost Cassee and others" +__version__ = "0.13.0" +__copyright__ = "Copyright (C) 2011-2012 Joost Cassee and others" __license__ = "MIT License" From 8cdd68011ea21374e021383af8b91cc3e5fd0d43 Mon Sep 17 00:00:00 2001 From: Simon Ye Date: Fri, 17 Aug 2012 19:09:20 -0700 Subject: [PATCH 12/18] Update mixpanel to latest code. --- analytical/templatetags/mixpanel.py | 9 ++++----- analytical/tests/test_tag_mixpanel.py | 14 +++++++------- docs/services/mixpanel.rst | 3 +-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/analytical/templatetags/mixpanel.py b/analytical/templatetags/mixpanel.py index 8ac2f70..d590f78 100644 --- a/analytical/templatetags/mixpanel.py +++ b/analytical/templatetags/mixpanel.py @@ -16,14 +16,13 @@ from analytical.utils import is_internal_ip, disable_html, get_identity, \ MIXPANEL_API_TOKEN_RE = re.compile(r'^[0-9a-f]{32}$') TRACKING_CODE = """ """ -IDENTIFY_CODE = "mpq.push(['identify', '%s']);" -EVENT_CODE = "mpq.push(['track', '%(name)s', %(properties)s]);" +IDENTIFY_CODE = "mixpanel.register_once({distinct_id: '%s'});" +EVENT_CODE = "mixpanel.track('%(name)s', %(properties)s);" EVENT_CONTEXT_KEY = 'mixpanel_event' register = Library() diff --git a/analytical/tests/test_tag_mixpanel.py b/analytical/tests/test_tag_mixpanel.py index d7132b5..3f61485 100644 --- a/analytical/tests/test_tag_mixpanel.py +++ b/analytical/tests/test_tag_mixpanel.py @@ -20,13 +20,13 @@ class MixpanelTagTestCase(TagTestCase): def test_tag(self): r = self.render_tag('mixpanel', 'mixpanel') self.assertTrue( - "mpq.push(['init', '0123456789abcdef0123456789abcdef']);" in r, + "mixpanel.init('0123456789abcdef0123456789abcdef');" in r, r) def test_node(self): r = MixpanelNode().render(Context()) self.assertTrue( - "mpq.push(['init', '0123456789abcdef0123456789abcdef']);" in r, + "mixpanel.init('0123456789abcdef0123456789abcdef');" in r, r) @override_settings(MIXPANEL_API_TOKEN=SETTING_DELETED) @@ -44,18 +44,18 @@ class MixpanelTagTestCase(TagTestCase): @override_settings(ANALYTICAL_AUTO_IDENTIFY=True) def test_identify(self): r = MixpanelNode().render(Context({'user': User(username='test')})) - self.assertTrue("mpq.push(['identify', 'test']);" in r, r) + self.assertTrue("mixpanel.register_once({distinct_id: 'test'});" in r, r) @override_settings(ANALYTICAL_AUTO_IDENTIFY=True) def test_identify_anonymous_user(self): r = MixpanelNode().render(Context({'user': AnonymousUser()})) - self.assertFalse("mpq.push(['identify', " in r, r) + self.assertFalse("mixpanel.register_once({distinct_id:" in r, r) def test_event(self): r = MixpanelNode().render(Context({'mixpanel_event': - ('test_event', {'prop1': 'val1', 'prop2': 'val2'})})) - self.assertTrue("mpq.push(['track', 'test_event', " - '{"prop1": "val1", "prop2": "val2"}]);' in r, r) + ('test_event', {'prop1': 'val1', 'prop2': 'val2'})})) + self.assertTrue("mixpanel.track('test_event', " + '{"prop1": "val1", "prop2": "val2"});' in r, r) @override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1']) def test_render_internal_ip(self): diff --git a/docs/services/mixpanel.rst b/docs/services/mixpanel.rst index 70f4488..980f22f 100644 --- a/docs/services/mixpanel.rst +++ b/docs/services/mixpanel.rst @@ -124,8 +124,7 @@ notation, as described in the section titled `"Asynchronous Tracking with Javascript"`_ in the Mixpanel documentation. For example:: - mpq.push(["track", "play-game", {"level": "12", "weapon": "sword", "character": "knight"}]); + mixpanel.track("play-game", {"level": "12", "weapon": "sword", "character": "knight"}); .. _django-celery: http://github.com/winhamwr/mixpanel-celery .. _`"Asynchronous Tracking with Javascript"`: http://mixpanel.com/api/docs/guides/integration/js#async - From a66346319822b012d76a4e68689881f945d6e947 Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Sun, 19 Aug 2012 22:11:27 +0200 Subject: [PATCH 13/18] Update changelog and bump version --- AUTHORS.rst | 3 ++- CHANGELOG.rst | 4 ++++ analytical/__init__.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index c95192b..b27de56 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,6 +1,6 @@ The django-analytical package was written by `Joost Cassee`_, with contributions from `Eric Davis`_, `Paul Oswald`_, `Uros Trebec`_, -`Steven Skoczen`_, `Piet Delport`_, `Sandra Mau`_ and others. +`Steven Skoczen`_, `Piet Delport`_, `Sandra Mau`_, `Simon Ye`_ and others. Included Javascript code snippets for integration of the analytics services were written by the respective service providers. @@ -17,5 +17,6 @@ The work on Crazy Egg was made possible by `Bateau Knowledge`_. .. _`Steven Skoczen`: https://github.com/skoczen .. _`Piet Delport`: https://github.com/pjdelport .. _`Sandra Mau`: https://github.com/xthepoet +.. _`Simon Ye`: https://github.com/yesimon .. _Analytical: https://github.com/jkrall/analytical .. _`Bateau Knowledge`: http://www.bateauknowledge.nl/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a5597eb..4dd189d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,7 @@ +Version 0.14.0 +-------------- +* Update mixpanel integration to latest code (Simon Ye) + Version 0.13.0 -------------- * Add support for the KISSmetrics alias feature (Sandra Mau) diff --git a/analytical/__init__.py b/analytical/__init__.py index 51e07df..02fddf8 100644 --- a/analytical/__init__.py +++ b/analytical/__init__.py @@ -10,6 +10,6 @@ Django_ project. See the ``docs`` directory for more information. __author__ = "Joost Cassee" __email__ = "joost@cassee.net" -__version__ = "0.13.0" +__version__ = "0.14.0" __copyright__ = "Copyright (C) 2011-2012 Joost Cassee and others" __license__ = "MIT License" From 2d5f8dd220a40a588d2d16f6271f56df579ea1a5 Mon Sep 17 00:00:00 2001 From: Sid Mitra Date: Thu, 4 Oct 2012 09:36:09 +0530 Subject: [PATCH 14/18] Upgrading mixpanel js script code to v2.1 --- analytical/templatetags/mixpanel.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/analytical/templatetags/mixpanel.py b/analytical/templatetags/mixpanel.py index d590f78..5c12bbc 100644 --- a/analytical/templatetags/mixpanel.py +++ b/analytical/templatetags/mixpanel.py @@ -16,9 +16,10 @@ from analytical.utils import is_internal_ip, disable_html, get_identity, \ MIXPANEL_API_TOKEN_RE = re.compile(r'^[0-9a-f]{32}$') TRACKING_CODE = """ """ IDENTIFY_CODE = "mixpanel.register_once({distinct_id: '%s'});" From 0754b5fd475c8a76d21ef0692415e68e2b5ff40c Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Thu, 18 Oct 2012 09:39:31 +0200 Subject: [PATCH 15/18] Add note on identifying users in installation docs --- docs/install.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/install.rst b/docs/install.rst index f058c40..8be6bee 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -161,5 +161,5 @@ settings required to enable each service are listed here: ---- The django-analytical application is now set-up to track visitors. For -information about further configuration and customization, see -:doc:`features`. +information about identifying users, further configuration and +customization, see :doc:`features`. From 2fd6dc1f77138e767ae44d209e387e88461bdce3 Mon Sep 17 00:00:00 2001 From: Tinnet Coronam Date: Mon, 14 Jan 2013 09:18:27 +0100 Subject: [PATCH 16/18] add ip anonymization setting to google analytics --- analytical/templatetags/google_analytics.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analytical/templatetags/google_analytics.py b/analytical/templatetags/google_analytics.py index 375a4e8..5e57a0b 100644 --- a/analytical/templatetags/google_analytics.py +++ b/analytical/templatetags/google_analytics.py @@ -50,6 +50,7 @@ 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']);" +ANONYMIZE_IP_CODE = "_gaq.push (['_gat._anonymizeIp']);" register = Library() @@ -120,6 +121,8 @@ class GoogleAnalyticsNode(Node): commands = [] if getattr(settings, 'GOOGLE_ANALYTICS_SITE_SPEED', False): commands.append(SITE_SPEED_CODE) + if getattr(settings, 'GOOGLE_ANALYTICS_ANONYMIZE_IP', False): + commands.append(ANONYMIZE_IP_CODE) return commands def contribute_to_analytical(add_node): From f4f99f6d6d3e6344bdd5ad1272808038c2acd73a Mon Sep 17 00:00:00 2001 From: Tinnet Coronam Date: Mon, 14 Jan 2013 09:25:31 +0100 Subject: [PATCH 17/18] add test for ip anonymization --- analytical/tests/test_tag_google_analytics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/analytical/tests/test_tag_google_analytics.py b/analytical/tests/test_tag_google_analytics.py index c833bf3..3b858e6 100644 --- a/analytical/tests/test_tag_google_analytics.py +++ b/analytical/tests/test_tag_google_analytics.py @@ -86,6 +86,15 @@ class GoogleAnalyticsTagTestCase(TagTestCase): ''), r) + @override_settings(GOOGLE_ANALYTICS_ANONYMIZE_IP=True) + def test_anonymize_ip(self): + r = GoogleAnalyticsNode().render(Context()) + self.assertTrue("_gaq.push (['_gat._anonymizeIp']);" in r, r) + + @override_settings(GOOGLE_ANALYTICS_ANONYMIZE_IP=False) + def test_anonymize_ip_not_present(self): + r = GoogleAnalyticsNode().render(Context()) + self.assertFalse("_gaq.push (['_gat._anonymizeIp']);" in r, r) @without_apps('django.contrib.sites') @override_settings(GOOGLE_ANALYTICS_PROPERTY_ID='UA-123456-7', From a88d7272a6cd7a1c5db69048cb483065784bffbe Mon Sep 17 00:00:00 2001 From: Tinnet Coronam Date: Fri, 8 Mar 2013 16:04:12 +0100 Subject: [PATCH 18/18] added documentation for ANONYMIZE_IP --- docs/services/google_analytics.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/services/google_analytics.rst b/docs/services/google_analytics.rst index 7e2d892..7136ee4 100644 --- a/docs/services/google_analytics.rst +++ b/docs/services/google_analytics.rst @@ -172,3 +172,21 @@ Just remember that if you set the same context variable in the context processor, the latter clobbers the former. .. _`custom variables`: http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html + + +.. _google-analytics-anonimyze-ips: + +Anonymize IPs +---------------- + +You can enable the `IP anonymization`_ feature by setting the +:const:`GOOGLE_ANALYTICS_ANONYMIZE_IP` configuration setting:: + + GOOGLE_ANALYTICS_ANONYMIZE_IP = True + +This may be mandatory for deployments in countries that have a firm policies +concerning data privacy (e.g. Germany). + +By default, IPs are not anonymized. + +.. _`IP anonymization`: https://support.google.com/analytics/bin/answer.py?hl=en&answer=2763052 \ No newline at end of file