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): ...@@ -127,6 +127,6 @@ class VideoEventProcessor(object):
context = event['context'] context = event['context']
if 'browser_page' in context: if 'open_in_browser_url' in context:
page, _sep, _tail = context.pop('browser_page').rpartition('/') page, _sep, _tail = context.pop('open_in_browser_url').rpartition('/')
event['page'] = page event['page'] = page
...@@ -143,9 +143,20 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements ...@@ -143,9 +143,20 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
raise EventValidationError(WARNING_IGNORED_TYPE) raise EventValidationError(WARNING_IGNORED_TYPE)
if segment_context: 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['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']: if field in context['client']:
del context['client'][field] del context['client'][field]
......
...@@ -114,9 +114,6 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -114,9 +114,6 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"properties": { "properties": {
'name': kwargs.get('name', str(sentinel.name)), 'name': kwargs.get('name', str(sentinel.name)),
'data': kwargs.get('data', {}), 'data': kwargs.get('data', {}),
'context': {
'course_id': kwargs.get('course_id') or '',
}
}, },
"channel": 'server', "channel": 'server',
"context": { "context": {
...@@ -125,6 +122,7 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -125,6 +122,7 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"version": "unknown" "version": "unknown"
}, },
'userAgent': str(sentinel.user_agent), 'userAgent': str(sentinel.user_agent),
'course_id': kwargs.get('course_id') or '',
}, },
"receivedAt": "2014-08-27T16:33:39.100Z", "receivedAt": "2014-08-27T16:33:39.100Z",
"timestamp": "2014-08-27T16:33:39.215Z", "timestamp": "2014-08-27T16:33:39.215Z",
...@@ -141,7 +139,10 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -141,7 +139,10 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
} }
if 'context' in kwargs: 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 return sample_event
...@@ -304,9 +305,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -304,9 +305,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
data=self.create_segmentio_event_json( data=self.create_segmentio_event_json(
name=name, name=name,
data=input_payload, data=input_payload,
open_in_browser_url='https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
context={ context={
'course_id': course_id, 'course_id': course_id,
'browser_page': 'https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
'application': { 'application': {
'name': 'edx.mobileapp.android', 'name': 'edx.mobileapp.android',
'version': '29', 'version': '29',
...@@ -342,14 +343,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -342,14 +343,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
'library': { 'library': {
'name': 'test-app', 'name': 'test-app',
'version': 'unknown' '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"), '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 = { 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