Feature request: cookie consent
See original GitHub issueStruggled with adding a cookie consent banner via Google Tag Manager (GTM) injection until a frontend colleague helped. Since I could not find anything about this topic related to mkdocs or mkdocs material I thought I’d open an issue here for others to google. Could maybe be added as a feature if relevant for more people, otherwise feel free to close soon.
HOWTO: Use the mkdocs theme override functionality and create a main.html
file with the following javascript code taken from here. The first, custom part of the code ensures that the GTM is not being active when running mkdocs serve
locally since this blocks from interacting with the site. Also see this PR and repository as an example for the structure of the overrides.
<!-- Elements added to main will be displayed on all pages -->
{% extends "base.html" %}
{% block libs %}
<!-- Google Tag Manager -->
<script>
var gtmId = 'GTM-YOURGTMCODE;
if (typeof window !== 'undefined' && window.location.href.includes('127.0.0.1')) {
gtmId = 'GTM-XXX'
}
(function(w,d,s,l,i){
w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer', gtmId);
</script>
<!-- End Google Tag Manager -->
{% endblock %}
Description
If this would be added by default I could imagine it being used similarly to the Google Analytics tag in the mkdocs.yml file. Depending on your GTM configuration adds a cookie banner. However probably not relevant for too many users. Don’t know much about cookies and was also told that when using Google Analytics anonymized this would not actually be neccessary (was still decided to add it for the future).
Screenshots / Mockups
- … the documentation does not mention anything about my idea
- … to my best knowledge, my idea wouldn’t break something for other users
- … there are no open or closed issues that are related to my idea
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:32 (25 by maintainers)
Top GitHub Comments
I’ve moved other features up the priority list, but I will try to provide a simple yes/no implementation in the coming weeks!
Thank you all for the input on this topic. I’m still wondering whether there’s any value in providing a completely self-contained solution for this, i.e. asking the user, setting a value in local storage, and firing an event when the value in local storage allows for tracking. What we could do is provide a simple yes/no solution for Google Analytics. Anything else would require some customizations, obviously, as there are too many potential services to integrate. So wrapping this in a template block could work.