Commit ca6633bd by Bill DeRusha

Add IP to all python Segment tracking calls

parent e0c430ff
...@@ -1062,6 +1062,7 @@ class CourseEnrollment(models.Model): ...@@ -1062,6 +1062,7 @@ class CourseEnrollment(models.Model):
'run': self.course_id.run, 'run': self.course_id.run,
'mode': self.mode, 'mode': self.mode,
}, context={ }, context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -1179,6 +1179,7 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused ...@@ -1179,6 +1179,7 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused
'provider': None 'provider': None
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
...@@ -1635,6 +1636,7 @@ def create_account_with_params(request, params): ...@@ -1635,6 +1636,7 @@ def create_account_with_params(request, params):
'provider': third_party_provider.name if third_party_provider else None 'provider': third_party_provider.name if third_party_provider else None
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -604,6 +604,7 @@ def login_analytics(strategy, auth_entry, *args, **kwargs): ...@@ -604,6 +604,7 @@ def login_analytics(strategy, auth_entry, *args, **kwargs):
'provider': getattr(kwargs['backend'], 'name') 'provider': getattr(kwargs['backend'], 'name')
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -7,9 +7,12 @@ from eventtracking import tracker ...@@ -7,9 +7,12 @@ from eventtracking import tracker
def create_tracking_context(user): def create_tracking_context(user):
""" Assembles attributes from user and request objects to be sent along """ Assembles attributes from user and request objects to be sent along
in ecommerce api calls for tracking purposes. """ in ecommerce api calls for tracking purposes. """
context_tracker = tracker.get_tracker().resolve_context()
return { return {
'lms_user_id': user.id, 'lms_user_id': user.id,
'lms_client_id': tracker.get_tracker().resolve_context().get('client_id') 'lms_client_id': context_tracker.get('client_id'),
'lms_ip': context_tracker.get('ip'),
} }
......
...@@ -60,7 +60,7 @@ class EcommerceApiClientTest(TestCase): ...@@ -60,7 +60,7 @@ class EcommerceApiClientTest(TestCase):
) )
mock_tracker = mock.Mock() mock_tracker = mock.Mock()
mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID}) mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID, 'ip': '127.0.0.1'})
with mock.patch('commerce.tracker.get_tracker', return_value=mock_tracker): with mock.patch('commerce.tracker.get_tracker', return_value=mock_tracker):
ecommerce_api_client(self.user).baskets(1).post() ecommerce_api_client(self.user).baskets(1).post()
...@@ -75,6 +75,7 @@ class EcommerceApiClientTest(TestCase): ...@@ -75,6 +75,7 @@ class EcommerceApiClientTest(TestCase):
'tracking_context': { 'tracking_context': {
'lms_user_id': self.user.id, # pylint: disable=no-member 'lms_user_id': self.user.id, # pylint: disable=no-member
'lms_client_id': self.TEST_CLIENT_ID, 'lms_client_id': self.TEST_CLIENT_ID,
'lms_ip': '127.0.0.1',
}, },
} }
......
...@@ -944,6 +944,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): ...@@ -944,6 +944,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
}, },
context={ context={
'ip': '127.0.0.1',
'Google Analytics': 'Google Analytics':
{'clientId': None} {'clientId': None}
} }
......
...@@ -1395,6 +1395,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis ...@@ -1395,6 +1395,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis
'label': unicode(course_id) 'label': unicode(course_id)
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -517,6 +517,7 @@ class Order(models.Model): ...@@ -517,6 +517,7 @@ class Order(models.Model):
'currency': self.currency, 'currency': self.currency,
'products': [item.analytics_data() for item in orderitems] 'products': [item.analytics_data() for item in orderitems]
}, context={ }, context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -265,7 +265,7 @@ class OrderTest(ModuleStoreTestCase): ...@@ -265,7 +265,7 @@ class OrderTest(ModuleStoreTestCase):
} }
] ]
}, },
context={'Google Analytics': {'clientId': None}} context={'ip': None, 'Google Analytics': {'clientId': None}}
) )
def test_purchase_item_failure(self): def test_purchase_item_failure(self):
...@@ -860,7 +860,7 @@ class CertificateItemTest(ModuleStoreTestCase): ...@@ -860,7 +860,7 @@ class CertificateItemTest(ModuleStoreTestCase):
} }
] ]
}, },
context={'Google Analytics': {'clientId': None}} context={'ip': None, 'Google Analytics': {'clientId': None}}
) )
def test_existing_enrollment(self): def test_existing_enrollment(self):
......
...@@ -1963,6 +1963,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase): ...@@ -1963,6 +1963,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
}, },
context={ context={
'ip': '127.0.0.1',
'Google Analytics': 'Google Analytics':
{'clientId': None} {'clientId': None}
} }
...@@ -2020,6 +2021,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase): ...@@ -2020,6 +2021,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
'checkpoint': self.reverification_assessment 'checkpoint': self.reverification_assessment
}, },
context={ context={
'ip': '127.0.0.1',
'Google Analytics': 'Google Analytics':
{'clientId': None} {'clientId': None}
} }
......
...@@ -1105,6 +1105,7 @@ class SubmitPhotosView(View): ...@@ -1105,6 +1105,7 @@ class SubmitPhotosView(View):
if settings.SEGMENT_KEY: if settings.SEGMENT_KEY:
tracking_context = tracker.get_tracker().resolve_context() tracking_context = tracker.get_tracker().resolve_context()
context = { context = {
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
...@@ -1450,6 +1451,7 @@ class InCourseReverifyView(View): ...@@ -1450,6 +1451,7 @@ class InCourseReverifyView(View):
'checkpoint': checkpoint 'checkpoint': checkpoint
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
...@@ -290,6 +290,7 @@ def _track_update_email_opt_in(user_id, organization, opt_in): ...@@ -290,6 +290,7 @@ def _track_update_email_opt_in(user_id, organization, opt_in):
'label': organization 'label': organization
}, },
context={ context={
'ip': tracking_context.get('ip'),
'Google Analytics': { 'Google Analytics': {
'clientId': tracking_context.get('client_id') 'clientId': tracking_context.get('client_id')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment