Commit ec74398d by Nimisha Asthagiri

Merge pull request #5956 from edx/mobile/analytics-shim-update

MA-90 Update Analytics Shim to match new mobile requirements.
parents 126747fe 07d50ba7
......@@ -127,6 +127,6 @@ class VideoEventProcessor(object):
context = event['context']
if 'browser_page' in context:
page, _sep, _tail = context.pop('browser_page').rpartition('/')
if 'open_in_browser_url' in context:
page, _sep, _tail = context.pop('open_in_browser_url').rpartition('/')
event['page'] = page
......@@ -143,9 +143,20 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
raise EventValidationError(WARNING_IGNORED_TYPE)
if segment_context:
# copy required fields from segment's context dict to our custom context dict
for context_field_name, segment_context_field_name in [
('course_id', 'course_id'),
('open_in_browser_url', 'open_in_browser_url'),
('agent', 'userAgent')
]:
if segment_context_field_name in segment_context:
context[context_field_name] = segment_context[segment_context_field_name]
# copy the entire segment's context dict as a sub-field of our custom context dict
context['client'] = dict(segment_context)
context['agent'] = segment_context.get('userAgent', '')
for field in ('traits', 'integrations', 'userAgent'):
# remove duplicate and unnecessary fields from our copy
for field in ('traits', 'integrations', 'userAgent', 'course_id', 'open_in_browser_url'):
if field in context['client']:
del context['client'][field]
......
......@@ -114,9 +114,6 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"properties": {
'name': kwargs.get('name', str(sentinel.name)),
'data': kwargs.get('data', {}),
'context': {
'course_id': kwargs.get('course_id') or '',
}
},
"channel": 'server',
"context": {
......@@ -125,6 +122,7 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"version": "unknown"
},
'userAgent': str(sentinel.user_agent),
'course_id': kwargs.get('course_id') or '',
},
"receivedAt": "2014-08-27T16:33:39.100Z",
"timestamp": "2014-08-27T16:33:39.215Z",
......@@ -141,7 +139,10 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
}
if 'context' in kwargs:
sample_event['properties']['context'].update(kwargs['context'])
sample_event['context'].update(kwargs['context'])
if 'open_in_browser_url' in kwargs:
sample_event['context']['open_in_browser_url'] = kwargs['open_in_browser_url']
return sample_event
......@@ -304,9 +305,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
data=self.create_segmentio_event_json(
name=name,
data=input_payload,
open_in_browser_url='https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
context={
'course_id': course_id,
'browser_page': 'https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
'application': {
'name': 'edx.mobileapp.android',
'version': '29',
......@@ -342,14 +343,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
'library': {
'name': 'test-app',
'version': 'unknown'
},
'application': {
'name': 'edx.mobileapp.android',
'version': '29',
'component': 'videoplayer'
}
},
'received_at': datetime.strptime("2014-08-27T16:33:39.100Z", "%Y-%m-%dT%H:%M:%S.%fZ"),
'application': {
'name': 'edx.mobileapp.android',
'version': '29',
'component': 'videoplayer'
}
},
}
expected_payload = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment