Add IP to all python Segment tracking calls
This commit is contained in:
@@ -1062,6 +1062,7 @@ class CourseEnrollment(models.Model):
|
||||
'run': self.course_id.run,
|
||||
'mode': self.mode,
|
||||
}, context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -1179,6 +1179,7 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused
|
||||
'provider': None
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
@@ -1635,6 +1636,7 @@ def create_account_with_params(request, params):
|
||||
'provider': third_party_provider.name if third_party_provider else None
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -604,6 +604,7 @@ def login_analytics(strategy, auth_entry, *args, **kwargs):
|
||||
'provider': getattr(kwargs['backend'], 'name')
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ from eventtracking import tracker
|
||||
def create_tracking_context(user):
|
||||
""" Assembles attributes from user and request objects to be sent along
|
||||
in ecommerce api calls for tracking purposes. """
|
||||
context_tracker = tracker.get_tracker().resolve_context()
|
||||
|
||||
return {
|
||||
'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):
|
||||
)
|
||||
|
||||
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):
|
||||
ecommerce_api_client(self.user).baskets(1).post()
|
||||
|
||||
@@ -75,6 +75,7 @@ class EcommerceApiClientTest(TestCase):
|
||||
'tracking_context': {
|
||||
'lms_user_id': self.user.id, # pylint: disable=no-member
|
||||
'lms_client_id': self.TEST_CLIENT_ID,
|
||||
'lms_ip': '127.0.0.1',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -944,6 +944,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
|
||||
},
|
||||
|
||||
context={
|
||||
'ip': '127.0.0.1',
|
||||
'Google Analytics':
|
||||
{'clientId': None}
|
||||
}
|
||||
|
||||
@@ -1395,6 +1395,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis
|
||||
'label': unicode(course_id)
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -517,6 +517,7 @@ class Order(models.Model):
|
||||
'currency': self.currency,
|
||||
'products': [item.analytics_data() for item in orderitems]
|
||||
}, context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
@@ -860,7 +860,7 @@ class CertificateItemTest(ModuleStoreTestCase):
|
||||
}
|
||||
]
|
||||
},
|
||||
context={'Google Analytics': {'clientId': None}}
|
||||
context={'ip': None, 'Google Analytics': {'clientId': None}}
|
||||
)
|
||||
|
||||
def test_existing_enrollment(self):
|
||||
|
||||
@@ -1963,6 +1963,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
|
||||
},
|
||||
|
||||
context={
|
||||
'ip': '127.0.0.1',
|
||||
'Google Analytics':
|
||||
{'clientId': None}
|
||||
}
|
||||
@@ -2020,6 +2021,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
|
||||
'checkpoint': self.reverification_assessment
|
||||
},
|
||||
context={
|
||||
'ip': '127.0.0.1',
|
||||
'Google Analytics':
|
||||
{'clientId': None}
|
||||
}
|
||||
|
||||
@@ -1105,6 +1105,7 @@ class SubmitPhotosView(View):
|
||||
if settings.SEGMENT_KEY:
|
||||
tracking_context = tracker.get_tracker().resolve_context()
|
||||
context = {
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
@@ -1450,6 +1451,7 @@ class InCourseReverifyView(View):
|
||||
'checkpoint': checkpoint
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
@@ -290,6 +290,7 @@ def _track_update_email_opt_in(user_id, organization, opt_in):
|
||||
'label': organization
|
||||
},
|
||||
context={
|
||||
'ip': tracking_context.get('ip'),
|
||||
'Google Analytics': {
|
||||
'clientId': tracking_context.get('client_id')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user