Commits

Anonymous committed 428012a

* Adding ip property to people track

  • Participants
  • Parent commits 5b815e4

Comments (0)

Files changed (2)

pyramid_mixpanel/__init__.py

             log.exception('mixpanel track event exception: event %s; properties: %s',
                           event, properties)
 
-    def people_track(self, distinct_id, properties, action=u'$set'):
+    def people_track(self, distinct_id, properties, action=u'$set', ip='0'):
         """Create or update user in Mixpanel People.
 
         *distinct_id* must be a string and *properties* a dictionary.
         Note that Mixpanel only supports ``"$append"`` for transactions,
         and that transactions must be of the form
         ``{"$time": iso_datetime, "$amount": number}``.
+
+        *ip* is the ip of the client, if not set the 0 value will tell to
+        mixpanel to not track the ip of the client.
+        This field is mandatory to track Country/Region/City.
         """
         try:
             data = base64.b64encode(json.dumps({
                 u'$token': self.token,
                 u'$distinct_id': distinct_id,
                 action: properties,
+                '$ip': ip,
             }))
 
             response = requests.post('https://api.mixpanel.com/engage/',

pyramid_mixpanel/tests/unittests/test_pyramid_mixpanel.py

             u'$set': {
                 'whatever': u'whatevs',
             },
+            u'$ip': '0',
         }))
         m_post.assert_called_once_with('https://api.mixpanel.com/engage/',
                                        {'data': data})
         mu = MixpanelUtility({u'mixpanel.token': u'token'})
 
         mu.people_track(
-            u'some ID', {u'$transaction': transaction}, action='$append')
+            u'some ID', {u'$transaction': transaction}, action='$append', ip='127.0.0.1')
 
         data = base64.b64encode(json.dumps({
             u'$token': u'token',
             u'$append': {
                 '$transaction': transaction,
             },
+            u'$ip': '127.0.0.1',
         }))
         m_post.assert_called_once_with('https://api.mixpanel.com/engage/',
                                        {'data': data})