Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - No longer collecting star-rating data for tutorials, since transition to GA4 #2696

Closed
carljparker opened this issue Dec 1, 2023 · 1 comment · Fixed by #2701
Closed
Assignees
Labels

Comments

@carljparker
Copy link
Contributor

Add Link

The problem occurs with all the tutorials, but here is an example that I have been working with:

https://pytorch.org/tutorials/beginner/basics/quickstart_tutorial.html

Describe the bug

Near the footer of each tutorial page is a UX of five stars which provides an opportunity for a user to rate the tutorial. (Refreshing the page resets the star rating.)

Prior to the transition to GA4 in June, 2023, we received event data when a user clicked on one of these stars. Since the transition to GA4 we are no longer seeing this data on the Google Analytics site.

One possibility is that the data is still collected, but that I just don't see where it is reported on the Google Analytics site; the reporting UX for GA4 is different than for Universal Analytics (UA)--the previous version of Google Analytics. This seems unlikely given my exploration of the site and the reporting UX.

Another possibility is that the mechanism that we were using is no longer supported by GA4. This seems more likely because the code to send the star rating still exists on our tutorial pages--but it no longer appears to do anything. That said, it could be possible to update that the code to make it compatible with GA4.

In the event that the existing code cannot be adapted to GA4, a fallback option is to use the expanded click-detection of GA4 to detect when the stars on clicked on--and report that using the GA4 reporting UX.

Describe your environment

MacBook Pro ~ 14-inch, 2021

  • Apple M1 Pro
  • 16 GB RAM
  • Storage: 303.33 GB available of 494.38 GB

Google Chrome ~ Version 119.0.6045.199 (Official Build) (arm64)

@carljparker carljparker added the bug label Dec 1, 2023
@carljparker carljparker self-assigned this Dec 1, 2023
@carljparker
Copy link
Contributor Author

In the transition from Universal Analytics (UA) to Google Analytics 4 (GA4), PR 182 (in pytorch_sphinx_theme/layout.html in the pytorch_sphinx_theme repo) deleted a JavaScript function definition that is used by the star-rating code:

function gtag(){dataLayer.push(arguments);}

Screenshot 2023-12-04 at 11 43 42 AM

You can see this function, gtag() used in the following block of code (in _templates/layout.html in the tutorials repo):

    gtag('event', 'click', {
      'event_category': 'Tutorial Rating',
      'event_label': $("h1").first().text(),
      'value': $(this).attr("data-count")
    });

If I put Google Tag Manager (GTM) in Preview mode, bring up a tutorial in Chrome, use Chrome's debug tools to define this function ad hoc, and then click on a star rating, I see the star rating appear in the data layer displayed by GTM.

Screenshot 2023-12-03 at 4 28 26 PM

Recommend that we restore this JavaScript function definition (roughly) in its original location in pytorch_sphinx_theme/layout.html in the pytorch_sphinx_theme repo.

carljparker added a commit to pytorch/pytorch_sphinx_theme that referenced this issue Dec 5, 2023
The associated issue is in the pytorch/tutorials repository:

Issue #2696 · [BUG]
No longer collecting star-rating data...since transition to GA4
pytorch/tutorials#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant