File: kiss_metrics.rst

package info (click to toggle)
python-django-analytical 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: python: 4,693; makefile: 7
file content (171 lines) | stat: -rw-r--r-- 5,395 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
==============================
KISSmetrics -- funnel analysis
==============================

KISSmetrics_ is an easy to implement analytics solution that provides a
powerful visual representation of your customer lifecycle.  Discover how
many visitors go from your landing page to pricing to sign up, and how
many drop out at each stage.

.. _KISSmetrics: http://www.kissmetrics.com/

.. kiss-metrics-installation:

Installation
============

To start using the KISSmetrics 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 KISSmetrics 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:`kiss-metrics-configuration`.

The KISSmetrics Javascript code is inserted into templates using a
template tag.  Load the :mod:`kiss_metrics` template tag library and
insert the :ttag:`kiss_metrics` 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 at the top of the HTML head::

    {% load kiss_metrics %}
    <html>
    <head>
    {% kiss_metrics %}
    ...


.. _kiss-metrics-configuration:

Configuration
=============

Before you can use the KISSmetrics integration, you must first set your
API key.


.. _kiss-metrics-api-key:

Setting the API key
-------------------

Every website you track events for with KISSmetrics gets its own API
key, and the :ttag:`kiss_metrics` tag will include it in the rendered
Javascript code.  You can find the website API key by visiting the
website *Product center* on your KISSmetrics dashboard.  Set
:const:`KISS_METRICS_API_KEY` in the project :file:`settings.py` file::

    KISS_METRICS_API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

If you do not set an API key, the tracking code will not be rendered.


.. _kiss-metrics-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:`KISS_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.


.. _kiss-metrics-identify-user:

Identifying users
-----------------

If your websites identifies visitors, you can pass this information on
to KISSmetrics so that you can tie events to users.  By default, the
username of an authenticated user is passed to KISSmetrics
automatically.  See :ref:`identifying-visitors`.

You can also send the visitor identity yourself by adding either the
``kiss_metrics_identity`` or the ``analytical_identity`` variable to the
template context.  If both variables are set, the former takes
precedence. For example::

    context = RequestContext({'kiss_metrics_identity': identity})
    return some_template.render(context)

If you can derive the identity from the HTTP request, you can also use
a context processor that you add to the
:data:`TEMPLATE_CONTEXT_PROCESSORS` list in :file:`settings.py`::

    def identify(request):
        try:
            return {'kiss_metrics_identity': request.user.email}
        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.


.. _kiss-metrics-alias:

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 alias API`: http://support.kissmetrics.com/apis/common-methods#alias


Recording events
----------------

You may tell KISSmetrics about an event by setting a variable in the context.

For example::

    context = RequestContext({
        'kiss_metrics_event': ['Signed Up', {'Plan' : 'Pro', 'Amount' : 9.99}],
    })
    return some_template.render(context)

The output script tag will then include the corresponding Javascript event as
documented in the `KISSmetrics record API`_ docs.


.. _kiss-metrics-properties:

Recording properties
--------------------

You may also set KISSmetrics properties without a corresponding event.

For example::

    context = RequestContext({
        'kiss_metrics_properties': {'gender': 'Male'},
    })
    return some_template.render(context)

The output script tag will then include the corresponding properties as
documented in the `KISSmetrics set API`_ docs.


.. _`KISSmetrics set API`: http://support.kissmetrics.com/apis/common-methods#record
.. _`KISSmetrics record API`: http://support.kissmetrics.com/apis/common-methods#set