Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Adding Google Analytics Global Site Tag

Hi everyone,

Now that Google Analytics has moved away from analytics.js to gtag.js, how does one add the tracking script to the dash app ? As previously it looked like:

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-39373211-1', 'auto');
ga('send', 'pageview');

and now it with gtag.js it looks like:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-111343278-1');

With two scripts in the gtag.js, do I need to use app.scripts.append_script twice ?

Any help would be appreciated. Thanks !

analytics.js still works ! However, a workaround gtag.js would be great too !

1 Like

Hey I’m trying to get basic GA set up on my Dash app. I haven’t been able to find any success so far in getting that to work, js or otherwise. Could you provide a real quick overview of how to add GA to my app? I would be forever grateful :slight_smile:

Hi Stayup,

Kindly refer to my repo:

First you need to create a gtag.js script as in my repo. Then if you refer to at the end of the script, you can see I use

‘external_url’: ‘

Note that you need to put your gtag.js through rawgit.


1 Like