mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Update mixpanel to latest code.
This commit is contained in:
parent
d89b9f56af
commit
8cdd68011e
3 changed files with 12 additions and 14 deletions
|
|
@ -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 = """
|
||||
<script type="text/javascript">
|
||||
var mpq = [];
|
||||
mpq.push(['init', '%(token)s']);
|
||||
(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.0.min.js';d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f?g=a[f]=[]:f="mixpanel";g.people=g.people||[];h=['disable','track','track_pageview','track_links','track_forms','register','register_once','unregister','identify','name_tag','set_config','people.set','people.increment'];for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.1;})(document,window.mixpanel||[]);
|
||||
mixpanel.init('%(token)s');
|
||||
%(commands)s
|
||||
(function(){var b,a,e,d,c;b=document.createElement("script");b.type="text/javascript";b.async=true;b.src=(document.location.protocol==="https:"?"https:":"http:")+"//api.mixpanel.com/site_media/js/api/mixpanel.js";a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(b,a);e=function(f){return function(){mpq.push([f].concat(Array.prototype.slice.call(arguments,0)))}};d=["init","track","track_links","track_forms","register","register_once","identify","name_tag","set_config"];for(c=0;c<d.length;c++){mpq[d[c]]=e(d[c])}})();
|
||||
</script>
|
||||
"""
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue