mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Removed Universal Analytics integration (UA-XXXXXXXX-X)
This commit is contained in:
parent
b2a20a2a11
commit
fb9c9f9486
@ -16,11 +16,14 @@ MkDocs natively integrates with [Google Analytics] and offers a customizable
|
||||
[:octicons-tag-24: 7.1.8][Google Analytics support] ·
|
||||
:octicons-milestone-24: Default: _none_
|
||||
|
||||
Material for MkDocs integrates with both, Google Analytics 4 and the now phasing
|
||||
out Universal Analytics. Depending on the given property prefix, add the
|
||||
Material for MkDocs integrates natively with Google Analytics 4[^1]. If you
|
||||
already set up Google Analytics and have a property, enable it by adding the
|
||||
following lines to `mkdocs.yml`:
|
||||
|
||||
=== ":material-google-analytics: Google Analytics 4"
|
||||
[^1]:
|
||||
Prior to Material for MkDocs 9.2.0, Universal Analytics was supported as
|
||||
well. However, since Universal Analytics has been sunset, this integration
|
||||
was removed in 9.2.0.
|
||||
|
||||
``` yaml
|
||||
extra:
|
||||
@ -29,15 +32,6 @@ following lines to `mkdocs.yml`:
|
||||
property: G-XXXXXXXXXX
|
||||
```
|
||||
|
||||
=== ":material-google-analytics: Universal Analytics"
|
||||
|
||||
``` yaml
|
||||
extra:
|
||||
analytics:
|
||||
provider: google
|
||||
property: UA-XXXXXXXX-X
|
||||
```
|
||||
|
||||
[Google Analytics support]: https://github.com/squidfunk/mkdocs-material/releases/tag/7.1.8
|
||||
|
||||
??? question "How to measure site search usage?"
|
||||
@ -46,22 +40,12 @@ following lines to `mkdocs.yml`:
|
||||
understand how people use your documentation and what they expect to find.
|
||||
In order to enable site search tracking, the following steps are required:
|
||||
|
||||
=== ":material-google-analytics: Google Analytics 4"
|
||||
|
||||
1. Go to your Google Analytics __admin settings__
|
||||
2. Select the property for the respective tracking code
|
||||
3. Select the __data streams__ tab and click the corresponding URL
|
||||
4. Click the gear icon within the __enhanced measurement__ section
|
||||
5. Ensure that __site search__ is enabled
|
||||
|
||||
=== ":material-google-analytics: Universal Analytics"
|
||||
|
||||
1. Go to your Google Analytics __admin settings__
|
||||
2. Select the property for the respective tracking code
|
||||
3. Go to the __view settings__ tab
|
||||
4. Scroll down and enable __site search settings__
|
||||
5. Set the __query parameter__ to `q`
|
||||
|
||||
[site search]: setting-up-site-search.md
|
||||
|
||||
### Was this page helpful?
|
||||
@ -102,9 +86,9 @@ extra:
|
||||
Both properties, `title` and `ratings`, are required. Note that it's allowed to
|
||||
define more than two ratings, e.g. to implement a 1-5 star rating. Since the
|
||||
feedback widget sends data to a third-party service, it is, of course, natively
|
||||
integrated with the [cookie consent] feature[^1].
|
||||
integrated with the [cookie consent] feature[^2].
|
||||
|
||||
[^1]:
|
||||
[^2]:
|
||||
If the user doesn't accept the `analytics` cookie, the feedback widget is
|
||||
not shown.
|
||||
|
||||
@ -114,8 +98,6 @@ integrated with the [cookie consent] feature[^1].
|
||||
[Google Analytics] that will quickly show you the worst- and best-rated
|
||||
pages of your project documentation.
|
||||
|
||||
=== ":material-google-analytics: Google Analytics 4"
|
||||
|
||||
1. Go to your Google Analytics __dashboard__
|
||||
|
||||
2. Go to the __configure__ page on the left hand menu, then select
|
||||
@ -146,15 +128,6 @@ integrated with the [cookie consent] feature[^1].
|
||||
|
||||
The report may take 24 hours or longer to begin displaying data
|
||||
|
||||
=== ":material-google-analytics: Universal Analytics"
|
||||
|
||||
1. Go to your Google Analytics __dashboard__
|
||||
2. Open the __customization__ panel on the left and go to __custom reports__
|
||||
3. Create a __new custom report__ and set a custom __title__ and __name__
|
||||
4. Add `Avg. Value` and `Total Events` to __metric group__
|
||||
5. Add `Event Label` to __dimension drilldown__
|
||||
6. Add `Event Category` to __filters__ and filter for the value __feedback__
|
||||
|
||||
Now, after you've saved the report and collected some feedback ratings,
|
||||
you'll have a list of all pages with the total number of ratings, and an
|
||||
average rating per page. This should help you identify pages that need to
|
||||
@ -185,9 +158,9 @@ The following properties are available for each rating:
|
||||
|
||||
: :octicons-milestone-24: Default: _none_ · :octicons-alert-24: __Required__ –
|
||||
The value of this property is sent as a data value with the custom event
|
||||
that is transmitted to Google Analytics[^2] (or any custom integration).
|
||||
that is transmitted to Google Analytics[^3] (or any custom integration).
|
||||
|
||||
[^2]:
|
||||
[^3]:
|
||||
Note that for Google Analytics, the data value must be an integer.
|
||||
|
||||
[`note`](#+analytics.feedback.ratings.note){ #+analytics.feedback.ratings.note }
|
||||
|
@ -4,8 +4,4 @@
|
||||
{% if config.extra.analytics %}
|
||||
{% set property = config.extra.analytics.property | d("", true) %}
|
||||
{% endif %}
|
||||
{% if property.startswith("G-") %}
|
||||
<script id="__analytics">function __md_analytics(){function n(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","{{ property }}"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){this.value&&n("event","search",{search_term:this.value})}),document$.subscribe(function(){var a=document.forms.feedback;if(void 0!==a)for(var e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");n("event","feedback",{page:t,data:e}),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}),location$.subscribe(function(e){n("config","{{ property }}",{page_path:e.pathname})})});var e=document.createElement("script");e.async=!0,e.src="https://www.googletagmanager.com/gtag/js?id={{ property }}",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
|
||||
{% elif property.startswith("UA-") %}
|
||||
<script id="__analytics">function __md_analytics(){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))}),document$.subscribe(function(){var a=document.forms.feedback;if(void 0!==a)for(var e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");ga("send","event","feedback","click",t,e),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}),location$.subscribe(function(e){ga("send","pageview",e.pathname)})});var e=document.createElement("script");e.async=!0,e.src="https://www.google-analytics.com/analytics.js",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
|
||||
{% endif %}
|
||||
|
@ -25,8 +25,7 @@
|
||||
{% set property = config.extra.analytics.property | d("", true) %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Google Analytics 4 (G-XXXXXXXXXX) -->
|
||||
{% if property.startswith("G-") %}
|
||||
<!-- Integrate with Google Analytics 4 -->
|
||||
<script id="__analytics">
|
||||
function __md_analytics() {
|
||||
window.dataLayer = window.dataLayer || []
|
||||
@ -96,79 +95,3 @@
|
||||
container.insertAdjacentElement("afterEnd", script)
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Universal Analytics (UA-XXXXXXXX-X) -->
|
||||
{% elif property.startswith("UA-") %}
|
||||
<script id="__analytics">
|
||||
function __md_analytics() {
|
||||
window.ga = window.ga || function() {
|
||||
(ga.q = ga.q || []).push(arguments)
|
||||
}
|
||||
ga.l = +new Date()
|
||||
|
||||
/* Set up integration and send page view */
|
||||
ga("create", "{{ property }}", "auto")
|
||||
ga("set", "anonymizeIp", true)
|
||||
ga("send", "pageview")
|
||||
|
||||
/* Register event handlers after documented loaded */
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
/* Set up search tracking */
|
||||
if (document.forms.search) {
|
||||
var query = document.forms.search.query
|
||||
query.addEventListener("blur", function() {
|
||||
if (this.value) {
|
||||
var page = document.location.pathname;
|
||||
ga("send", "pageview", page + "?q=" + this.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* Set up feedback, i.e. "Was this page helpful?" */
|
||||
document$.subscribe(function() {
|
||||
var feedback = document.forms.feedback
|
||||
if (typeof feedback === "undefined")
|
||||
return
|
||||
|
||||
/* Send feedback to Google Analytics */
|
||||
for (var button of feedback.querySelectorAll("[type=submit]")) {
|
||||
button.addEventListener("click", function(ev) {
|
||||
ev.preventDefault()
|
||||
|
||||
/* Retrieve and send data */
|
||||
var page = document.location.pathname
|
||||
var data = this.getAttribute("data-md-value")
|
||||
ga("send", "event", "feedback", "click", page, data)
|
||||
|
||||
/* Disable form and show note, if given */
|
||||
feedback.firstElementChild.disabled = true
|
||||
var note = feedback.querySelector(
|
||||
".md-feedback__note [data-md-value='" + data + "']"
|
||||
)
|
||||
if (note)
|
||||
note.hidden = false
|
||||
})
|
||||
|
||||
/* Show feedback */
|
||||
feedback.hidden = false
|
||||
}
|
||||
})
|
||||
|
||||
/* Send page view on location change */
|
||||
location$.subscribe(function(url) {
|
||||
ga("send", "pageview", url.pathname)
|
||||
})
|
||||
})
|
||||
|
||||
/* Create script tag */
|
||||
var script = document.createElement("script")
|
||||
script.async = true
|
||||
script.src = "https://www.google-analytics.com/analytics.js"
|
||||
|
||||
/* Inject script tag */
|
||||
var container = document.getElementById("__analytics")
|
||||
container.insertAdjacentElement("afterEnd", script)
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user