openxla / community

Stores documents and resources used by the OpenXLA developer community
Apache License 2.0
106 stars 23 forks source link

Enable Google Analytics #73

Closed pcoet closed 1 year ago

pcoet commented 1 year ago

This commit enables Google Analytics 4, following these instructions.

If you inspect the generated HTML, you should find something like this in the head of each page:

<script id="__analytics">function __md_analytics(){function n(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","G-Z67BRKDG1B"),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","G-Z67BRKDG1B",{page_path:e.pathname})})});var e=document.createElement("script");e.async=!0,e.src="https://www.googletagmanager.com/gtag/js?id=G-Z67BRKDG1B",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>

It's also possible to ask for cookie consent, as described at Ensuring data privacy. I'm not sure if we need to enable this, but I'll follow up. NOTE: Ad blockers seem to prevent the cookie consent, so if we do enable this, we need to test in a browser without ad blocking.