From b686abc18db042bbaef8f7717c0cad4816c5f877 Mon Sep 17 00:00:00 2001 From: Bill DeRusha Date: Wed, 17 Feb 2016 13:40:36 -0500 Subject: [PATCH] Disable mailchimp integration for most segment identify requests --- cms/templates/widgets/segment-io-footer.html | 19 +++++++++++++---- .../student/tests/test_create_account.py | 1 + common/djangoapps/student/views.py | 21 ++++++++++++++----- lms/templates/widgets/segment-io-footer.html | 19 +++++++++++++---- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/cms/templates/widgets/segment-io-footer.html b/cms/templates/widgets/segment-io-footer.html index 571011d68b..e22c11f6d7 100644 --- a/cms/templates/widgets/segment-io-footer.html +++ b/cms/templates/widgets/segment-io-footer.html @@ -5,10 +5,21 @@ // We can't use JQuery's on load method because it // screws up RequireJS' JQuery initialization. var onLoadCallback = function() { - analytics.identify("${user.id}", { - email: "${user.email}", - username: "${user.username}" - }); + analytics.identify( + "${user.id}", + { + email: "${user.email}", + username: "${user.username}" + }, + { + integrations: { + // Disable MailChimp because we don't want to update the user's email + // and username in MailChimp on every page load. We only need to capture + // this data on registration/activation. + MailChimp: false + } + } + ); }; if (window.addEventListener) { window.addEventListener("load", onLoadCallback, false); diff --git a/common/djangoapps/student/tests/test_create_account.py b/common/djangoapps/student/tests/test_create_account.py index 55aa4d22f7..7422a02279 100644 --- a/common/djangoapps/student/tests/test_create_account.py +++ b/common/djangoapps/student/tests/test_create_account.py @@ -136,6 +136,7 @@ class TestCreateAccount(TestCase): 'username': self.params['username'], 'name': self.params['name'], 'age': 13, + 'yearOfBirth': year_of_birth, 'education': 'Associate degree', 'address': self.params['mailing_address'], 'gender': 'Other/Prefer Not to Say', diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 230677ea69..79aaa6aa8d 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1242,10 +1242,19 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused # Track the user's sign in if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY: tracking_context = tracker.get_tracker().resolve_context() - analytics.identify(user.id, { - 'email': email, - 'username': username - }) + analytics.identify( + user.id, + { + 'email': email, + 'username': username + }, + { + # Disable MailChimp because we don't want to update the user's email + # and username in MailChimp on every page load. We only need to capture + # this data on registration/activation. + 'MailChimp': False + } + ) analytics.track( user.id, @@ -1699,7 +1708,9 @@ def create_account_with_params(request, params): 'email': user.email, 'username': user.username, 'name': profile.name, - 'age': profile.age, + # Mailchimp requires the age & yearOfBirth to be integers, we send a sane integer default if falsey. + 'age': profile.age or -1, + 'yearOfBirth': profile.year_of_birth or datetime.datetime.now(UTC).year, 'education': profile.level_of_education_display, 'address': profile.mailing_address, 'gender': profile.gender_display, diff --git a/lms/templates/widgets/segment-io-footer.html b/lms/templates/widgets/segment-io-footer.html index 287cf6a15d..6088f5db97 100644 --- a/lms/templates/widgets/segment-io-footer.html +++ b/lms/templates/widgets/segment-io-footer.html @@ -3,10 +3,21 @@