3
votes

I was rending map with my google analytics data using embed api as:


    (function(w,d,s,g,js,fs){
      g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
      js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
      js.src='https://apis.google.com/js/platform.js';
      fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
    }(window,document,'script'));

    gapi.analytics.auth.authorize({
       serverAuth: {
           access_token: 'my access token' 
        }
    )};

    var commonConfig2 = {
       query: {
           ids: 'ga:' + gaViewId,
           metrics: 'ga:users',
           dimensions: 'ga:region',
           'max-results': 5,
           sort : '-ga:users'   
        },
           chart: {
           type: 'GEO',
           container: 'timeline',
           options: {
              displayMode: 'markers',
              width: '100%' 
           }
        }
    };

    var dataChart3 = new gapi.analytics.googleCharts.DataChart(commonConfig2)
          .set({query: dateRange1})
          .set({chart: {container: 'chart-3-container'}});

Map was rendering fine. But few days back i got error "Google Maps API error: MissingKeyMapError" and map is no longer rending. After some googling i came to know that google now require Api key to access its api. How can i set api key with my existing code.

2
You know I am not all that sure you can. I am thinking its built into the Embeded API. I am going to ping Google on this, see if they respond might take a while they are west cost USA.DaImTo
Thanks @DaImTo will be waiting.Sadia
don't use analytics, so i'm guessing this doesn't apply? --> Specify a key when loading the apiWhiteHat
@WhiteHat post editted please check how gapi is initialized. not able to set key.Sadia

2 Answers

3
votes

This took a little emailing back and forth with the team at Google.

It appears that the Maps API has changed and now requires that you send an key to access it.

The embedded API was not designed to allow you to send a key it assumed that one was not needed.

Status: At this time no one is working on the Embedded API and the code for it is not open source. Maps in the Embedded API are broken until further notice. My Google contact was unable to tell me when or if it would be fixed in the future.

4
votes

I noticed the same issue today, after many attemps and no documentation I've got it working again!

Here is what you need to do:

  1. Go to https://console.developers.google.com, select your project and enable on it the Google Maps Geocoding API and the Google Maps JavaScript API (for the second one, keep note of the API_KEY and set your allowed referrer urls);
  2. In your sources, ensure to import the following scripts:

    <script src="https://www.google.com/jsapi"></script>
    <script src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script>
    

That's all, now your Embed API maps will restart to draw the location data with no errors or warnings. It would be better if that was written on Google Analytics Embed API documentation (as of now, it has been also removed the map sample on the website)