From c928c876453f089248a5c269005544e5c148acf3 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 24 Feb 2023 08:08:26 +0000 Subject: [PATCH] google_analytics: Track realm registration separately from user signup. While the function which processes the realm registration and signup remains the same, we use different urls and functions to call the process so that we can separately track them. This will help us know the conversion rate of realm registration after receiving the confirmation link. --- .../confirm_preregistrationuser.html | 2 +- zerver/tests/test_management_commands.py | 2 +- zerver/tests/test_signup.py | 2 +- zerver/views/registration.py | 25 ++++++++++++++++--- zproject/urls.py | 2 ++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/templates/confirmation/confirm_preregistrationuser.html b/templates/confirmation/confirm_preregistrationuser.html index fba8331e38..9e6efdfafb 100644 --- a/templates/confirmation/confirm_preregistrationuser.html +++ b/templates/confirmation/confirm_preregistrationuser.html @@ -13,7 +13,7 @@ requisite context to make a useful signup form. Therefore, we immediately post to another view which executes in our code to produce the desired form. #} -
+ {{ csrf_input }} diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py index 0d59668c1c..d31dcd6ef8 100644 --- a/zerver/tests/test_management_commands.py +++ b/zerver/tests/test_management_commands.py @@ -306,7 +306,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase): # Bypass sending mail for confirmation, go straight to creation form result = self.client_get(result["Location"]) - self.assert_in_response('action="/accounts/register/"', result) + self.assert_in_response('action="/realm/register/"', result) # Original link is now dead result = self.client_get(generated_link) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 78e434a011..f80553a357 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -3625,7 +3625,7 @@ class RealmCreationTest(ZulipTestCase): "key": find_key_by_email(email), "from_confirmation": "1", } - result = self.client_post("/accounts/register/", payload) + result = self.client_post("/realm/register/", payload) # Assert that the form did not prompt the user for enabling # marketing emails. self.assert_not_in_success_response(['input id="id_enable_marketing_emails"'], result) diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 3b84409080..5293ea3036 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -116,14 +116,24 @@ def get_prereg_key_and_redirect( accidentally adding an extra character after pasting). """ try: - check_prereg_key(request, confirmation_key) + prereg_user = check_prereg_key(request, confirmation_key) except ConfirmationKeyError as e: return render_confirmation_key_error(request, e) + realm_creation = prereg_user.realm_creation + + registration_url = reverse("accounts_register") + if realm_creation: + registration_url = reverse("realm_register") + return render( request, "confirmation/confirm_preregistrationuser.html", - context={"key": confirmation_key, "full_name": full_name}, + context={ + "key": confirmation_key, + "full_name": full_name, + "registration_url": registration_url, + }, ) @@ -150,8 +160,17 @@ def check_prereg_key(request: HttpRequest, confirmation_key: str) -> Preregistra @add_google_analytics @require_post +def realm_register(*args: Any, **kwargs: Any) -> HttpResponse: + return registration_helper(*args, **kwargs) + + +@require_post +def accounts_register(*args: Any, **kwargs: Any) -> HttpResponse: + return registration_helper(*args, **kwargs) + + @has_request_variables -def accounts_register( +def registration_helper( request: HttpRequest, key: str = REQ(default=""), timezone: str = REQ(default="", converter=to_timezone_or_empty), diff --git a/zproject/urls.py b/zproject/urls.py index 71805a2a5b..18a6175e66 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -127,6 +127,7 @@ from zerver.views.registration import ( get_prereg_key_and_redirect, new_realm_send_confirm, realm_redirect, + realm_register, signup_send_confirm, ) from zerver.views.report import ( @@ -579,6 +580,7 @@ i18n_urls = [ name="new_realm_send_confirm", ), path("accounts/register/", accounts_register, name="accounts_register"), + path("realm/register/", realm_register, name="realm_register"), path( "accounts/do_confirm/", get_prereg_key_and_redirect,