From 4f14d4f75bc366479ed8e6f78df9e325106d7dd5 Mon Sep 17 00:00:00 2001
From: Bill DeRusha <bill@edx.org>
Date: Tue, 22 Sep 2015 10:56:49 -0400
Subject: [PATCH] Bump version of segemnt's analytics-python package to 1.1.0

Wrap 3rd Party Auth Pipeline with Segment enabled checks
---
 common/djangoapps/third_party_auth/pipeline.py | 3 ++-
 lms/startup.py                                 | 4 ++--
 requirements/edx/base.txt                      | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py
index ba7da7ebec5..b9cff674b27 100644
--- a/common/djangoapps/third_party_auth/pipeline.py
+++ b/common/djangoapps/third_party_auth/pipeline.py
@@ -64,6 +64,7 @@ import urllib
 import analytics
 from eventtracking import tracker
 
+from django.conf import settings
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseBadRequest
@@ -586,7 +587,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:
+    if event_name is not None and hasattr(settings, 'SEGMENT_IO_LMS_KEY') and settings.SEGMENT_IO_LMS_KEY:
         tracking_context = tracker.get_tracker().resolve_context()
         analytics.track(
             kwargs['user'].id,
diff --git a/lms/startup.py b/lms/startup.py
index 6869f908285..5ed351add5b 100644
--- a/lms/startup.py
+++ b/lms/startup.py
@@ -44,8 +44,8 @@ def run():
 
     # Initialize Segment.io analytics module. Flushes first time a message is received and
     # every 50 messages thereafter, or if 10 seconds have passed since last flush
-    if settings.FEATURES.get('SEGMENT_IO_LMS') and hasattr(settings, 'SEGMENT_IO_LMS_KEY'):
-        analytics.init(settings.SEGMENT_IO_LMS_KEY, flush_at=50)
+    if settings.FEATURES.get('SEGMENT_IO_LMS') and hasattr(settings, 'SEGMENT_IO_LMS_KEY') and settings.SEGMENT_IO_LMS_KEY:  # pylint: disable=line-too-long
+        analytics.write_key = settings.SEGMENT_IO_LMS_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/requirements/edx/base.txt b/requirements/edx/base.txt
index 4ba60b4ba1a..cc06d4de70c 100644
--- a/requirements/edx/base.txt
+++ b/requirements/edx/base.txt
@@ -147,7 +147,7 @@ splinter==0.5.4
 testtools==0.9.34
 
 # Used for Segment.io analytics
-analytics-python==0.4.4
+analytics-python==1.1.0
 
 # Needed for mailchimp(mailing djangoapp)
 mailsnake==1.6.2
-- 
GitLab