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,27 +16,21 @@ MkDocs natively integrates with [Google Analytics] and offers a customizable
|
|||||||
[:octicons-tag-24: 7.1.8][Google Analytics support] ·
|
[:octicons-tag-24: 7.1.8][Google Analytics support] ·
|
||||||
:octicons-milestone-24: Default: _none_
|
:octicons-milestone-24: Default: _none_
|
||||||
|
|
||||||
Material for MkDocs integrates with both, Google Analytics 4 and the now phasing
|
Material for MkDocs integrates natively with Google Analytics 4[^1]. If you
|
||||||
out Universal Analytics. Depending on the given property prefix, add the
|
already set up Google Analytics and have a property, enable it by adding the
|
||||||
following lines to `mkdocs.yml`:
|
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
|
``` yaml
|
||||||
extra:
|
extra:
|
||||||
analytics:
|
analytics:
|
||||||
provider: google
|
provider: google
|
||||||
property: G-XXXXXXXXXX
|
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
|
[Google Analytics support]: https://github.com/squidfunk/mkdocs-material/releases/tag/7.1.8
|
||||||
|
|
||||||
@ -46,21 +40,11 @@ following lines to `mkdocs.yml`:
|
|||||||
understand how people use your documentation and what they expect to find.
|
understand how people use your documentation and what they expect to find.
|
||||||
In order to enable site search tracking, the following steps are required:
|
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
|
||||||
1. Go to your Google Analytics __admin settings__
|
3. Select the __data streams__ tab and click the corresponding URL
|
||||||
2. Select the property for the respective tracking code
|
4. Click the gear icon within the __enhanced measurement__ section
|
||||||
3. Select the __data streams__ tab and click the corresponding URL
|
5. Ensure that __site search__ is enabled
|
||||||
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
|
[site search]: setting-up-site-search.md
|
||||||
|
|
||||||
@ -102,9 +86,9 @@ extra:
|
|||||||
Both properties, `title` and `ratings`, are required. Note that it's allowed to
|
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
|
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
|
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
|
If the user doesn't accept the `analytics` cookie, the feedback widget is
|
||||||
not shown.
|
not shown.
|
||||||
|
|
||||||
@ -114,46 +98,35 @@ integrated with the [cookie consent] feature[^1].
|
|||||||
[Google Analytics] that will quickly show you the worst- and best-rated
|
[Google Analytics] that will quickly show you the worst- and best-rated
|
||||||
pages of your project documentation.
|
pages of your project documentation.
|
||||||
|
|
||||||
=== ":material-google-analytics: Google Analytics 4"
|
1. Go to your Google Analytics __dashboard__
|
||||||
|
|
||||||
1. Go to your Google Analytics __dashboard__
|
2. Go to the __configure__ page on the left hand menu, then select
|
||||||
|
__custom definitions__
|
||||||
|
|
||||||
2. Go to the __configure__ page on the left hand menu, then select
|
3. Click the __custom metrics__ tab and then __create custom metrics__,
|
||||||
__custom definitions__
|
enter the following values:
|
||||||
|
|
||||||
3. Click the __custom metrics__ tab and then __create custom metrics__,
|
* Metric name: Page helpful
|
||||||
enter the following values:
|
* Description: Was this page helpful?
|
||||||
|
* Event parameter: `data`
|
||||||
|
* Unit of measurement: Standard
|
||||||
|
|
||||||
* Metric name: Page helpful
|
4. Go to the __explore__ page on the left hand menu, create a new
|
||||||
* Description: Was this page helpful?
|
__blank exploration__
|
||||||
* Event parameter: `data`
|
|
||||||
* Unit of measurement: Standard
|
|
||||||
|
|
||||||
4. Go to the __explore__ page on the left hand menu, create a new
|
5. Configure the report as follows:
|
||||||
__blank exploration__
|
|
||||||
|
|
||||||
5. Configure the report as follows:
|
* Dimensions: Add `Event name` and `Page location`
|
||||||
|
* Metrics: Add `Event count` and `Page helpful`
|
||||||
|
(the custom metric created in step 3)
|
||||||
|
* Rows: `Page location`
|
||||||
|
* Values: Drag in both `Event count` and `Page helpful`
|
||||||
|
* Filters: Add a new filter for
|
||||||
|
`Event name / exactly matches / feedback`
|
||||||
|
|
||||||
* Dimensions: Add `Event name` and `Page location`
|
!!! warning "Delay in data availability"
|
||||||
* Metrics: Add `Event count` and `Page helpful`
|
|
||||||
(the custom metric created in step 3)
|
|
||||||
* Rows: `Page location`
|
|
||||||
* Values: Drag in both `Event count` and `Page helpful`
|
|
||||||
* Filters: Add a new filter for
|
|
||||||
`Event name / exactly matches / feedback`
|
|
||||||
|
|
||||||
!!! warning "Delay in data availability"
|
The report may take 24 hours or longer to begin displaying data
|
||||||
|
|
||||||
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,
|
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
|
you'll have a list of all pages with the total number of ratings, and an
|
||||||
@ -185,9 +158,9 @@ The following properties are available for each rating:
|
|||||||
|
|
||||||
: :octicons-milestone-24: Default: _none_ · :octicons-alert-24: __Required__ –
|
: :octicons-milestone-24: Default: _none_ · :octicons-alert-24: __Required__ –
|
||||||
The value of this property is sent as a data value with the custom event
|
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 that for Google Analytics, the data value must be an integer.
|
||||||
|
|
||||||
[`note`](#+analytics.feedback.ratings.note){ #+analytics.feedback.ratings.note }
|
[`note`](#+analytics.feedback.ratings.note){ #+analytics.feedback.ratings.note }
|
||||||
|
@ -4,8 +4,4 @@
|
|||||||
{% if config.extra.analytics %}
|
{% if config.extra.analytics %}
|
||||||
{% set property = config.extra.analytics.property | d("", true) %}
|
{% set property = config.extra.analytics.property | d("", true) %}
|
||||||
{% endif %}
|
{% 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>
|
||||||
<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,150 +25,73 @@
|
|||||||
{% set property = config.extra.analytics.property | d("", true) %}
|
{% set property = config.extra.analytics.property | d("", true) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Google Analytics 4 (G-XXXXXXXXXX) -->
|
<!-- Integrate with Google Analytics 4 -->
|
||||||
{% if property.startswith("G-") %}
|
<script id="__analytics">
|
||||||
<script id="__analytics">
|
function __md_analytics() {
|
||||||
function __md_analytics() {
|
window.dataLayer = window.dataLayer || []
|
||||||
window.dataLayer = window.dataLayer || []
|
function gtag() { dataLayer.push(arguments) }
|
||||||
function gtag() { dataLayer.push(arguments) }
|
|
||||||
|
|
||||||
/* Set up integration and send page view */
|
/* Set up integration and send page view */
|
||||||
gtag("js", new Date())
|
gtag("js", new Date())
|
||||||
gtag("config", "{{ property }}")
|
gtag("config", "{{ property }}")
|
||||||
|
|
||||||
/* Register event handlers after documented loaded */
|
/* Register event handlers after documented loaded */
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
/* Set up search tracking */
|
/* Set up search tracking */
|
||||||
if (document.forms.search) {
|
if (document.forms.search) {
|
||||||
var query = document.forms.search.query
|
var query = document.forms.search.query
|
||||||
query.addEventListener("blur", function() {
|
query.addEventListener("blur", function() {
|
||||||
if (this.value)
|
if (this.value)
|
||||||
gtag("event", "search", { search_term: this.value })
|
gtag("event", "search", { search_term: 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")
|
|
||||||
gtag("event", "feedback", { 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) {
|
|
||||||
gtag("config", "{{ property }}", {
|
|
||||||
page_path: url.pathname
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Create script tag */
|
|
||||||
var script = document.createElement("script")
|
|
||||||
script.async = true
|
|
||||||
script.src = "https://www.googletagmanager.com/gtag/js?id={{ property }}"
|
|
||||||
|
|
||||||
/* Inject script tag */
|
|
||||||
var container = document.getElementById("__analytics")
|
|
||||||
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 */
|
/* Set up feedback, i.e. "Was this page helpful?" */
|
||||||
ga("create", "{{ property }}", "auto")
|
document$.subscribe(function() {
|
||||||
ga("set", "anonymizeIp", true)
|
var feedback = document.forms.feedback
|
||||||
ga("send", "pageview")
|
if (typeof feedback === "undefined")
|
||||||
|
return
|
||||||
|
|
||||||
/* Register event handlers after documented loaded */
|
/* Send feedback to Google Analytics */
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
for (var button of feedback.querySelectorAll("[type=submit]")) {
|
||||||
|
button.addEventListener("click", function(ev) {
|
||||||
|
ev.preventDefault()
|
||||||
|
|
||||||
/* Set up search tracking */
|
/* Retrieve and send data */
|
||||||
if (document.forms.search) {
|
var page = document.location.pathname
|
||||||
var query = document.forms.search.query
|
var data = this.getAttribute("data-md-value")
|
||||||
query.addEventListener("blur", function() {
|
gtag("event", "feedback", { page, data })
|
||||||
if (this.value) {
|
|
||||||
var page = document.location.pathname;
|
/* Disable form and show note, if given */
|
||||||
ga("send", "pageview", page + "?q=" + this.value)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
/* Send page view on location change */
|
||||||
var script = document.createElement("script")
|
location$.subscribe(function(url) {
|
||||||
script.async = true
|
gtag("config", "{{ property }}", {
|
||||||
script.src = "https://www.google-analytics.com/analytics.js"
|
page_path: url.pathname
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
/* Inject script tag */
|
/* Create script tag */
|
||||||
var container = document.getElementById("__analytics")
|
var script = document.createElement("script")
|
||||||
container.insertAdjacentElement("afterEnd", script)
|
script.async = true
|
||||||
}
|
script.src = "https://www.googletagmanager.com/gtag/js?id={{ property }}"
|
||||||
</script>
|
|
||||||
{% endif %}
|
/* Inject script tag */
|
||||||
|
var container = document.getElementById("__analytics")
|
||||||
|
container.insertAdjacentElement("afterEnd", script)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user