From 66291c3aa6ceaa2ce597fb31fc17f51ce8af8d83 Mon Sep 17 00:00:00 2001 From: Mubbshar Anwar <78487564+mubbsharanwar@users.noreply.github.com> Date: Fri, 8 Oct 2021 18:29:18 +0500 Subject: [PATCH] feat: record opt in/out attribute (#28883) * feat: record opt in/out attribute save opt in/out attribute comming from frontend-app-authn register page. VAN-738 * feat: VAN-738 - Send marketing event property and email subscription * feat: VAN-738 - Send marketing event property and email subscription * feat: VAN-738 - updated conditions * feat: VAN-738 - added is_active for braze during registration * feat: VAN-738 - added is_active for braze during registration * feat: VAN-738 - fixed pep8 violation Co-authored-by: Shafqat Farhan --- lms/envs/common.py | 2 ++ .../core/djangoapps/user_authn/views/register.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lms/envs/common.py b/lms/envs/common.py index fdf5867418..fd3ed02fa6 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -989,6 +989,8 @@ RETRY_CALENDAR_SYNC_EMAIL_MAX_ATTEMPTS = 5 # Deadline message configurations COURSE_MESSAGE_ALERT_DURATION_IN_DAYS = 14 +MARKETING_EMAILS_OPT_IN = False + ############################# SET PATH INFORMATION ############################# PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /edx-platform/lms REPO_ROOT = PROJECT_ROOT.dirname() diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 6f9e4a787b..3c0d60b1e5 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -99,6 +99,7 @@ REGISTRATION_UTM_PARAMETERS = { 'utm_content': 'registration_utm_content', } REGISTRATION_UTM_CREATED_AT = 'registration_utm_created_at' +MARKETING_EMAILS_OPT_IN = 'marketing_emails_opt_in' # used to announce a registration REGISTER_USER = Signal(providing_args=["user", "registration"]) @@ -271,6 +272,7 @@ def create_account_with_params(request, params): try: _record_registration_attributions(request, new_user) + _record_marketing_emails_opt_in_attribute(params.get('marketing_emails_opt_in'), new_user) # Don't prevent a user from registering due to attribution errors. except Exception: # pylint: disable=broad-except log.exception('Error while attributing cookies to user registration.') @@ -359,6 +361,8 @@ def _track_user_registration(user, profile, params, third_party_provider, regist 'address': profile.mailing_address, 'gender': profile.gender_display, 'country': str(profile.country), + 'email_subscribe': 'unsubscribed' if settings.MARKETING_EMAILS_OPT_IN and + params.get('marketing_emails_opt_in') == 'false' else 'subscribed', } ] # .. pii: Many pieces of PII are sent to Segment here. Retired directly through Segment API call in Tubular. @@ -378,6 +382,10 @@ def _track_user_registration(user, profile, params, third_party_provider, regist 'total_registration_time': round(float(params.get('totalRegistrationTime', '0'))), 'activation_key': registration.activation_key if registration else None, } + if params.get('marketing_emails_opt_in') and settings.MARKETING_EMAILS_OPT_IN: + properties['marketing_emails_opt_in'] = params.get('marketing_emails_opt_in') == 'true' + properties['is_active'] = params.get('marketing_emails_opt_in') == 'true' + # 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. @@ -450,6 +458,14 @@ def _skip_activation_email(user, running_pipeline, third_party_provider): ) +def _record_marketing_emails_opt_in_attribute(opt_in, user): + """ + Attribute this user's registration based on form data + """ + if settings.MARKETING_EMAILS_OPT_IN and user and opt_in: + UserAttribute.set_user_attribute(user, MARKETING_EMAILS_OPT_IN, opt_in) + + def _record_registration_attributions(request, user): """ Attribute this user's registration based on referrer cookies.