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

Page feedback: support for Google Analytics 4 (GA4) #1302

Closed
9 tasks done
Tracked by #1096 ...
chalin opened this issue Nov 1, 2022 · 4 comments
Closed
9 tasks done
Tracked by #1096 ...

Page feedback: support for Google Analytics 4 (GA4) #1302

chalin opened this issue Nov 1, 2022 · 4 comments

Comments

@chalin
Copy link
Collaborator

chalin commented Nov 1, 2022

Universal Analytics (UA) is deprecated. For details, see #1096. Here's some of the code associated with the page feedback feature:

const sendFeedback = (value) => {
if (typeof ga !== 'function') return;
const args = {
command: 'send',
hitType: 'event',
category: 'Helpful',
action: 'click',
label: window.location.pathname,
value: value
};
ga(args.command, args.hitType, args.category, args.action, args.label, args.value);
};
yesButton.addEventListener('click', () => {
yesResponse.classList.add('feedback--response__visible');
disableButtons();
sendFeedback(1);
});

This still uses the analytics.js library's ga() function. Note that this code is incompatible with GA4 because of the library that is used and the event name, as is explained below.

Tasks


Notes:

/cc @caniszczyk @nate-double-u

@chalin
Copy link
Collaborator Author

chalin commented Nov 1, 2022

Note: the use of click as a custom event name might not prevent projects from accessing page-feedback event data (I'm still exploring how to do this in GA4), but it does seem to make it unnecessarily harder when the same event name is also used by GA4 for another purpose.

@chalin
Copy link
Collaborator Author

chalin commented Nov 3, 2022

In the interim, it seems that projects can define an event-modification rule through the analytics console interface, to change the event name of page-feedback events to, e.g., page_helpful from click. For extra details, see kubernetes/website#37657 (comment).

(Edit) Or projects could disable data-stream outbound clicks.

Thanks for the pointer to the relevant GA4 doc pages @emckean! 🧡

@jmichelgarcia
Copy link

jmichelgarcia commented Nov 5, 2022

Thank you for the pointers here, I just spent one hour trying to figure out this.

@chalin
Copy link
Collaborator Author

chalin commented Nov 15, 2023

All done!

@chalin chalin closed this as completed Nov 15, 2023
@chalin chalin changed the title Page feedback: support Google Analytics 4 (GA4) Page feedback: support for Google Analytics 4 (GA4) Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants