2.2 KiB
template |
---|
overrides/main.html |
Setting up site analytics
As with any other service that is offered on the web, understanding how your documentation is actually used can be an essential success factor. While Material for MkDocs natively integrates with Google Analytics, other analytics services can be used, too.
Configuration
Site analytics
:octicons-file-code-24: Source · :octicons-milestone-24: Default: none
After heading over to your Google Analytics account to create a new
property in order to obtain a new tracking id of the form UA-XXXXXXXX-X
,
add it to mkdocs.yml
:
google_analytics:
- UA-XXXXXXXX-X
- auto
Publish and refresh your site, and you should see events bubbling up.
Site search analytics
Besides basic page views, site search can also be tracked to better understand how people use your documentation and what they expect to find. To enable search tracking:
- Go to your Google Analytics admin settings
- Select the property for the respective tracking code
- Go to the view settings tab.
- Scroll down and enable site search settings
- Set the query parameter to
q
.
Customization
Other analytics services
:octicons-file-code-24: Source · :octicons-mortar-board-24: Difficulty: easy
In order to integrate another analytics service provider offering an
asynchronous JavaScript-based tracking solution, you can extend the theme
and override the analytics
block.
Instant loading
:octicons-file-code-24: Source · :octicons-mortar-board-24: Difficulty: easy
If you're using instant loading, you can use the DOMContentSwitch
event
to listen for navigation events and register a page view event with:
document.addEventListener("DOMContentSwitch", function() {
/* Register page event here */
})