DENG-803: add traits to segment context for enrollment activated events (#26842)

add traits to segment context for enrollment activated events
This commit is contained in:
Stu Young
2021-03-16 14:28:22 -04:00
committed by GitHub
parent 6b7d63af09
commit 5107aa41e9
4 changed files with 49 additions and 13 deletions

View File

@@ -341,20 +341,29 @@ def _track_user_registration(user, profile, params, third_party_provider):
# .. pii_types: email_address, username, name, birth_date, location, gender
# .. pii_retirement: third_party
segment.identify(*identity_args)
properties = {
'category': 'conversion',
# ..pii: Learner email is sent to Segment in following line and will be associated with analytics data.
'email': user.email,
'label': params.get('course_id'),
'provider': third_party_provider.name if third_party_provider else None,
'is_gender_selected': bool(profile.gender_display),
'is_year_of_birth_selected': bool(profile.year_of_birth),
'is_education_selected': bool(profile.level_of_education_display),
'is_goal_set': bool(profile.goals),
}
# DENG-803: For segment events forwarded along to Hubspot, duplicate the `properties` section of
# the event payload into the `traits` section so that they can be received. This is a temporary
# fix until we implement this behavior outside of the LMS.
# TODO: DENG-805: remove the properties duplication in the event traits.
segment_traits = dict(properties)
segment_traits['user_id'] = user.id
segment_traits['joined_date'] = user.date_joined.strftime("%Y-%m-%d")
segment.track(
user.id,
"edx.bi.user.account.registered",
{
'category': 'conversion',
# ..pii: Learner email is sent to Segment in following line and will be associated with analytics data.
'email': user.email,
'label': params.get('course_id'),
'provider': third_party_provider.name if third_party_provider else None,
'is_gender_selected': bool(profile.gender_display),
'is_year_of_birth_selected': bool(profile.year_of_birth),
'is_education_selected': bool(profile.level_of_education_display),
'is_goal_set': bool(profile.goals),
},
properties=properties,
traits=segment_traits,
)