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
d9d78994
Commit
d9d78994
authored
Feb 25, 2015
by
Awais Qureshi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7069 from edx/awais786/ECOM-1086-analytics-certs
ECOM-1086 adding tracking event for cert generation.
parents
a36c615c
28b633f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
lms/djangoapps/courseware/tests/test_views.py
+22
-2
lms/djangoapps/courseware/views.py
+32
-0
No files found.
lms/djangoapps/courseware/tests/test_views.py
View file @
d9d78994
...
...
@@ -769,11 +769,15 @@ class GenerateUserCertTests(ModuleStoreTestCase):
self
.
assertIn
(
"Your certificate will be available when you pass the course."
,
resp
.
content
)
@patch
(
'courseware.grades.grade'
,
Mock
(
return_value
=
{
'grade'
:
'Pass'
,
'percent'
:
0.75
}))
@override_settings
(
CERT_QUEUE
=
'certificates'
)
@override_settings
(
CERT_QUEUE
=
'certificates'
,
SEGMENT_IO_LMS_KEY
=
"foobar"
,
FEATURES
=
{
'SEGMENT_IO_LMS'
:
True
}
)
def
test_user_with_passing_grade
(
self
):
# If user has above passing grading then json will return cert generating message and
# status valid code
# mocking xqueue
# mocking xqueue and analytics
analytics_patcher
=
patch
(
'courseware.views.analytics'
)
mock_tracker
=
analytics_patcher
.
start
()
self
.
addCleanup
(
analytics_patcher
.
stop
)
with
patch
(
'capa.xqueue_interface.XQueueInterface.send_to_queue'
)
as
mock_send_to_queue
:
mock_send_to_queue
.
return_value
=
(
0
,
"Successfully queued"
)
...
...
@@ -781,6 +785,22 @@ class GenerateUserCertTests(ModuleStoreTestCase):
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertIn
(
"Creating certificate"
,
resp
.
content
)
#Verify Google Analytics event fired after generating certificate
mock_tracker
.
track
.
assert_called_once_with
(
# pylint: disable=no-member
self
.
student
.
id
,
# pylint: disable=no-member
'edx.bi.user.certificate.generate'
,
{
'category'
:
'certificates'
,
'label'
:
unicode
(
self
.
course
.
id
)
},
context
=
{
'Google Analytics'
:
{
'clientId'
:
None
}
}
)
mock_tracker
.
reset_mock
()
@patch
(
'courseware.grades.grade'
,
Mock
(
return_value
=
{
'grade'
:
'Pass'
,
'percent'
:
0.75
}))
def
test_user_with_passing_existing_generating_cert
(
self
):
# If user has passing grade but also has existing generating cert
...
...
lms/djangoapps/courseware/views.py
View file @
d9d78994
...
...
@@ -71,6 +71,8 @@ import survey.utils
import
survey.views
from
util.views
import
ensure_valid_course_key
from
eventtracking
import
tracker
import
analytics
log
=
logging
.
getLogger
(
"edx.courseware"
)
...
...
@@ -1303,6 +1305,7 @@ def generate_user_cert(request, course_id):
if
not
certificate_status
[
"is_downloadable"
]
and
not
certificate_status
[
"is_generating"
]:
generate_user_certificates
(
student
,
course
)
_track_successful_certificate_generation
(
student
.
id
,
course
.
id
)
return
HttpResponse
(
_
(
"Creating certificate"
))
# if certificate_status is not is_downloadable and is_generating or
...
...
@@ -1311,3 +1314,32 @@ def generate_user_cert(request, course_id):
# at backend debug the issue and re-submit the task.
return
HttpResponseBadRequest
(
_
(
"Creating certificate"
))
def
_track_successful_certificate_generation
(
user_id
,
course_id
):
# pylint: disable=invalid-name
"""Track an successfully certificate generation event.
Arguments:
user_id (str): The ID of the user generting the certificate.
course_id (unicode): id associated with the course
Returns:
None
"""
if
settings
.
FEATURES
.
get
(
'SEGMENT_IO_LMS'
)
and
hasattr
(
settings
,
'SEGMENT_IO_LMS_KEY'
):
event_name
=
'edx.bi.user.certificate.generate'
# pylint: disable=no-member
tracking_context
=
tracker
.
get_tracker
()
.
resolve_context
()
# pylint: disable=no-member
analytics
.
track
(
user_id
,
event_name
,
{
'category'
:
'certificates'
,
'label'
:
unicode
(
course_id
)
},
context
=
{
'Google Analytics'
:
{
'clientId'
:
tracking_context
.
get
(
'client_id'
)
}
}
)
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