Search code examples
google-analytics-apifirebase-hosting

Google Analytics Embed API with Server Side Authorization - Firebase Hosting


I completed the basic setup for Google Analytics and inserted the tracking code into my webpage(s). I can log in to analytics.google.com and see historical data just fine.

I have an admin page on my website where I want to display Google Analytics information to several users automatically (no additional logon req'd) and read that this is possible using the Embed API with Server-side Authorization.

I followed the instructions and created a Service Account that shows up under Service account keys in my Google API Manager portal. I also successfully ran 'sudo pip install --upgrade google-api-python-client' on my Cloud9 IDE and pushed the change to my hosting provider, Firebase, i.e. 'firebase deploy'. Lastly, I located and pasted my Analytics View ID in to the code sample provided with the Demo/Setup. My page is served with <!DOCTYPE html> declared.

I can't get it to work. Browser console says:

Uncaught TypeError: window.google.load is not a function

I am thinking that I am not invoking the get_access_token() in that Python module. In other words, I am thinking that server-side scripting is not supported with Firebase hosting.

Anyone know if and how to get Google Analytics Embed API with Server Side Authorization running with Firebase hosting?


Solution

  • This is not exactly a direct answer to your question, but rather an alternative solution to this problem. At least I’m using approach.

    You can use Google Design Studio to build and embed amazing analytics and BI dashboards anywhere you like (also on your Admin website). But even easier would be to use Google’s authentication (via gmail) to provide access to select dashboards directly, as Google’s authentication and authorisation is likely more secure that your website’s.