diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 3d9101c4b1..6e6bc00cc1 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -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') } diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index b6b47577fc..30f89bbedc 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -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') } diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index a1bbb65655..1549070e97 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -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') } diff --git a/lms/djangoapps/commerce/__init__.py b/lms/djangoapps/commerce/__init__.py index 38e19e7eb5..d00bca69aa 100644 --- a/lms/djangoapps/commerce/__init__.py +++ b/lms/djangoapps/commerce/__init__.py @@ -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'), } diff --git a/lms/djangoapps/commerce/tests/__init__.py b/lms/djangoapps/commerce/tests/__init__.py index a4430e5fa0..abc1e3d8a0 100644 --- a/lms/djangoapps/commerce/tests/__init__.py +++ b/lms/djangoapps/commerce/tests/__init__.py @@ -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', }, } diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 93344dc920..74456bd9a2 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -944,6 +944,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): }, context={ + 'ip': '127.0.0.1', 'Google Analytics': {'clientId': None} } diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 3ca192ba15..45472a7440 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -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') } diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index f5cad742e8..22a643db3f 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -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') } diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index 883d60470f..5918a376f6 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -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): diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 3c1bfe661a..5ca1f2de4f 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -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} } diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 3b4278d520..4e57756f64 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -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') } diff --git a/openedx/core/djangoapps/user_api/preferences/api.py b/openedx/core/djangoapps/user_api/preferences/api.py index fea5acd0a2..790e9702da 100644 --- a/openedx/core/djangoapps/user_api/preferences/api.py +++ b/openedx/core/djangoapps/user_api/preferences/api.py @@ -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') }