Adding google analytics to your custom gadget

What you need

It took me a while to find out how to do this, but it’s really simple.Implementing this means that you can track usage of your gadget, whether embedded in a web page, or in  a Google doc.

What you need to do
  • Add a new domain to your google analytics account. Just make one up – in my case I used It doesn’t need to exist, and you dont need to own it. It just needs to look like a real domain.
  • Remember the  UA-xxxxx-n code that Analytics generates for that domain.
  • Think of an imaginary page address – this is what views will get recorded against in your analytics report. Again – it doesn’t need to exist.
  • Inject this into your in your XML code
    var ga = new _IG_GA(‘UA-10017268-2’);
  • And this in your XML

     Require feature=”setprefs” / 
     Require feature=”” / 


You are good to go. Shortly afterwards analytics will start reporting on accesses to you gadget, under the domain and page you settled on.


About brucemcp 223 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.

Be the first to comment

Leave a Reply

Your email address will not be published.


two × 1 =