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

Track Lunr search queries and search-result clicks #1519

Merged

Conversation

chalin
Copy link
Collaborator

@chalin chalin commented Jul 1, 2023

  • Closes Track Lunr search via Google Analytics 4 #1518
  • Contributes to Improving Website Analytics #1289
  • Adds an event handler to send search terms as a search event to GA4 with the search term as an attribute, at no more than the debounce rate.
  • Adds a click event handler to each search-result item. When a user clicks on a search result, a click event is sent to GA4 with the destination link and associated search term as attributes.

A note about the deploy preview: the site preview will allow you to confirm that search is still functional, but it won't generate GA4 events, since analytics is only enabled in production. When _debug is enabled (which it was for my original commit, but has since been disabled), you can at least see that the tracking functions get called, like this:

trackSearchEvent: searchTerm = installation
trackSearchResultClick: searchTerm = installation, link = https://deploy-preview-1519--vitess.netlify.app/docs/17.0/get-started/local-mac/

I've locally built a "production" version of the site, and can confirm that GA4 is receiving both search and click (related to search) events. Notice the search_term attribute in both events:

Event Event attributes
Notice the search event with event count of 1: Screen Shot 2023-07-01 at 11 33 43 Screen Shot 2023-07-01 at 11 34 04
Oops forgot to get a click-event screenshot Screen Shot 2023-07-01 at 11 34 24

/cc @harshit-gangal @thisisobate @nate-double-u

@netlify
Copy link

netlify bot commented Jul 1, 2023

Deploy Preview for vitess ready!

Name Link
🔨 Latest commit 792cd9c
🔍 Latest deploy log https://app.netlify.com/sites/vitess/deploys/64a060630bbe97000884081b
😎 Deploy Preview https://deploy-preview-1519--vitess.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 configuration.

Signed-off-by: Patrice Chalin <[email protected]>
Copy link
Contributor

@thisisobate thisisobate left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

Thank you for doing this. Hope to see better analytics now and see how the search is performing for the users.

@harshit-gangal harshit-gangal merged commit 7069350 into vitessio:prod Jul 6, 2023
@chalin chalin deleted the chalin-im-lunr-ga4-tracking-2023-07-01 branch July 6, 2023 22:51
event_category: lunrSearchEventCategory,
event_label: 'Search-result Click',
search_term: searchTerm,
value: searchResultURL,
Copy link
Member

Choose a reason for hiding this comment

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

from the documentation value can be a number only, so it cannot be set to string
https://developers.google.com/tag-platform/devguides/events#gtag.js_1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For a preliminary analysis, see:

@chalin chalin mentioned this pull request Aug 28, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Track Lunr search via Google Analytics 4
3 participants