Skip to content
Snippets Groups Projects
Commit 48a3db7f authored by Brian Wilson's avatar Brian Wilson
Browse files

Fix synthesized URL emitted to Segment.

Add schema to URL synthesized from host and path.
parent b05eac0b
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment