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

Add creation of url from host and path.

parent 5311509b
No related merge requests found
......@@ -8,9 +8,9 @@ required by server-side events.
To use, call "from track import segment", then call segment.track() or segment.identify().
"""
from urlparse import urljoin
import analytics
from django.conf import settings
from eventtracking import tracker
......@@ -37,6 +37,13 @@ def track(user_id, event_name, properties=None, context=None):
path = tracking_context.get('path')
referer = tracking_context.get('referer')
page = tracking_context.get('page')
if path and not page:
# Try to put together a url from host and path:
host = tracking_context.get('host')
if host:
page = urljoin("//{host}".format(host=host), path)
if path is not None or referer is not None or page is not None:
if 'page' not in segment_context:
segment_context['page'] = {}
......
......@@ -79,15 +79,16 @@ class SegmentTrackTestCase(TestCase):
@override_settings(LMS_SEGMENT_KEY="testkey")
def test_track_with_standard_context(self):
# Note that 'host' and 'path' will be urlparsed, so must be strings.
tracking_context = {
'accept_language': sentinel.accept_language,
'referer': sentinel.referer,
'username': sentinel.username,
'session': sentinel.session,
'ip': sentinel.ip,
'host': sentinel.host,
'host': 'hostname',
'agent': sentinel.agent,
'path': sentinel.path,
'path': '/this/is/a/path',
'user_id': sentinel.user_id,
'course_id': sentinel.course_id,
'org_id': sentinel.org_id,
......@@ -106,9 +107,9 @@ class SegmentTrackTestCase(TestCase):
},
'userAgent': sentinel.agent,
'page': {
'path': sentinel.path,
'path': '/this/is/a/path',
'referrer': sentinel.referer,
# No URL value.
'url': '//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.5
event-tracking==0.2.6
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.5
event-tracking==0.2.6
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.5
event-tracking==0.2.6
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