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
a22f120a
Commit
a22f120a
authored
Dec 04, 2014
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6133 from edx/renzo/track-email-opt-in
Add BI events for tracking email opt-ins
parents
212598e6
5e80389b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
9 deletions
+46
-9
common/djangoapps/user_api/api/profile.py
+46
-9
No files found.
common/djangoapps/user_api/api/profile.py
View file @
a22f120a
...
@@ -6,13 +6,16 @@ email address.
...
@@ -6,13 +6,16 @@ email address.
"""
"""
import
datetime
import
datetime
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
import
logging
from
pytz
import
UTC
from
pytz
import
UTC
import
analytics
from
user_api.models
import
User
,
UserProfile
,
UserPreference
,
UserOrgTag
from
user_api.models
import
User
,
UserProfile
,
UserPreference
,
UserOrgTag
from
user_api.helpers
import
intercept_errors
from
user_api.helpers
import
intercept_errors
from
eventtracking
import
tracker
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -57,7 +60,7 @@ def profile_info(username):
...
@@ -57,7 +60,7 @@ def profile_info(username):
At least one of the keyword args must be provided.
At least one of the keyword args must be provided.
Args:
Arg
ument
s:
username (unicode): The username of the account to retrieve.
username (unicode): The username of the account to retrieve.
Returns:
Returns:
...
@@ -89,10 +92,10 @@ def profile_info(username):
...
@@ -89,10 +92,10 @@ def profile_info(username):
def
update_profile
(
username
,
full_name
=
None
):
def
update_profile
(
username
,
full_name
=
None
):
"""Update a user's profile.
"""Update a user's profile.
Args:
Arg
ument
s:
username (unicode): The username associated with the account.
username (unicode): The username associated with the account.
Keyword Args:
Keyword Arg
ument
s:
full_name (unicode): If provided, set the user's full name to this value.
full_name (unicode): If provided, set the user's full name to this value.
Returns:
Returns:
...
@@ -119,7 +122,7 @@ def update_profile(username, full_name=None):
...
@@ -119,7 +122,7 @@ def update_profile(username, full_name=None):
def
preference_info
(
username
):
def
preference_info
(
username
):
"""Retrieve information about a user's preferences.
"""Retrieve information about a user's preferences.
Args:
Arg
ument
s:
username (unicode): The username of the account to retrieve.
username (unicode): The username of the account to retrieve.
Returns:
Returns:
...
@@ -141,10 +144,10 @@ def update_preferences(username, **kwargs):
...
@@ -141,10 +144,10 @@ def update_preferences(username, **kwargs):
Sets the provided preferences for the given user.
Sets the provided preferences for the given user.
Args:
Arg
ument
s:
username (unicode): The username of the account to retrieve.
username (unicode): The username of the account to retrieve.
Keyword Args:
Keyword Arg
ument
s:
**kwargs (unicode): Arbitrary key-value preference pairs
**kwargs (unicode): Arbitrary key-value preference pairs
Returns:
Returns:
...
@@ -170,10 +173,10 @@ def update_email_opt_in(username, org, optin):
...
@@ -170,10 +173,10 @@ def update_email_opt_in(username, org, optin):
Sets a User Org Tag defining the choice to opt in or opt out of organization-wide
Sets a User Org Tag defining the choice to opt in or opt out of organization-wide
emails.
emails.
Args:
Arg
ument
s:
username (str): The user to set a preference for.
username (str): The user to set a preference for.
org (str): The org is used to determine the organization this setting is related to.
org (str): The org is used to determine the organization this setting is related to.
optin (
b
oolean): True if the user is choosing to receive emails for this organization. If the user is not
optin (
B
oolean): True if the user is choosing to receive emails for this organization. If the user is not
the correct age to receive emails, email-optin is set to False regardless.
the correct age to receive emails, email-optin is set to False regardless.
Returns:
Returns:
...
@@ -201,5 +204,39 @@ def update_email_opt_in(username, org, optin):
...
@@ -201,5 +204,39 @@ def update_email_opt_in(username, org, optin):
)
)
preference
.
value
=
str
(
optin
and
of_age
)
preference
.
value
=
str
(
optin
and
of_age
)
preference
.
save
()
preference
.
save
()
if
settings
.
FEATURES
.
get
(
'SEGMENT_IO_LMS'
)
and
settings
.
SEGMENT_IO_LMS_KEY
:
_track_update_email_opt_in
(
user
.
id
,
org
,
optin
)
except
IntegrityError
as
err
:
except
IntegrityError
as
err
:
log
.
warn
(
u"Could not update organization wide preference due to IntegrityError: {}"
.
format
(
err
.
message
))
log
.
warn
(
u"Could not update organization wide preference due to IntegrityError: {}"
.
format
(
err
.
message
))
def
_track_update_email_opt_in
(
user_id
,
organization
,
opt_in
):
"""Track an email opt-in preference change.
Arguments:
user_id (str): The ID of the user making the preference change.
organization (str): The organization whose emails are being opted into or out of by the user.
opt_in (Boolean): Whether the user has chosen to opt-in to emails from the organization.
Returns:
None
"""
event_name
=
'edx.bi.user.org_email.opted_in'
if
opt_in
else
'edx.bi.user.org_email.opted_out'
tracking_context
=
tracker
.
get_tracker
()
.
resolve_context
()
analytics
.
track
(
user_id
,
event_name
,
{
'category'
:
'communication'
,
'label'
:
organization
},
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