Use Embed API to embed Google Analytics location map view

喜欢而已 提交于 2019-12-30 07:18:48

问题


THe below is a screenshot of a view on the Google analytics website (Geo > Location > Primary Dimension = city)

I would like to embed this exact view or replicate it as similarly as possible using google's Embed API and display it on my own site.

I have followed the tutorial here > https://developers.google.com/analytics/devguides/reporting/embed/v1/devguide and got the simple line graph working on my site but I cant seem to find any information showing how to add the map functionallity, the pie chart, or the table like we see in the below.

Are there any good examples or tutorials that could help me with this?

I tried the documentation but I just dont see a lot of explanation regarding what you can create with the API.


回答1:


How about something like this? http://jsbin.com/relufutenuto/2/edit

You can set chart options based on the options allowed by the various Google chart libraries. Here's the Google chart documentation for the chart type GEO: https://developers.google.com/chart/interactive/docs/gallery/geochart#Configuration_Options

Note: you might have to disable pop-up blockers to get auth to work in jsbin, but this should give you the idea.

Here's the part of the code that sets the chart type of options:

var timeline = new gapi.analytics.googleCharts.DataChart({
  query: {
    'ids': 'ga:1234',
    'dimensions': 'ga:country',
    'metrics': 'ga:sessions',
    'start-date': '30daysAgo',
    'end-date': 'yesterday',
  },
  chart: {
    type: 'GEO',
    container: 'timeline',
    options: {
      region: '155', // Western Europe
      displayMode: 'markers'
    }
  }
});


来源:https://stackoverflow.com/questions/25944787/use-embed-api-to-embed-google-analytics-location-map-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!