Commit bcb71a32 by Bill DeRusha

Rename SEGMENT_KEY to have a unique key name for both CMS and LMS

parent cc15a9ad
......@@ -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 == "":
......
......@@ -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,
......
......@@ -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')
#####################################################################
......
......@@ -211,7 +211,7 @@ PASSWORD_HASHERS = (
)
# No segment key
SEGMENT_KEY = None
CMS_SEGMENT_KEY = None
FEATURES['ENABLE_SERVICE_STATUS'] = True
......
......@@ -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'
......
......@@ -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 }", {
......
......@@ -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',
......
......@@ -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
......
......@@ -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,
......
......@@ -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
......
......@@ -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()
......
......@@ -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
......
......@@ -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,
}
......
......@@ -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()
......
......@@ -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,
......
......@@ -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)
......
......@@ -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
......
......@@ -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 ######################
......
......@@ -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
......
% 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():
......
......@@ -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))
......
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