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
50e39982
Commit
50e39982
authored
Oct 17, 2016
by
Bill DeRusha
Committed by
GitHub
Oct 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13768 from edx/bderusha/release-fix-2016-10-16
Fix for UTM parameter tracking when UTM not present
parents
b8a02534
a36df010
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
13 deletions
+56
-13
common/djangoapps/student/tests/test_create_account.py
+43
-0
common/djangoapps/student/views.py
+13
-13
No files found.
common/djangoapps/student/tests/test_create_account.py
View file @
50e39982
...
@@ -360,6 +360,49 @@ class TestCreateAccount(TestCase):
...
@@ -360,6 +360,49 @@ class TestCreateAccount(TestCase):
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_content'
)))
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_content'
)))
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_CREATED_AT
))
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_CREATED_AT
))
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_incomplete_utm_referral
(
self
):
"""Verify that no referral is recorded when a cookie is not present."""
utm_cookie_name
=
'edx.test.utm'
with
mock
.
patch
(
'student.models.RegistrationCookieConfiguration.current'
)
as
config
:
instance
=
config
.
return_value
instance
.
utm_cookie_name
=
utm_cookie_name
utm_cookie
=
{
'utm_source'
:
'test-source'
,
'utm_medium'
:
'test-medium'
,
# No campaign
'utm_term'
:
'test-term'
,
'utm_content'
:
'test-content'
,
# No created at
}
self
.
client
.
cookies
[
utm_cookie_name
]
=
json
.
dumps
(
utm_cookie
)
user
=
self
.
create_account_and_fetch_profile
()
.
user
self
.
assertEqual
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_source'
)),
utm_cookie
.
get
(
'utm_source'
)
)
self
.
assertEqual
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_medium'
)),
utm_cookie
.
get
(
'utm_medium'
)
)
self
.
assertEqual
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_term'
)),
utm_cookie
.
get
(
'utm_term'
)
)
self
.
assertEqual
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_content'
)),
utm_cookie
.
get
(
'utm_content'
)
)
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_PARAMETERS
.
get
(
'utm_campaign'
))
)
self
.
assertIsNone
(
UserAttribute
.
get_user_attribute
(
user
,
REGISTRATION_UTM_CREATED_AT
)
)
@ddt.ddt
@ddt.ddt
class
TestCreateAccountValidation
(
TestCase
):
class
TestCreateAccountValidation
(
TestCase
):
...
...
common/djangoapps/student/views.py
View file @
50e39982
...
@@ -1903,25 +1903,25 @@ def record_utm_registration_attribution(request, user):
...
@@ -1903,25 +1903,25 @@ def record_utm_registration_attribution(request, user):
utm_cookie
=
request
.
COOKIES
.
get
(
utm_cookie_name
)
utm_cookie
=
request
.
COOKIES
.
get
(
utm_cookie_name
)
if
user
and
utm_cookie
:
if
user
and
utm_cookie
:
utm
=
json
.
loads
(
utm_cookie
)
utm
=
json
.
loads
(
utm_cookie
)
for
utm_parameter
in
REGISTRATION_UTM_PARAMETERS
:
for
utm_parameter_name
in
REGISTRATION_UTM_PARAMETERS
:
UserAttribute
.
set_user_attribute
(
utm_parameter
=
utm
.
get
(
utm_parameter_name
)
user
,
if
utm_parameter
:
REGISTRATION_UTM_PARAMETERS
.
get
(
utm_parameter
),
UserAttribute
.
set_user_attribute
(
utm
.
get
(
utm_parameter
)
user
,
)
REGISTRATION_UTM_PARAMETERS
.
get
(
utm_parameter_name
),
utm_parameter
)
created_at_unixtime
=
utm
.
get
(
'created_at'
)
created_at_unixtime
=
utm
.
get
(
'created_at'
)
if
created_at_unixtime
:
if
created_at_unixtime
:
# We divide by 1000 here because the javascript timestamp generated is in milliseconds not seconds.
# We divide by 1000 here because the javascript timestamp generated is in milliseconds not seconds.
# PYTHON: time.time() => 1475590280.823698
# PYTHON: time.time() => 1475590280.823698
# JS: new Date().getTime() => 1475590280823
# JS: new Date().getTime() => 1475590280823
created_at_datetime
=
datetime
.
datetime
.
fromtimestamp
(
int
(
created_at_unixtime
)
/
float
(
1000
),
tz
=
UTC
)
created_at_datetime
=
datetime
.
datetime
.
fromtimestamp
(
int
(
created_at_unixtime
)
/
float
(
1000
),
tz
=
UTC
)
else
:
UserAttribute
.
set_user_attribute
(
created_at_datetime
=
None
user
,
UserAttribute
.
set_user_attribute
(
REGISTRATION_UTM_CREATED_AT
,
user
,
created_at_datetime
REGISTRATION_UTM_CREATED_AT
,
)
created_at_datetime
)
def
record_registration_attributions
(
request
,
user
):
def
record_registration_attributions
(
request
,
user
):
...
...
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