Embed API

Basic Dashboard

Demo Overview

This demos shows how to create a basic dashboard with a single timeline chart showing site traffic over the past week. You can update the chart to see data for any Google Analytics view you have access to.


Last 30 days

How it works

You can recreate the demo above by copy and pasting the following code into an HTML file running on a web server. Feel free to add some CSS to spice it up a bit!

If you want to know more, check out the Embed API documentation on our developers site.

Step 1: Load the Embed API library.


Step 2: Add HTML containers to host the dashboard components.

<div id="embed-api-auth-container"></div>
<div id="chart-container"></div>
<div id="view-selector-container"></div>

Step 3: Write the dashboard code.


gapi.analytics.ready(function() {

   * Authorize the user immediately if the user has already granted access.
   * If no access has been created, render an authorize button inside the
   * element with the ID "embed-api-auth-container".
    container: 'embed-api-auth-container',

   * Create a new ViewSelector instance to be rendered inside of an
   * element with the id "view-selector-container".
  var viewSelector = new gapi.analytics.ViewSelector({
    container: 'view-selector-container'

  // Render the view selector to the page.

   * Create a new DataChart instance with the given query parameters
   * and Google chart options. It will be rendered inside an element
   * with the id "chart-container".
  var dataChart = new gapi.analytics.googleCharts.DataChart({
    query: {
      metrics: 'ga:sessions',
      dimensions: 'ga:date',
      'start-date': '30daysAgo',
      'end-date': 'yesterday'
    chart: {
      container: 'chart-container',
      type: 'LINE',
      options: {
        width: '100%'

   * Render the dataChart on the page whenever a new view is selected.
  viewSelector.on('change', function(ids) {
    dataChart.set({query: {ids: ids}}).execute();