Skip to content

Commit fb64efa

Browse files
committed
Merge branch 'master' of github.com:squidfunk/mkdocs-material
2 parents f3c27fd + 07bea1e commit fb64efa

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

docs/setup/setting-up-site-analytics.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,23 @@ following lines to `mkdocs.yml`:
5151
understand how people use your documentation and what they expect to find.
5252
In order to enable site search tracking, the following steps are required:
5353

54-
1. Go to your Google Analytics __admin settings__
55-
2. Select the property for the respective tracking code
56-
3. Go to the __view settings__ tab
57-
4. Scroll down and enable __site search settings__
58-
5. Set the __query parameter__ to `q`
54+
=== ":material-google-analytics: Google Analytics 4"
5955

60-
Note that currently, site search tracking is not supported with Google
61-
Analytics 4 due to the more complicated manual setup. If you want to set up
62-
site search tracking yourself, [this tutorial][tutorial] is a good start.
56+
1. Go to your Google Analytics __admin settings__
57+
2. Select the property for the respective tracking code
58+
3. Select the __Data Streams__ tab and click the corresponding URL
59+
4. Click the gear icon within the __Enhanced measurement__ section
60+
5. Ensure that __Site search__ is enabled
61+
62+
=== ":material-google-analytics: Universal Analytics"
63+
64+
1. Go to your Google Analytics __admin settings__
65+
2. Select the property for the respective tracking code
66+
3. Go to the __view settings__ tab
67+
4. Scroll down and enable __site search settings__
68+
5. Set the __query parameter__ to `q`
6369

6470
[site search]: setting-up-site-search.md
65-
[tutorial]: https://www.analyticsmania.com/post/track-site-search-with-google-tag-manager-and-google-analytics/
6671

6772
### Was this page helpful?
6873

material/partials/integrations/analytics/google.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% set property = config.extra.analytics.property | d("", true) %}
99
{% endif %}
1010
{% if property.startswith("G-") %}
11-
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","{{ property }}"),document.addEventListener("DOMContentLoaded",function(){"undefined"!=typeof location$&&location$.subscribe(function(t){gtag("config","{{ property }}",{page_path:t.pathname})})})</script>
11+
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","{{ property }}"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){this.value&&gtag("event","search",{search_term:this.value})}),"undefined"!=typeof location$&&location$.subscribe(function(e){gtag("config","{{ property }}",{page_path:e.pathname})})})</script>
1212
<script async src="https://www.googletagmanager.com/gtag/js?id={{ property }}"></script>
1313
{% elif property.startswith("UA-") %}
1414
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","{{ property }}","auto"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){var e;this.value&&(e=document.location.pathname,ga("send","pageview",e+"?q="+this.value))}),"undefined"!=typeof location$&&location$.subscribe(function(e){ga("send","pageview",e.pathname)})})</script>

src/partials/integrations/analytics/google.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242

4343
/* Register virtual event handlers */
4444
document.addEventListener("DOMContentLoaded", function() {
45+
if (document.forms.search) {
46+
var query = document.forms.search.query
47+
query.addEventListener("blur", function() {
48+
if (this.value) {
49+
gtag("event", "search", {search_term: this.value})
50+
}
51+
})
52+
}
4553

4654
/* Send page view on location change */
4755
if (typeof location$ !== "undefined")

0 commit comments

Comments
 (0)