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

[GA4] Emit page_helpful events for page feedback #1726

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ For the full list of changes, see the [release][0.8.0] notes.

**Breaking changes**:

- **Page feedback**, or [User feedback] ([#1726]):
- Feedback-event attribute changes:
- Event `name` is `page_helpful`rather than`click`
- Event `value` for "yes" is 100 by default, rather than 1, allowing for
more response options in the future. To override the default set
`params.ui.feedback.max_value`.
- SCSS: `@function prepend()` and file `assets/scss/support/_functions.scss`
have been dropped. Instead use the more general SASS/SCSS list `join()`
function ([#1385]).
Expand All @@ -37,6 +43,7 @@ For the full list of changes, see the [release][0.8.0] notes.
**Other changes**:

[#1385]: https://github.com/google/docsy/issues/1385
[#1726]: https://github.com/google/docsy/pull/1726
[0.8.0]: https://github.com/google/docsy/releases/v0.8.0/#FIXME
[User feedback]:
https://www.docsy.dev/docs/adding-content/feedback/#user-feedback
Expand Down
19 changes: 8 additions & 11 deletions layouts/partials/feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ <h2 class="feedback--title">{{- i18n "feedback_title" -}}</h2>
noButton.disabled = true;
};
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);
if (typeof gtag !== 'function') return;
gtag('event', 'page_helpful', {
'event_category': 'Helpful',
'event_label': window.location.pathname,
'value': value
});
};
yesButton.addEventListener('click', () => {
yesResponse.classList.add('feedback--response__visible');
disableButtons();
sendFeedback(1);
{{ $maxValue := .max_value | default 100 -}}
sendFeedback({{ $maxValue }});
});
noButton.addEventListener('click', () => {
noResponse.classList.add('feedback--response__visible');
Expand Down
6 changes: 5 additions & 1 deletion userguide/content/en/docs/adding-content/feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ of every documentation page, as shown in Figure 1.
</figure>

After clicking **Yes** the user should see a response like Figure 2. You can
[configure] the response text in the project's [configuration file] `hugo.toml`.
[configure] the response text in your project's [configuration file].

<figure>
<img src="/images/yes.png"
Expand Down Expand Up @@ -185,6 +185,10 @@ params:

3. Save the edits to your configuration file.

By default, Docsy emits an event value of 100 when a user clicks "yes". You can
change this value by setting `params.ui.feedback.max_value` to a positive
integer. Docsy uses 0 for "no" events.

### Access the feedback data

This section assumes basic familiarity with Google Analytics. For example, you
Expand Down