Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
marketing: Track when navigation menus are opened.
Daniel K7258b81bb07b
diff --git a/templates/zerver/marketing_nav.html b/templates/zerver/marketing_nav.htmlindex 490d79195e8..143c2c741df 100644--- a/templates/zerver/marketing_nav.html+++ b/templates/zerver/marketing_nav.html@@ -199,12 +199,12 @@<label class="top-menu-tab-label-unselect nav-menu-label" for="top-menu-tab-close" tabindex="0"></label></nav><!-- We have separate copies of the navbar list for web and mobile. Please update both the versions when making changes. -->-<details class="top-menu-mobile">+<details data-menu-id="menu" class="top-menu-mobile"><summary class="top-menu-mobile-summary"><a class="top-menu-logo nav-zulip-logo" href="https://zulip.com"></a></summary><div class="top-menu-mobile-items-group-1">- <details>+ <details data-menu-id="product"><summary class="top-menu-mobile-item-summary">Product</summary><div class="top-menu-mobile-submenu"><span class="top-menu-mobile-submenu-section">OVERVIEW</span>@@ -229,7 +229,7 @@</ul></div></details>- <details>+ <details data-menu-id="solutions"><summary class="top-menu-mobile-item-summary">Solutions</summary><div class="top-menu-mobile-submenu"><span class="top-menu-mobile-submenu-section">USE CASES</span>@@ -249,7 +249,7 @@</ul></div></details>- <details>+ <details data-menu-id="case-studies"><summary class="top-menu-mobile-item-summary">Case studies</summary><div class="top-menu-mobile-submenu"><span class="top-menu-mobile-submenu-section">BUSINESS</span>@@ -302,7 +302,7 @@</ul></div></details>- <details>+ <details data-menu-id="resources"><summary class="top-menu-mobile-item-summary">Resources</summary><div class="top-menu-mobile-submenu"><span class="top-menu-mobile-submenu-section">FOR USERS</span>@@ -327,7 +327,7 @@<div class="top-menu-mobile-items-group-2"><div class='top-menu-mobile-item'><a href="/new/">New organization</a></div>{% if user_is_authenticated %}- <details>+ <details data-menu-id="user"><summary class="top-menu-mobile-item-summary"><img class="top-menu-mobile-user-img"src="{{ realm_icon }}" />diff --git a/web/src/portico/google-analytics.ts b/web/src/portico/google-analytics.tsindex f4a351a7d0c..def25a2c832 100644--- a/web/src/portico/google-analytics.ts+++ b/web/src/portico/google-analytics.ts@@ -18,6 +18,33 @@ if (page_params.google_analytics_id !== undefined) {$(document).on("click", ".analytics-click", function () {gtag("event", "marketing_click", {button_id: $(this).attr("data-button-id")!});});++ // Opening a navigation menu doesn't load a page, so Google+ // Analytics can't see it unless we send an event.+ $(document).on("change", ".top-menu-tab-input", function () {+ const menu_id = $(this)+ .attr("id")!+ .replace(/^top-menu-tab-/, "");+ gtag("event", "menu_open", {menu_id, layout: "wide"});+ });++ // The narrow-screen menu and its sections are <details> elements,+ // whose toggle event doesn't bubble, so we listen while it's+ // captured on the way down instead.+ document.addEventListener(+ "toggle",+ (event) => {+ const details = event.target;+ if (+ details instanceof HTMLDetailsElement &&+ details.open &&+ details.closest(".top-menu-mobile") !== null+ ) {+ gtag("event", "menu_open", {menu_id: details.dataset["menuId"], layout: "narrow"});+ }+ },+ {capture: true},+ );} else {config = () => {// No Google Analytics tracking configured.