The tracking code given by Google Analytics looks like this :
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-131327483-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-131327483-1');
</script>
Just wanted to share something that I did to get it to work.
In my dash app, I added the following lines:
app.scripts.config.serve_locally = False
app.scripts.append_script({
'external_url': 'https://cdn.jsdelivr.net/gh/lppier/lppier.github.io/async_src.js'
})
app.scripts.append_script({
'external_url': 'https://cdn.jsdelivr.net/gh/lppier/lppier.github.io/gtag.js'
})
where async_src.js is the javascript contents I got after entering “https://www.googletagmanager.com/gtag/js?id=UA-131327483-1” in the browser.
and
gtag.js is the
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-131327483-1');
I followed the steps here : https://stackoverflow.com/questions/17341122/link-and-execute-external-javascript-file-hosted-on-github to serve my javascript (hosted in github pages) via jsDelivr.
Hope this helps someone out there, and do let me know if there’s an easier way of doing this!