diff --git a/cms/envs/aws.py b/cms/envs/aws.py index 064dcc17c934a24c8e2cf71243c58ac7200bbb7e..5f36f7122afc92b7623f7f37a707889bce4a733b 100644 --- a/cms/envs/aws.py +++ b/cms/envs/aws.py @@ -244,7 +244,7 @@ EMAIL_HOST_USER = AUTH_TOKENS.get('EMAIL_HOST_USER', EMAIL_HOST_USER) EMAIL_HOST_PASSWORD = AUTH_TOKENS.get('EMAIL_HOST_PASSWORD', EMAIL_HOST_PASSWORD) # Note that this is the Studio key for Segment. There is a separate key for the LMS. -SEGMENT_KEY = AUTH_TOKENS.get('SEGMENT_KEY') +CMS_SEGMENT_KEY = AUTH_TOKENS.get('SEGMENT_KEY') AWS_ACCESS_KEY_ID = AUTH_TOKENS["AWS_ACCESS_KEY_ID"] if AWS_ACCESS_KEY_ID == "": diff --git a/cms/envs/common.py b/cms/envs/common.py index ddd6112f0f6c2c6101bc74c6958707915e84c382..38e20d59e31087623e7b0ac8fc50ecd210b55036 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -78,7 +78,7 @@ FEATURES = { 'STUDIO_REQUEST_EMAIL': '', # Segment - must explicitly turn it on for production - 'SEGMENT_KEY': None, + 'CMS_SEGMENT_KEY': None, # Enable URL that shows information about the status of various services 'ENABLE_SERVICE_STATUS': False, diff --git a/cms/envs/dev.py b/cms/envs/dev.py index 0a9c0de7e097416bb2558a5f358d0560ae995193..ffd83d064adc72a99e5ec95e6e047404dad62044 100644 --- a/cms/envs/dev.py +++ b/cms/envs/dev.py @@ -167,7 +167,7 @@ FEATURES['ENABLE_SERVICE_STATUS'] = True # If there's an environment variable set, grab it to turn on Segment # Note that this is the Studio key. There is a separate key for the LMS. import os -SEGMENT_KEY = os.environ.get('SEGMENT_KEY') +CMS_SEGMENT_KEY = os.environ.get('SEGMENT_KEY') ##################################################################### diff --git a/cms/envs/test.py b/cms/envs/test.py index 343b7f3817bf54ce30c37f303cdcdd1ab439958d..842302b92c1fd9bdca8d6012ebcbf138896c2e39 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -211,7 +211,7 @@ PASSWORD_HASHERS = ( ) # No segment key -SEGMENT_KEY = None +CMS_SEGMENT_KEY = None FEATURES['ENABLE_SERVICE_STATUS'] = True diff --git a/cms/envs/yaml_config.py b/cms/envs/yaml_config.py index f301eaa406ba50516d3d1c6fd259a56079d7070e..3c863be41bb985149a5eb252684c9902384c6668 100644 --- a/cms/envs/yaml_config.py +++ b/cms/envs/yaml_config.py @@ -120,7 +120,7 @@ ADDL_INSTALLED_APPS = [] AUTH_USE_CAS = False CAS_ATTRIBUTE_CALLBACK = None MICROSITE_ROOT_DIR = '' -SEGMENT_KEY = None +CMS_SEGMENT_KEY = None DATADOG = {} ADDL_INSTALLED_APPS = [] LOCAL_LOGLEVEL = 'INFO' diff --git a/cms/templates/widgets/segment-io.html b/cms/templates/widgets/segment-io.html index b1e1fa034e7b79b963155af19d505e4ab8a6fb53..0e0c4a3f7f5bf3e26328b7add2f684e6eecb27e3 100644 --- a/cms/templates/widgets/segment-io.html +++ b/cms/templates/widgets/segment-io.html @@ -6,7 +6,7 @@ %> % endif -% if settings.SEGMENT_KEY: +% if settings.CMS_SEGMENT_KEY: <!-- begin Segment --> <script type="text/javascript"> // if inside course, inject the course location into the JS namespace @@ -15,7 +15,7 @@ %endif var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])}; - analytics.load("${ settings.SEGMENT_KEY }"); + analytics.load("${ settings.CMS_SEGMENT_KEY }"); % if user.is_authenticated(): analytics.identify("${ user.id }", { diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 3d9101c4b1b7c30fa5d73a99252a20a95064533f..58793750dc8b5ea18db99e7e6dc02a9cd4fc552a 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -1052,7 +1052,7 @@ class CourseEnrollment(models.Model): with tracker.get_tracker().context(event_name, context): tracker.emit(event_name, data) - if settings.SEGMENT_KEY: + if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() analytics.track(self.user_id, event_name, { 'category': 'conversion', diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index b6b47577fcc6cd5cd3760a7e46b3ac3f99dda093..5b41a0b31cfeb08dca28dfccd8e74f02a0782357 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1163,7 +1163,7 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused LoginFailures.clear_lockout_counter(user) # Track the user's sign in - if settings.SEGMENT_KEY: + if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() analytics.identify(user.id, { 'email': email, @@ -1601,7 +1601,7 @@ def create_account_with_params(request, params): third_party_provider = provider.Registry.get_from_pipeline(running_pipeline) # Track the user's registration - if settings.SEGMENT_KEY: + if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() identity_args = [ user.id, # pylint: disable=no-member diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index a1bbb6565524012dc283e51ff3ebfc5f70976f27..e4e519640e05d15e256a9d29c27efb78f4e3d1e3 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -593,7 +593,7 @@ def login_analytics(strategy, auth_entry, *args, **kwargs): elif auth_entry in [AUTH_ENTRY_ACCOUNT_SETTINGS]: event_name = 'edx.bi.user.account.linked' - if event_name is not None and settings.SEGMENT_KEY: + if event_name is not None and hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() analytics.track( kwargs['user'].id, diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 93344dc920a9b774dc4d88b8981732396ab172b6..55e955e171695274e0c98356554499548a3757d8 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -919,7 +919,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): self.assertIn("Your certificate will be available when you pass the course.", resp.content) @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75})) - @override_settings(CERT_QUEUE='certificates', SEGMENT_KEY="foobar") + @override_settings(CERT_QUEUE='certificates', LMS_SEGMENT_KEY="foobar") def test_user_with_passing_grade(self): # If user has above passing grading then json will return cert generating message and # status valid code @@ -965,7 +965,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): self.assertIn("Certificate is being created.", resp.content) @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75})) - @override_settings(CERT_QUEUE='certificates', SEGMENT_KEY="foobar") + @override_settings(CERT_QUEUE='certificates', LMS_SEGMENT_KEY="foobar") def test_user_with_passing_existing_downloadable_cert(self): # If user has already downloadable certificate # then json will return cert generating message with bad request code diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 3ca192ba15ae095433578d1fafab3b3f66be510c..bb4bcc0686aef7d32170999acc6e6d2589159e51 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -1383,7 +1383,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis None """ - if settings.SEGMENT_KEY: + if settings.LMS_SEGMENT_KEY: event_name = 'edx.bi.user.certificate.generate' tracking_context = tracker.get_tracker().resolve_context() diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index f5cad742e80829468d9108b48a2fbed0396c91fc..a0bab1793dc5f808de3a198b990d869d759582b7 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -509,7 +509,7 @@ class Order(models.Model): """ try: - if settings.SEGMENT_KEY: + if settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() analytics.track(self.user.id, event_name, { # pylint: disable=no-member 'orderId': self.id, # pylint: disable=no-member diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index 883d60470ff461d266e302455e2eac49faba86d2..33f44f9ef776f94b1d1864824b47a7decf52c806 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -220,7 +220,7 @@ class OrderTest(ModuleStoreTestCase): self.assertEqual(item.status, status) @override_settings( - SEGMENT_KEY="foobar", + LMS_SEGMENT_KEY="foobar", FEATURES={ 'STORE_BILLING_INFO': True, } @@ -883,7 +883,7 @@ class CertificateItemTest(ModuleStoreTestCase): self.assertEquals(cert_item.single_item_receipt_template, 'shoppingcart/receipt.html') @override_settings( - SEGMENT_KEY="foobar", + LMS_SEGMENT_KEY="foobar", FEATURES={ 'STORE_BILLING_INFO': True, } @@ -924,7 +924,7 @@ class CertificateItemTest(ModuleStoreTestCase): self.assertEquals(target_certs[0].order.status, 'purchased') @override_settings( - SEGMENT_KEY="foobar", + LMS_SEGMENT_KEY="foobar", FEATURES={ 'STORE_BILLING_INFO': True, } diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 3c1bfe661a0b5f70b5bbac15ca85febbb7858bb5..44ddbb344e7a3b0bc329ed826da2080e90b44292 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -1939,7 +1939,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase): url += u"?{params}".format(params=urllib.urlencode({"checkpoint": self.reverification_location})) self.assertRedirects(response, url) - @override_settings(SEGMENT_KEY="foobar") + @override_settings(LMS_SEGMENT_KEY="foobar") @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) def test_incourse_reverify_get(self): """ @@ -1994,7 +1994,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase): response = self._submit_photos(self.course_key, self.reverification_location, "") self.assertEqual(response.status_code, 400) - @override_settings(SEGMENT_KEY="foobar") + @override_settings(LMS_SEGMENT_KEY="foobar") @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) def test_incourse_reverify_post(self): self._create_checkpoint() diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 3b4278d520e0a2d63f6230e429c20e53e37c7758..98b2ddf36b8952a8510bb173abec840416e8421c 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -1102,7 +1102,7 @@ class SubmitPhotosView(View): Returns: None """ - if settings.SEGMENT_KEY: + if settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() context = { 'Google Analytics': { @@ -1439,7 +1439,7 @@ class InCourseReverifyView(View): event_name, user_id, course_id, checkpoint ) - if settings.SEGMENT_KEY: + if settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() analytics.track( user_id, diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 0ceb9f0511f5a70eda85526499b23842d6994f3b..611d7890ad2e928e69859658f5bfae4774c9d2ed 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -400,7 +400,7 @@ if 'DJFS' in AUTH_TOKENS and AUTH_TOKENS['DJFS'] is not None: HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS = ENV_TOKENS.get('HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', {}) ############### Mixed Related(Secure/Not-Secure) Items ########## -SEGMENT_KEY = AUTH_TOKENS.get('SEGMENT_KEY') +LMS_SEGMENT_KEY = AUTH_TOKENS.get('SEGMENT_KEY') CC_PROCESSOR_NAME = AUTH_TOKENS.get('CC_PROCESSOR_NAME', CC_PROCESSOR_NAME) CC_PROCESSOR = AUTH_TOKENS.get('CC_PROCESSOR', CC_PROCESSOR) diff --git a/lms/envs/common.py b/lms/envs/common.py index d9f7675995362ed951a8ae6910fd2816d430dcb1..151fea82a738835cb6649c839ac96777ccd5a0c5 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -608,7 +608,7 @@ USAGE_ID_PATTERN = r'(?P<usage_id>(?:i4x://?[^/]+/[^/]+/[^/]+/[^@]+(?:@[^/]+)?)| ############################## EVENT TRACKING ################################# -SEGMENT_KEY = None +LMS_SEGMENT_KEY = None # FIXME: Should we be doing this truncation? TRACK_MAX_EVENT = 50000 diff --git a/lms/envs/dev.py b/lms/envs/dev.py index 5c9c784969a6fae983b508494f898229ccd5e024..0dc306b5c14d2182c791cbb1c4b6dd7737aca65e 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -275,7 +275,7 @@ ANALYTICS_API_KEY = "" ##### Segment ###### # If there's an environment variable set, grab it -SEGMENT_KEY = os.environ.get('SEGMENT_KEY') +LMS_SEGMENT_KEY = os.environ.get('SEGMENT_KEY') ###################### Payment ###################### diff --git a/lms/startup.py b/lms/startup.py index b2865a3fed3389499d7ab12aaeec3ea1a7a46cbc..9dc2b0d7bb7b102630133b777acbbbfedbd87d30 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -39,8 +39,8 @@ def run(): enable_third_party_auth() # Initialize Segment analytics module by setting the write_key. - if settings.SEGMENT_KEY: - analytics.write_key = settings.SEGMENT_KEY + if settings.LMS_SEGMENT_KEY: + analytics.write_key = settings.LMS_SEGMENT_KEY # register any dependency injections that we need to support in edx_proctoring # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit diff --git a/lms/templates/widgets/segment-io.html b/lms/templates/widgets/segment-io.html index 7fa0757d7eeda0e5480111a7914a970809dc0d4d..68013f6c2800853a933597db643bac72dec082d4 100644 --- a/lms/templates/widgets/segment-io.html +++ b/lms/templates/widgets/segment-io.html @@ -1,9 +1,9 @@ -% if settings.SEGMENT_KEY: +% if settings.LMS_SEGMENT_KEY: <!-- begin Segment --> <script type="text/javascript"> // Asynchronously load Segment's analytics.js library window.analytics||(window.analytics=[]),window.analytics.methods=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group","on","once","off"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var method=window.analytics.methods[i];window.analytics[method]=window.analytics.factory(method)}window.analytics.load=function(t){var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)},window.analytics.SNIPPET_VERSION="2.0.8", - analytics.load("${ settings.SEGMENT_KEY }"); + analytics.load("${ settings.LMS_SEGMENT_KEY }"); analytics.page(); % if user.is_authenticated(): diff --git a/openedx/core/djangoapps/user_api/preferences/api.py b/openedx/core/djangoapps/user_api/preferences/api.py index fea5acd0a229eb978515396180cea71a420c8f7f..2d3afcf47738c0ee7e8b4138f4686fa5c4ae376c 100644 --- a/openedx/core/djangoapps/user_api/preferences/api.py +++ b/openedx/core/djangoapps/user_api/preferences/api.py @@ -261,7 +261,7 @@ def update_email_opt_in(user, org, opt_in): preference.value = str(opt_in) try: preference.save() - if settings.SEGMENT_KEY: + if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: _track_update_email_opt_in(user.id, org, opt_in) except IntegrityError as err: log.warn(u"Could not update organization wide preference due to IntegrityError: {}".format(err.message))