From 76d66718458edb516b550ee62f01b81aaf437782 Mon Sep 17 00:00:00 2001 From: Carl Parker Date: Tue, 5 Dec 2023 12:59:03 -0800 Subject: [PATCH] Restore the gtag JavaScript function to re-enable metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The associated issue is in the pytorch/tutorials repository: Issue #2696 ยท [BUG] No longer collecting star-rating data...since transition to GA4 https://github.com/pytorch/tutorials/issues/2696 The gtag function is used by metrics such as star-rating in the tutorials repository (which leverages pytorch_sphinx_theme). The definition for the gtag function was deleted in the transition to Google Analytics 4 (GA4) in PR#182, which in-turn broke our metrics. This commit restores the definition of the function to re-enable these metrics. --- pytorch_sphinx_theme/layout.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytorch_sphinx_theme/layout.html b/pytorch_sphinx_theme/layout.html index d84273cb..c3203e3a 100644 --- a/pytorch_sphinx_theme/layout.html +++ b/pytorch_sphinx_theme/layout.html @@ -81,7 +81,9 @@ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','{{ theme_analytics_id }}'); + })(window,document,'script','dataLayer','{{ theme_analytics_id }}'); + function gtag(){dataLayer.push(arguments);} + {% endblock %}