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

feat(analytics): allow query/hash changes to be sent to GA #7545

Merged
merged 1 commit into from Jun 2, 2022
Merged

feat(analytics): allow query/hash changes to be sent to GA #7545

merged 1 commit into from Jun 2, 2022

Conversation

lanegoolsby
Copy link
Contributor

@lanegoolsby lanegoolsby commented Jun 1, 2022

Pre-flight checklist

Motivation

This change will allow page transitions (i.e. changes to the query string and bookmark hash) to be sent to Google Analytics

Test Plan

Ran yarn serve:website and verified that GA events are being sent

Related issues/PRs

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 1, 2022
Comment on lines -26 to -29
window.gtag('config', trackingID, {
page_path: location.pathname,
page_title: document.title,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config is done here so doing it again here is redundant.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know the practice here, because here we are also sending page_path etc. Do we have docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the reference I used to verify. I also poked around in some internal code in our org and verified that config does not need to be ran each time. Also, near as I can tell, the page_path and page_title are ignored if passed in as a config object. config is mostly intended for handling multiple property tracker IDs, campaign IDs, etc. Its not intended as a way to log page events.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see—sounds good to me, then!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually like a bug fix to me and also something I suspected

When navigating, there were 2 network entries:

CleanShot 2022-06-02 at 12 41 49@2x

Now there's only one 👍

@netlify
Copy link

netlify bot commented Jun 1, 2022

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 1c0343e
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6297877b1334a1000955755d
😎 Deploy Preview https://deploy-preview-7545--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Jun 1, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 65 🟢 100 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 89 🟢 99 🟢 100 🟢 100 🟢 90 Report

@Josh-Cena Josh-Cena changed the title feat(analytics): Allow changes to query string and bookmark hash to be sent to GA feat(analytics): allow query/hash changes to be sent to GA Jun 1, 2022
@Josh-Cena Josh-Cena added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Jun 1, 2022
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

That looks like a good default

Not 100% sure all users will like to track hash changes, but we can eventually add an option if someone complains later

Comment on lines -26 to -29
window.gtag('config', trackingID, {
page_path: location.pathname,
page_title: document.title,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually like a bug fix to me and also something I suspected

When navigating, there were 2 network entries:

CleanShot 2022-06-02 at 12 41 49@2x

Now there's only one 👍

@slorber slorber merged commit 1efcfc4 into facebook:main Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send page_view events to Google Analytics on query string mutations
4 participants