Merge pull request #91 from bittner/feature/remove-obsolete-reinvigorate-net

Remove Reinvigorate template tag, tests and docs
This commit is contained in:
Joost Cassee 2016-05-19 10:09:30 +02:00
commit 4ceb9aa2f1
6 changed files with 37 additions and 341 deletions

View file

@ -90,7 +90,6 @@ Currently Supported Services
.. _`Optimizely`: http://www.optimizely.com/
.. _`Performable`: http://www.performable.com/
.. _`Piwik`: http://www.piwik.org/
.. _`Reinvigorate`: http://www.reinvigorate.net/
.. _`SnapEngage`: http://www.snapengage.com/
.. _`Spring Metrics`: http://www.springmetrics.com/
.. _`UserVoice`: http://www.uservoice.com/

View file

@ -8,10 +8,8 @@ import logging
from django import template
from django.template import Node, TemplateSyntaxError
try:
from importlib import import_module
except ImportError: # Python 2.6
from django.utils.importlib import import_module
from importlib import import_module
from analytical.utils import AnalyticalException
@ -34,7 +32,6 @@ TAG_MODULES = [
'analytical.optimizely',
'analytical.performable',
'analytical.piwik',
'analytical.reinvigorate',
'analytical.snapengage',
'analytical.spring_metrics',
'analytical.uservoice',

View file

@ -1,81 +0,0 @@
"""
Reinvigorate template tags and filters.
"""
from __future__ import absolute_import
import json
import re
from django.template import Library, Node, TemplateSyntaxError
from analytical.utils import get_identity, is_internal_ip, disable_html, \
get_required_setting
TRACKING_ID_RE = re.compile(r'^[\w\d]+-[\w\d]+$')
TRACKING_CODE = """
<script type="text/javascript">
document.write(unescape("%%3Cscript src='" + (("https:" == document.location.protocol) ? "https://ssl-" : "http://") + "include.reinvigorate.net/re_.js' type='text/javascript'%%3E%%3C/script%%3E"));
</script>
<script type="text/javascript">
try {
%(tags)s
reinvigorate.track("%(tracking_id)s");
} catch(err) {}
</script>
"""
register = Library()
@register.tag
def reinvigorate(parser, token):
"""
Reinvigorate tracking template tag.
Renders Javascript code to track page visits. You must supply
your Reinvigorate tracking ID (as a string) in the
``REINVIGORATE_TRACKING_ID`` setting.
"""
bits = token.split_contents()
if len(bits) > 1:
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return ReinvigorateNode()
class ReinvigorateNode(Node):
def __init__(self):
self.tracking_id = get_required_setting('REINVIGORATE_TRACKING_ID',
TRACKING_ID_RE,
"must be a string looking like XXXXX-XXXXXXXXXX")
def render(self, context):
re_vars = {}
for dict_ in context:
for var, val in dict_.items():
if var.startswith('reinvigorate_'):
re_vars[var[13:]] = val
if 'name' not in re_vars:
identity = get_identity(context, 'reinvigorate',
lambda u: u.get_full_name())
if identity is not None:
re_vars['name'] = identity
if 'context' not in re_vars:
email = get_identity(context, 'reinvigorate', lambda u: u.email)
if email is not None:
re_vars['context'] = email
tags = " ".join("var re_%s_tag = %s;" % (tag, json.dumps(value, sort_keys=True))
for tag, value in re_vars.items())
html = TRACKING_CODE % {'tracking_id': self.tracking_id,
'tags': tags}
if is_internal_ip(context, 'REINVIGORATE'):
html = disable_html(html, 'Reinvigorate')
return html
def contribute_to_analytical(add_node):
ReinvigorateNode() # ensure properly configured
add_node('body_bottom', ReinvigorateNode)

View file

@ -1,67 +0,0 @@
"""
Tests for the Reinvigorate template tags and filters.
"""
import re
from django.contrib.auth.models import User, AnonymousUser
from django.http import HttpRequest
from django.template import Context
from django.test.utils import override_settings
from analytical.templatetags.reinvigorate import ReinvigorateNode
from analytical.tests.utils import TagTestCase
from analytical.utils import AnalyticalException
@override_settings(REINVIGORATE_TRACKING_ID='12345-abcdefghij')
class ReinvigorateTagTestCase(TagTestCase):
"""
Tests for the ``reinvigorate`` template tag.
"""
def test_tag(self):
r = self.render_tag('reinvigorate', 'reinvigorate')
self.assertTrue('reinvigorate.track("12345-abcdefghij");' in r, r)
def test_node(self):
r = ReinvigorateNode().render(Context({}))
self.assertTrue('reinvigorate.track("12345-abcdefghij");' in r, r)
@override_settings(REINVIGORATE_TRACKING_ID=None)
def test_no_tracking_id(self):
self.assertRaises(AnalyticalException, ReinvigorateNode)
@override_settings(REINVIGORATE_TRACKING_ID='123abc')
def test_wrong_tracking_id(self):
self.assertRaises(AnalyticalException, ReinvigorateNode)
@override_settings(ANALYTICAL_AUTO_IDENTIFY=True)
def test_identify(self):
r = ReinvigorateNode().render(Context({'user':
User(username='test', first_name='Test', last_name='User',
email='test@example.com')}))
self.assertTrue('var re_name_tag = "Test User";' in r, r)
self.assertTrue('var re_context_tag = "test@example.com";' in r, r)
@override_settings(ANALYTICAL_AUTO_IDENTIFY=True)
def test_identify_anonymous_user(self):
r = ReinvigorateNode().render(Context({'user': AnonymousUser()}))
self.assertFalse('var re_name_tag = ' in r, r)
self.assertFalse('var re_context_tag = ' in r, r)
def test_tags(self):
r = ReinvigorateNode().render(Context({'reinvigorate_var1': 'val1',
'reinvigorate_var2': 2}))
self.assertTrue(re.search('var re_var1_tag = "val1";', r), r)
self.assertTrue(re.search('var re_var2_tag = 2;', r), r)
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
def test_render_internal_ip(self):
req = HttpRequest()
req.META['REMOTE_ADDR'] = '1.1.1.1'
context = Context({'request': req})
r = ReinvigorateNode().render(context)
self.assertTrue(r.startswith(
'<!-- Reinvigorate disabled on internal IP address'), r)
self.assertTrue(r.endswith('-->'), r)

View file

@ -20,23 +20,29 @@ Installing the Python package
To install django-analytical the ``analytical`` package must be added to
the Python path. You can install it directly from PyPI using
``easy_install``::
``easy_install``:
$ easy_install django-analytical
.. code-block:: bash
$ easy_install django-analytical
You can also install directly from source. Download either the latest
stable version from PyPI_ or any release from GitHub_, or use Git to
get the development code::
get the development code:
$ git clone https://github.com/jcassee/django-analytical.git
.. code-block:: bash
$ git clone https://github.com/jcassee/django-analytical.git
.. _PyPI: http://pypi.python.org/pypi/django-analytical/
.. _GitHub: http://github.com/jcassee/django-analytical
Then install the package by running the setup script::
Then install the package by running the setup script:
$ cd django-analytical
$ python setup.py install
.. code-block::
$ cd django-analytical
$ python setup.py install
.. _installing-the-application:
@ -46,13 +52,15 @@ Installing the Django application
After you installed django-analytical, add the ``analytical`` Django
application to the list of installed applications in the ``settings.py``
file of your project::
file of your project:
INSTALLED_APPS = [
...
'analytical',
...
]
.. code-block:: python
INSTALLED_APPS = [
...
'analytical',
...
]
.. _adding-the-template-tags:
@ -64,7 +72,9 @@ Because every analytics service uses own specific Javascript code that
should be added to the top or bottom of either the head or body of the
HTML page, django-analytical provides four general-purpose template tags
that will render the code needed for the services you are using. Your
base template should look like this::
base template should look like this:
.. code-block:: html
{% load analytical %}
<!DOCTYPE ... >
@ -101,27 +111,27 @@ settings required to enable each service are listed here:
* :doc:`Chartbeat <services/chartbeat>`::
CHARTBEAT_USER_ID = '12345'
CHARTBEAT_USER_ID = '12345'
* :doc:`Clickmap <services/clickmap>`::
CLICKMAP_TRACKER_CODE = '12345678....912'
CLICKMAP_TRACKER_CODE = '12345678....912'
* :doc:`Clicky <services/clicky>`::
CLICKY_SITE_ID = '12345678'
CLICKY_SITE_ID = '12345678'
* :doc:`Crazy Egg <services/crazy_egg>`::
CRAZY_EGG_ACCOUNT_NUMBER = '12345678'
CRAZY_EGG_ACCOUNT_NUMBER = '12345678'
* :doc:`Gaug.es <services/gauges>`::
GAUGES_SITE_ID = '0123456789abcdef0123456789abcdef'
GAUGES_SITE_ID = '0123456789abcdef0123456789abcdef'
* :doc:`Google Analytics <services/google_analytics>`::
GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-1234567-8'
GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-1234567-8'
* :doc:`HubSpot <services/hubspot>`::
@ -134,16 +144,16 @@ settings required to enable each service are listed here:
* :doc:`KISSinsights <services/kiss_insights>`::
KISS_INSIGHTS_ACCOUNT_NUMBER = '12345'
KISS_INSIGHTS_SITE_CODE = 'abc'
KISS_INSIGHTS_ACCOUNT_NUMBER = '12345'
KISS_INSIGHTS_SITE_CODE = 'abc'
* :doc:`KISSmetrics <services/kiss_metrics>`::
KISS_METRICS_API_KEY = '0123456789abcdef0123456789abcdef01234567'
KISS_METRICS_API_KEY = '0123456789abcdef0123456789abcdef01234567'
* :doc:`Mixpanel <services/mixpanel>`::
MIXPANEL_API_TOKEN = '0123456789abcdef0123456789abcdef'
MIXPANEL_API_TOKEN = '0123456789abcdef0123456789abcdef'
* :doc:`Olark <services/olark>`::
@ -151,7 +161,7 @@ settings required to enable each service are listed here:
* :doc:`Optimizely <services/optimizely>`::
OPTIMIZELY_ACCOUNT_NUMBER = '1234567'
OPTIMIZELY_ACCOUNT_NUMBER = '1234567'
* :doc:`Performable <services/performable>`::
@ -162,15 +172,10 @@ settings required to enable each service are listed here:
PIWIK_DOMAIN_PATH = 'your.piwik.server/optional/path'
PIWIK_SITE_ID = '123'
* :doc:`Reinvigorate <services/reinvigorate>`::
REINVIGORATE_TRACKING_ID = '12345-abcdefghij'
* :doc:`Woopra <services/woopra>`::
WOOPRA_DOMAIN = 'abcde.com'
----
The django-analytical application is now set-up to track visitors. For

View file

@ -1,157 +0,0 @@
================================
Reinvigorate -- visitor tracking
================================
Reinvigorate_ gives you real-time traffic analysis, visitor activity,
search and referrer information and click heatmaps. A system tray /
system status bar application for your desktop notifies you when
interesting events occur.
.. _Reinvigorate: http://www.reinvigorate.net/
.. reinvigorate-installation:
Installation
============
To start using the Reinvigorate integration, you must have installed the
django-analytical package and have added the ``analytical`` application
to :const:`INSTALLED_APPS` in your project :file:`settings.py` file.
See :doc:`../install` for details.
Next you need to add the Reinvigorate template tag to your templates.
This step is only needed if you are not using the generic
:ttag:`analytical.*` tags. If you are, skip to
:ref:`reinvigorate-configuration`.
The Reinvigorate tracking code is inserted into templates using a
template tag. Load the :mod:`reinvigorate` template tag library and
insert the :ttag:`reinvigorate` tag. Because every page that you want
to track must have the tag, it is useful to add it to your base
template. Insert the tag somewhere within the HTML body::
{% load reinvigorate %}
...
{% reinvigorate %}
</body>
</html>
.. _reinvigorate-configuration:
Configuration
=============
Before you can use the Reinvigorate integration, you must first set your
tracking ID. You can also customize the data that Reinvigorate tracks.
.. _reinvigorate-tracking-id:
Setting the tracking ID
-----------------------
Every website you track with Reinvigorate gets a tracking ID, and the
:ttag:`reinvigorate` tag will include it in the rendered Javascript
code. You can find the tracking ID in the URL of your website report
pages. The URL looks like this:
\https://report.reinvigorate.net/accounts/XXXXX-XXXXXXXXXX/
Here, ``XXXXX-XXXXXXXXXX`` is the tracking ID. Set
:const:`REINVIGORATE_TRACKING_ID` in the project :file:`settings.py`
file::
REINVIGORATE_TRACKING_ID = 'XXXXX-XXXXXXXXXX'
If you do not set a tracking ID, the tracking code will not be rendered.
.. _reinvigorate-internal-ips:
Internal IP addresses
---------------------
Usually you do not want to track clicks from your development or
internal IP addresses. By default, if the tags detect that the client
comes from any address in the :const:`REINVIGORATE_INTERNAL_IPS`
setting, the tracking code is commented out. It takes the value of
:const:`ANALYTICAL_INTERNAL_IPS` by default (which in turn is
:const:`INTERNAL_IPS` by default). See :ref:`identifying-visitors` for
important information about detecting the visitor IP address.
.. _reinvigorate-tags:
Reinvigorate tags
-----------------
As described in the Reinvigorate *NameTags* and *Snoop* pages,
the data that is tracked by Reinvigorate can be customized by adding
*tags* to the Javascript tracking code. (These should not be confused
with Django template tags.) Using template context variables, you can
let the :ttag:`reinvigorate` template tag pass reinvigorate tags to
automatically. You can set the context variables in your view when your
render a template containing the tracking code::
context = RequestContext({'reinvigorate_purchase': True,
'reinvigorate_comment': 'Got discount'})
return some_template.render(context)
If you have tags that are generated on every page, you may want to set
them in a context processor that you add to the
:data:`TEMPLATE_CONTEXT_PROCESSORS` list in :file:`settings.py`::
def reinvigorate_tags(request):
try:
return {'name': request.user.username}
except AttributeError:
return {}
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.
Here is a table with the most important tags. All tags listed on the
Reinvigorate pages can be set by replacing ``re_XXX_tag`` with
``reinvigorate_XXX``.
========================= =============================================
Context variable Description
========================= =============================================
``reinvigorate_name`` The visitor name.
------------------------- ---------------------------------------------
``reinvigorate_context`` Some context information about the visitor,
e.g. an e-mail address.
------------------------- ---------------------------------------------
``reinvigorate_purchase`` A boolean indicating whether the visitor has
just made a purchase. Setting this variable
triggers an event in the Snoop notification
application.
------------------------- ---------------------------------------------
``reinvigorate_new_user`` A boolean indicating whether the visitor has
just registered as a new user. Setting this
variable triggers an event in the Snoop
notification application.
------------------------- ---------------------------------------------
``reinvigorate_comment`` A comment, which is included in a Snoop
event notification.
========================= =============================================
.. _reinvigorate-identify-user:
Identifying authenticated users
-------------------------------
If you have not set the ``reinvigorate_name`` context variable
explicitly, the full name of an authenticated user is passed to
Reinvigorate automatically. Similarly, the e-mail address is passed
automatically in the ``context`` tag. See :ref:`identifying-visitors`.
----
Thanks go to Reinvigorate for their support with the development of this
application.