Skip to content

Commit 7ea6b9e

Browse files
Sadashiimekarpeles
andauthored
feat: add statsd and matomo tracking for signup and activation funnel (#13190)
* feat: add statsd and matomo tracking for signup and activation funnel This commit adds observability to measure signup to email verification funnel rates: 1. Statsd counters (ol.account.created, ol.account.verify.success, and ol.account.verify.fail) to track raw signup events, activation success events, and activation failures. 2. Matomo trackEvent ('Account', 'RegistrationSuccess') and ('Account', 'ActivationSuccess') pushed via JavaScript so Matomo can capture device types natively from the User-Agent. --------- Co-authored-by: Mek <michael.karpeles@gmail.com>
1 parent c1bafad commit 7ea6b9e

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎openlibrary/plugins/upstream/account.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def GET(self):
692692
raise web.seeother("/account/create")
693693
r = InternetArchiveAccount.verify(token=i.t)
694694
if "error" in r:
695+
stats.increment("ol.account.verify.fail")
695696
if accounts.get_current_user():
696697
raise web.seeother("/account/books")
697698
add_flash_message(
@@ -700,6 +701,8 @@ def GET(self):
700701
)
701702
raise web.seeother("/account/create")
702703
add_flash_message("success", _("Your email has been verified. You are now logged in."))
704+
stats.increment("ol.account.verify.success")
705+
web.setcookie("ol_activation", "1", expires=300)
703706
kwargs = {"access": r["s3"]["access"], "secret": r["s3"]["secret"]}
704707
if i.redirect:
705708
kwargs["redirect"] = i.redirect

‎openlibrary/templates/account/verify.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ <h1>$_("Hi, %(user)s", user=username)!</h1>
1515
</p>
1616

1717
</div>
18+
19+
<script>
20+
var _paq = window._paq = window._paq || [];
21+
_paq.push(['trackEvent', 'Account', 'RegistrationSuccess']);
22+
</script>

‎openlibrary/templates/site/head.html‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
// Dimension 1 (visit-scoped): "Days Since Registration" — ID must match Matomo admin config (issue #12144)
6464
var _paq = window._paq = window._paq || [];
6565
_paq.push(['setCustomDimension', 1, $:json_encode(get_days_registered(ctx.user))]);
66+
// One-shot ActivationSuccess: cookie set by /account/verify on successful email activation.
67+
// Cleared immediately so it only fires once per activation.
68+
if (document.cookie.match(/(?:^|;\s*)ol_activation=1/)) {
69+
_paq.push(['trackEvent', 'Account', 'ActivationSuccess']);
70+
document.cookie = 'ol_activation=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
71+
}
6672

6773
var _mtm = window._mtm = window._mtm || [];
6874
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});

0 commit comments

Comments
 (0)