Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
63b03785
Commit
63b03785
authored
May 15, 2015
by
Gabe Mulley
Committed by
cahrens
May 18, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure GA events have a course label if available
parent
e7a348d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
0 deletions
+83
-0
cms/envs/common.py
+3
-0
common/djangoapps/track/shim.py
+15
-0
common/djangoapps/track/tests/test_shim.py
+62
-0
lms/envs/common.py
+3
-0
No files found.
cms/envs/common.py
View file @
63b03785
...
...
@@ -782,6 +782,9 @@ EVENT_TRACKING_BACKENDS = {
'OPTIONS'
:
{
'whitelist'
:
[]
}
},
{
'ENGINE'
:
'track.shim.GoogleAnalyticsProcessor'
}
]
}
...
...
common/djangoapps/track/shim.py
View file @
63b03785
...
...
@@ -166,3 +166,18 @@ class VideoEventProcessor(object):
event
[
'page'
]
=
page
event
[
'event'
]
=
json
.
dumps
(
payload
)
class
GoogleAnalyticsProcessor
(
object
):
"""Adds course_id as label, and sets nonInteraction property"""
# documentation of fields here: https://segment.com/docs/integrations/google-analytics/
# this should *only* be used on events destined for segment.com and eventually google analytics
def
__call__
(
self
,
event
):
context
=
event
.
get
(
'context'
,
{})
course_id
=
context
.
get
(
'course_id'
)
if
course_id
is
not
None
:
event
[
'label'
]
=
course_id
event
[
'nonInteraction'
]
=
1
common/djangoapps/track/tests/test_shim.py
View file @
63b03785
...
...
@@ -13,6 +13,12 @@ LEGACY_SHIM_PROCESSOR = [
}
]
GOOGLE_ANALYTICS_PROCESSOR
=
[
{
'ENGINE'
:
'track.shim.GoogleAnalyticsProcessor'
}
]
@override_settings
(
EVENT_TRACKING_PROCESSORS
=
LEGACY_SHIM_PROCESSOR
,
...
...
@@ -87,3 +93,59 @@ class LegacyFieldMappingProcessorTestCase(EventTrackingTestCase):
'session'
:
''
,
}
assert_events_equal
(
expected_event
,
emitted_event
)
@override_settings
(
EVENT_TRACKING_PROCESSORS
=
GOOGLE_ANALYTICS_PROCESSOR
,
)
class
GoogleAnalyticsProcessorTestCase
(
EventTrackingTestCase
):
"""Ensure emitted events contain the fields necessary for Google Analytics."""
def
test_event_fields
(
self
):
""" Test that course_id is added as the label if present, and nonInteraction is set. """
data
=
{
sentinel
.
key
:
sentinel
.
value
}
context
=
{
'path'
:
sentinel
.
path
,
'user_id'
:
sentinel
.
user_id
,
'course_id'
:
sentinel
.
course_id
,
'org_id'
:
sentinel
.
org_id
,
'client_id'
:
sentinel
.
client_id
,
}
with
self
.
tracker
.
context
(
'test'
,
context
):
self
.
tracker
.
emit
(
sentinel
.
name
,
data
)
emitted_event
=
self
.
get_event
()
expected_event
=
{
'context'
:
context
,
'data'
:
data
,
'label'
:
sentinel
.
course_id
,
'name'
:
sentinel
.
name
,
'nonInteraction'
:
1
,
'timestamp'
:
FROZEN_TIME
,
}
assert_events_equal
(
expected_event
,
emitted_event
)
def
test_no_course_id
(
self
):
""" Test that a label is not added if course_id is not specified, but nonInteraction is still set. """
data
=
{
sentinel
.
key
:
sentinel
.
value
}
context
=
{
'path'
:
sentinel
.
path
,
'user_id'
:
sentinel
.
user_id
,
'client_id'
:
sentinel
.
client_id
,
}
with
self
.
tracker
.
context
(
'test'
,
context
):
self
.
tracker
.
emit
(
sentinel
.
name
,
data
)
emitted_event
=
self
.
get_event
()
expected_event
=
{
'context'
:
context
,
'data'
:
data
,
'name'
:
sentinel
.
name
,
'nonInteraction'
:
1
,
'timestamp'
:
FROZEN_TIME
,
}
assert_events_equal
(
expected_event
,
emitted_event
)
lms/envs/common.py
View file @
63b03785
...
...
@@ -623,6 +623,9 @@ EVENT_TRACKING_BACKENDS = {
'OPTIONS'
:
{
'whitelist'
:
[]
}
},
{
'ENGINE'
:
'track.shim.GoogleAnalyticsProcessor'
}
]
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment