Add Google Analytics

MkDocs

For the mkdocs theme:

theme:
  name: mkdocs
  analytics:
    gtag: G-xxxxxxxxxx

ReadTheDocs

For the readthedocs theme:

theme:
  name: readthedocs
  analytics:
    gtag: G-xxxxxxxxxx

Material

For the material theme:

theme:
  name: material

extra:
  analytics:
    provider: google
    property: G-xxxxxxxxxx

Others

If it cannot be configured directly from mkdocs.yml, you can override the base.html file:

{% extends "base.html" %}

{% block extrahead %}
  {{ super() }}
  <!-- Google tag (gtag.js) -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxxxx"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'G-xxxxxxxxxx');
  </script>
{% endblock %}