registration: Add google analytics to realm creation process.

Track `create_realm` and `new_realm_send_confirm` using
google analytics.
This will help us track number of users who want to
create a new Zulip organization.
This commit is contained in:
Aman Agrawal 2022-12-08 10:08:55 +00:00 committed by Tim Abbott
parent 0f2d4a3ab9
commit 51737b8905
2 changed files with 18 additions and 7 deletions

View File

@ -11,6 +11,7 @@ from django.core.exceptions import ValidationError
from django.db.models import Q from django.db.models import Q
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.template.response import TemplateResponse
from django.urls import reverse from django.urls import reverse
from django.utils.translation import get_language from django.utils.translation import get_language
from django_auth_ldap.backend import LDAPBackend, _LDAPUser from django_auth_ldap.backend import LDAPBackend, _LDAPUser
@ -33,7 +34,7 @@ from zerver.actions.user_settings import (
do_change_user_setting, do_change_user_setting,
) )
from zerver.context_processors import get_realm_from_request, login_context from zerver.context_processors import get_realm_from_request, login_context
from zerver.decorator import do_login, require_post from zerver.decorator import add_google_analytics, do_login, require_post
from zerver.forms import ( from zerver.forms import (
FindMyTeamForm, FindMyTeamForm,
HomepageForm, HomepageForm,
@ -604,17 +605,18 @@ def redirect_to_email_login_url(email: str) -> HttpResponseRedirect:
return HttpResponseRedirect(redirect_url) return HttpResponseRedirect(redirect_url)
@add_google_analytics
def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> HttpResponse: def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> HttpResponse:
try: try:
key_record = validate_key(creation_key) key_record = validate_key(creation_key)
except RealmCreationKey.InvalidError: except RealmCreationKey.InvalidError:
return render( return TemplateResponse(
request, request,
"zerver/realm_creation_link_invalid.html", "zerver/realm_creation_link_invalid.html",
) )
if not settings.OPEN_REALM_CREATION: if not settings.OPEN_REALM_CREATION:
if key_record is None: if key_record is None:
return render( return TemplateResponse(
request, request,
"zerver/realm_creation_disabled.html", "zerver/realm_creation_disabled.html",
) )
@ -628,7 +630,7 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht
rate_limit_request_by_ip(request, domain="sends_email_by_ip") rate_limit_request_by_ip(request, domain="sends_email_by_ip")
except RateLimitedError as e: except RateLimitedError as e:
assert e.secs_to_freedom is not None assert e.secs_to_freedom is not None
return render( return TemplateResponse(
request, request,
"zerver/rate_limit_exceeded.html", "zerver/rate_limit_exceeded.html",
context={"retry_after": int(e.secs_to_freedom)}, context={"retry_after": int(e.secs_to_freedom)},
@ -658,13 +660,22 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht
return HttpResponseRedirect(reverse("new_realm_send_confirm", kwargs={"email": email})) return HttpResponseRedirect(reverse("new_realm_send_confirm", kwargs={"email": email}))
else: else:
form = RealmCreationForm() form = RealmCreationForm()
return render( return TemplateResponse(
request, request,
"zerver/create_realm.html", "zerver/create_realm.html",
context={"form": form, "current_url": request.get_full_path}, context={"form": form, "current_url": request.get_full_path},
) )
@add_google_analytics
def new_realm_send_confirm(request: HttpRequest, email: str) -> HttpResponse:
return TemplateResponse(
request,
"zerver/accounts_send_confirm.html",
context={"email": email, "realm_creation": True},
)
def accounts_home( def accounts_home(
request: HttpRequest, request: HttpRequest,
multiuse_object_key: str = "", multiuse_object_key: str = "",

View File

@ -124,6 +124,7 @@ from zerver.views.registration import (
create_realm, create_realm,
find_account, find_account,
get_prereg_key_and_redirect, get_prereg_key_and_redirect,
new_realm_send_confirm,
realm_redirect, realm_redirect,
) )
from zerver.views.report import ( from zerver.views.report import (
@ -569,8 +570,7 @@ i18n_urls = [
), ),
path( path(
"accounts/new/send_confirm/<email>", "accounts/new/send_confirm/<email>",
TemplateView.as_view(template_name="zerver/accounts_send_confirm.html"), new_realm_send_confirm,
{"realm_creation": True},
name="new_realm_send_confirm", name="new_realm_send_confirm",
), ),
path("accounts/register/", accounts_register, name="accounts_register"), path("accounts/register/", accounts_register, name="accounts_register"),