-
Notifications
You must be signed in to change notification settings - Fork 24
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
Update Google analytics to support google tag manager and GA4 #3469
base: master
Are you sure you want to change the base?
Conversation
Successful deploy here: https://app.netlify.com/sites/keen-mayer-a86c8b/deploys/64ac425521410d177485ae71 |
Seems like "nonce" approach doesn't work for static site builds (which is what our site is). Wondering if we move forward as is since we're only collecting page views just to see if the pipeline is working? Can adjust the CSP as necessary following. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that according to Sherry, we'll probably have to disable google analytics altogether until we we enable the opt in/out banner (GDPR etc).
export const pageview = url => { | ||
window.gtag('config', GA_TRACKING_ID, { | ||
page_path: url, | ||
}); | ||
}; | ||
|
||
// https://developers.google.com/analytics/devguides/collection/gtagjs/events | ||
export const event = ({ action, category, label, value }) => { | ||
window.gtag('event', action, { | ||
event_category: category, | ||
event_label: label, | ||
value, | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hard coding calls to these inside _app.js and such you could simply look at the event in line 5 above (in the analytics callback) and send the appropriate ga event there. That's what that callback is intended for.
Deploy Preview
What does this PR do?
Adds support for google tag manager, GA4 to collect page views on Design System site.
Key changes:
Resources for CSP changes: https://developers.google.com/tag-platform/tag-manager/csp#google_analytics_4_google_analytics
Where should the reviewer start?
aries-site/src/pages/_app.js
What testing has been done on this PR?
The script is being loaded successfully (checked Network tab). Need to merge to see if the data is flowing properly.
In addition to the feature you are implementing, have you checked the following:
General UX Checks
Accessibility Checks
Code Quality Checks
How should this be manually tested?
Any background context you want to provide?
What are the relevant issues?
Closes #3444
Screenshots (if appropriate)
Should this PR be mentioned in Design System updates?
Is this change backwards compatible or is it a breaking change?