0

I am trying to add the Google Analytics Embed API to a tabbed Reports page in my MVC 5 Web App. I am using these instructions.

https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started

I added the main function to the $(document).ready(function (), which is in an external Javascript file that gets called in the main Index View for the tabbed Reports page. I then created a PartialView called _GooglePartial. The PartialView contains the rest of the code along with the other Javascript code.

I've set alerts all throughout the code. The first time the entire page loads and everything gets called.

I get the Google login button and I can login. After log in, it displays the email of the logged in user. I now notice that the Javascript code does not call my Step 4 alert as shown below.

Step 4: Create the view selector. alert('Step 4');

Here is how I am calling the _GooglePartial View. This is in my external Javascript file.

getGoogleData: function () {
        var url = '/Reports/GetGoogleData';
        myapp.GetNoParam(
            url,
            function (result) {
                $('div#filter-content').html(result);
            }
        );
    },

I had to use this to get my Google Map code to work correctly in another Page/View, so I believe I have to do something similar with platform.js, but I have no idea how to make it work.

function loadScript() {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' +
                'callback=initMap' + '&key=SOMEKEY';
            document.body.appendChild(script);
        }

        window.onload = loadScript;

Does anyone know how to get this to work? I'm trying to display Google Analytics (their own) to my user's in a multi-tenant application. Perhaps there is a better way to do this in an MVC 5 App.

Any help is much appreciated! Thanks!

Dumber_Texan2
  • 840
  • 2
  • 12
  • 34

1 Answers1

0

This alternate script is what worked for me. All the script code is now running in the _GooglePartial View and nothing related to the Google Analytics Embed AI is running in the external JavaScript file. This means that it is not being called from the $(document).ready(function ().

https://stackoverflow.com/a/34920516

I'm also using this slick method of getting around the ViewSelector issue. I'm able to use this because I already have the user's permission and the RefreshToken.

https://stackoverflow.com/a/53791128/5360237

Dumber_Texan2
  • 840
  • 2
  • 12
  • 34