From 48a3db7ffa9eaa299cf17bc27e434753e5866afd Mon Sep 17 00:00:00 2001 From: Brian Wilson <brian@edx.org> Date: Thu, 22 Nov 2018 02:40:02 -0500 Subject: [PATCH] Fix synthesized URL emitted to Segment. Add schema to URL synthesized from host and path. --- common/djangoapps/track/segment.py | 8 +++++--- common/djangoapps/track/tests/test_segment.py | 2 +- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/testing.txt | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/track/segment.py b/common/djangoapps/track/segment.py index 9b2b1dbadab..e1470a83f05 100644 --- a/common/djangoapps/track/segment.py +++ b/common/djangoapps/track/segment.py @@ -8,7 +8,7 @@ required by server-side events. To use, call "from track import segment", then call segment.track() or segment.identify(). """ -from urlparse import urljoin +from urlparse import urlunsplit import analytics from django.conf import settings @@ -39,10 +39,12 @@ def track(user_id, event_name, properties=None, context=None): page = tracking_context.get('page') if path and not page: - # Try to put together a url from host and path: + # Try to put together a url from host and path, hardcoding the schema. + # (Segment doesn't care about the schema for GA, but will extract the host and path from the url.) host = tracking_context.get('host') if host: - page = urljoin("//{host}".format(host=host), path) + parts = ("https", host, path, "", "") + page = urlunsplit(parts) if path is not None or referer is not None or page is not None: if 'page' not in segment_context: diff --git a/common/djangoapps/track/tests/test_segment.py b/common/djangoapps/track/tests/test_segment.py index aef0421269a..90f45a51782 100644 --- a/common/djangoapps/track/tests/test_segment.py +++ b/common/djangoapps/track/tests/test_segment.py @@ -109,7 +109,7 @@ class SegmentTrackTestCase(TestCase): 'page': { 'path': '/this/is/a/path', 'referrer': sentinel.referer, - 'url': '//hostname/this/is/a/path' # Synthesized URL value. + 'url': 'https://hostname/this/is/a/path' # Synthesized URL value. } } self.assertEqual((sentinel.user_id, sentinel.name, self.properties, expected_segment_context), args) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 8c8a5328b40..d7c3bcdad5a 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -133,7 +133,7 @@ edx-user-state-client==1.0.4 edxval==0.1.22 elasticsearch==1.9.0 # via edx-search enum34==1.1.6 -event-tracking==0.2.6 +event-tracking==0.2.7 feedparser==5.1.3 firebase-token-generator==1.3.2 fs-s3fs==0.1.8 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 4a9e263f723..dcf4d6c50c3 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -154,7 +154,7 @@ edx-user-state-client==1.0.4 edxval==0.1.22 elasticsearch==1.9.0 enum34==1.1.6 -event-tracking==0.2.6 +event-tracking==0.2.7 execnet==1.5.0 extras==1.0.0 factory_boy==2.8.1 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index e514c660161..2562e0f61eb 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -148,7 +148,7 @@ edx-user-state-client==1.0.4 edxval==0.1.22 elasticsearch==1.9.0 enum34==1.1.6 -event-tracking==0.2.6 +event-tracking==0.2.7 execnet==1.5.0 # via pytest-xdist extras==1.0.0 # via python-subunit, testtools factory_boy==2.8.1 -- GitLab