Google Analytics in Dash Web Apps

You’ve made a fantastic web app in dash, flexing some of those end-to-end data science skills, and want to see what kind of web traffic you are siphoning. Well how exactly do you get a grasp of where your biggest fans are from?! Using google analytics of course.

Suggestions on plotly’s community forum, issues on git hub, and stackoverflow eventually let me to plotly’s docs and a pieced together solution. You can customize dash’s HTML directly in your python script with the javascript that links google analytics to your webapp. So you would add the following snippet to your Dash app script, replacing “UA-XXXXXXX” with your google analytics tracker id.

Similarly if you want to work with google tag manager you can follow instructions here.

Potential useful links if you are on a similar quest: