Forums

Google analytics

Hi,

How do I include Google analytics in my web app?

You need to set up Google Analytics (on a Google account) and put a script tag with tracking code to the pages you want to track.

I added the script tag provided by Google right after the <head> tag of the /mysite/templates/layout.html file, but it is not showing on my site pages. I am running Flask

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

    gtag('config', 'G-xxxxxxxxx);
</script>

Did you reload your web app after making the change?

Yes, a couple of times, just to be sure :-)

So, are you sure that that's the template that is actually rendered?

I was actually editing the template of a similar app that I have in pythonanywhere. Silly mistake. It is working fine now. Thank you

Glad to hear that you made it work!