mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
This commit is contained in:
commit
3eb0ba07f9
3 changed files with 35 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -110,6 +110,27 @@ 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 alias API`: http://support.kissmetrics.com/apis/common-methods#alias
|
||||
|
||||
Recording events
|
||||
----------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue