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

Send search analytics for Google Analytics 4 #3169

Closed
3 of 4 tasks
garrettheel opened this issue Nov 3, 2021 · 4 comments
Closed
3 of 4 tasks

Send search analytics for Google Analytics 4 #3169

garrettheel opened this issue Nov 3, 2021 · 4 comments

Comments

@garrettheel
Copy link
Contributor

Contribution guidelines

I want to suggest an idea and checked that ...

  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... the documentation does not mention anything about my idea
  • ... there are no open or closed issues that are related to my idea

Description

It'd be great if mkdocs-material would send search queries to GA4.

#1658 was the previous implementation of this for Universal Analytics (UA-*)

Use Cases

This would help to understand how documentation is being used and improve the ranking of pages.

Screenshots / Mockups

No response

@squidfunk
Copy link
Owner

Thanks for reporting! The problem with site search tracking in GA 4 is that it's very complicated to set up, which is why it's not considered to be in-scope. This is also mentioned in the documentation in "how to measure site search usage".

@garrettheel
Copy link
Contributor Author

@squidfunk I understand that it's a little tougher to set up on the Google Analytics side, but I think it would still be nice if mkdocs-material fired a custom event for search so that the data is somehow available. I suppose it can be hacked around with custom javascript, but would be a pretty common use case.

@squidfunk
Copy link
Owner

squidfunk commented Nov 3, 2021

If you would like to work on this, we can integrate it. Unfortunately, I currently don't have the bandwidth to do so. We would need a snippet to send the data, similar to the following code:

if (document.forms.search) {
var query = document.forms.search.query
query.addEventListener("blur", function() {
if (this.value) {
var path = document.location.pathname;
ga("send", "pageview", path + "?q=" + this.value)
}
})
}

... and documentation, which explains how to configure Google Analytics to pick up the query. The code snippet has to go into the same file, but into the GA4 section. If you can provide both in a PR, I'm happy to merge it.

@garrettheel
Copy link
Contributor Author

@squidfunk created #3184

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

No branches or pull requests

2 participants