diff --git a/analytical/templatetags/spring_metrics.py b/analytical/templatetags/spring_metrics.py index 26633eb..afafab9 100644 --- a/analytical/templatetags/spring_metrics.py +++ b/analytical/templatetags/spring_metrics.py @@ -18,7 +18,6 @@ TRACKING_CODE = """ """ @@ -74,8 +74,12 @@ class SpringMetricsNode(Node): return html def _generate_custom_javascript(self, vars): - commands = ("_springMetq.push(['%s', '%s']);" % (var, val) - for var, val in vars.items()) + commands = [] + convert = vars.pop('convert', None) + if convert is not None: + commands.append("_springMetq.push(['convert', '%s'])" % convert) + commands.extend("_springMetq.push(['setdata', {'%s': '%s'}]);" + % (var, val) for var, val in vars.items()) return " ".join(commands) diff --git a/analytical/tests/test_tag_spring_metrics.py b/analytical/tests/test_tag_spring_metrics.py index 0de0804..2bac026 100644 --- a/analytical/tests/test_tag_spring_metrics.py +++ b/analytical/tests/test_tag_spring_metrics.py @@ -40,13 +40,16 @@ class SpringMetricsTagTestCase(TagTestCase): def test_identify(self): r = SpringMetricsNode().render(Context({'user': User(email='test@test.com')})) - self.assertTrue("_springMetq.push(['email', 'test@test.com']);" in r, r) + self.assertTrue("_springMetq.push(['setdata', " + "{'email': 'test@test.com'}]);" in r, r) def test_custom(self): r = SpringMetricsNode().render(Context({'spring_metrics_var1': 'val1', 'spring_metrics_var2': 'val2'})) - self.assertTrue("_springMetq.push(['var1', 'val1']);" in r, r) - self.assertTrue("_springMetq.push(['var2', 'val2']);" in r, r) + self.assertTrue("_springMetq.push(['setdata', {'var1': 'val1'}]);" in r, + r) + self.assertTrue("_springMetq.push(['setdata', {'var2': 'val2'}]);" in r, + r) @override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1']) def test_render_internal_ip(self): diff --git a/docs/services/spring_metrics.rst b/docs/services/spring_metrics.rst index c9937a3..d40fcf6 100644 --- a/docs/services/spring_metrics.rst +++ b/docs/services/spring_metrics.rst @@ -44,8 +44,8 @@ Configuration ============= Before you can use the Spring Metrics integration, you must first set -your website Tracking ID. You can also customize the data that Spring -Metrics tracks. +your website Tracking ID and tag a page for conversion. You can also +customize the data that Spring Metrics tracks. Setting the Tracking ID @@ -53,7 +53,7 @@ Setting the Tracking ID Every website you track with Spring Metrics gets its own Tracking ID, and the :ttag:`spring_metrics` tag will include it in the rendered -Javascript code. You can find the Tracking ID in the `manage page`_ +Javascript code. You can find the Tracking ID in the `Site Settings`_ of your Spring Metrics account. Set :const:`SPRING_METRICS_TRACKING_ID` in the project :file:`settings.py` file:: @@ -64,16 +64,24 @@ If you do not set a Tracking ID, the tracking code will not be rendered. .. _`manage page`: https://app.springmetrics.com/manage/ -Internal IP addresses ---------------------- +.. _`Convertion Tagging`: -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:`SPRING_METRICS_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. +Tagging conversion +------------------ + +In order to make use of Spring Metrics, you must tell it when visitors +become customers. This is called conversion. Usually, it marked by +the client requesting a specific page, such as the "thank you" page +of a webshop checkout. You tag these pages in the `Site Settings`_ +of your Spring Metrics account. + +Alternatively, you can mark conversion pages using the +:data:`spring_metrics_convert` template context variable:: + + context = RequestContext({'spring_metrics_convert': 'mailinglist signup'}) + return some_template.render(context) + +.. _`Site Settings`: https://app.springmetrics.com/manage Tracking revenue @@ -85,9 +93,15 @@ can let the :ttag:`spring_metrics` tag pass earned revenue to Spring Metrics. You can set the context variable in your view when you render a template containing thetracking code:: - context = RequestContext({'spring_metrics_revenue': '30.53'}) + context = RequestContext({ + 'spring_metrics_convert': 'sale', + 'spring_metrics_revenue': '30.53', + }) return some_template.render(context) +(You would not need to use the :data:`spring_metrics_convert` variable +if you already tagged the page in Spring Metrics.) + Custom data ----------- @@ -128,6 +142,18 @@ explicitly, the e-mail address of an authenticated user is passed to Spring Metrics automatically. See :ref:`identifying-visitors`. +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:`SPRING_METRICS_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. + + ---- Thanks go to Spring Metrics for their support with the development of