{"action":"created","issue":{"url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/51","labels_url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/51/comments","events_url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/51/events","html_url":"https://github.com/googleanalytics/ga-dev-tools/issues/51","id":65580008,"number":51,"title":"Trouble replicating 3rd Party Visualizations Demo","user":{"login":"kulander","id":11746036,"avatar_url":"https://avatars.githubusercontent.com/u/11746036?v=3","gravatar_id":"","url":"https://api.github.com/users/kulander","html_url":"https://github.com/kulander","followers_url":"https://api.github.com/users/kulander/followers","following_url":"https://api.github.com/users/kulander/following{/other_user}","gists_url":"https://api.github.com/users/kulander/gists{/gist_id}","starred_url":"https://api.github.com/users/kulander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kulander/subscriptions","organizations_url":"https://api.github.com/users/kulander/orgs","repos_url":"https://api.github.com/users/kulander/repos","events_url":"https://api.github.com/users/kulander/events{/privacy}","received_events_url":"https://api.github.com/users/kulander/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-01T01:16:50Z","updated_at":"2015-04-01T06:06:01Z","closed_at":null,"body":"I am replicating Google Analytics Embed API demos. So far, I have been able to replicate the basic dashboard, multiple date ranges, multiple views and interactive charts using my clientid.\r\nThe one that is giving me trouble is the Third Party Visualizations and I am following the steps according to what is posted. By the way for step number three I am using the full path \"https://ga-dev-tools.appspot.com/public/...\".\r\nOnce I log in using my Google Account, all I get is the embed-api-auth-container but not the charts. I am using the following html code:\r\n```\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n<title>Demo</title>\r\n<script>\r\n(function(w,d,s,g,js,fs){\r\n  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};\r\n  js=d.createElement(s);fs=d.getElementsByTagName(s)[0];\r\n  js.src='https://apis.google.com/js/platform.js';\r\n  fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};\r\n}(window,document,'script'));\r\n</script>\r\n</head>\r\n<body>\r\n<div id=\"embed-api-auth-container\"></div>\r\n<div id=\"view-selector-container\"></div>\r\n<div id=\"active-users-container\"></div>\r\n<div id=\"chart-1-container\"></div>\r\n<div id=\"legend-1-container\"></div>\r\n<div id=\"chart-2-container\"></div>\r\n<div id=\"legend-2-container\"></div>\r\n<div id=\"chart-3-container\"></div>\r\n<div id=\"legend-3-container\"></div>\r\n<div id=\"chart-4-container\"></div>\r\n<div id=\"legend-4-container\"></div>\r\n</body>\r\n<!-- This demo uses the Chart.js graphing library and Moment.js to do date\r\n     formatting and manipulation. -->\r\n<script src=\"https://ga-dev-tools.appspot.com/public/javascript/Chart.min.js\"></script>\r\n<script src=\"https://ga-dev-tools.appspot.com/public/javascript/moment.min.js\"></script>\r\n\r\n<!-- Include the ViewSelector2 component script. -->\r\n<script src=\"https://ga-dev-tools.appspot.com/public/javascript/embed-api/view-selector2.js\"></script>\r\n\r\n<!-- Include the DateRangeSelector component script. -->\r\n<script src=\"https://ga-dev-tools.appspot.com/public/javascript/embed-api/date-range-selector.js\"></script>\r\n\r\n<!-- Include the ActiveUsers component script. -->\r\n<script src=\"https://ga-dev-tools.appspot.com/public/javascript/embed-api/active-users.js\"></script>\r\n\r\n<script>\r\n\r\n// == NOTE ==\r\n// This code uses ES6 promises. If you want to use this code in a browser\r\n// that doesn't supporting promises natively, you'll have to include a polyfill.\r\n\r\ngapi.analytics.ready(function() {\r\n\r\n  /**\r\n   * Authorize the user immediately if the user has already granted access.\r\n   * If no access has been created, render an authorize button inside the\r\n   * element with the ID \"embed-api-auth-container\".\r\n   */\r\n  gapi.analytics.auth.authorize({\r\n    container: 'embed-api-auth-container',\r\n    clientid: '210186284123-v4md8kq7c02622er75pm0mjbo3sbcu1d.apps.googleusercontent.com',\r\n  });\r\n\r\n\r\n  /**\r\n   * Create a new ActiveUsers instance to be rendered inside of an\r\n   * element with the id \"active-users-container\" and poll for changes every\r\n   * five seconds.\r\n   */\r\n  var activeUsers = new gapi.analytics.ext.ActiveUsers({\r\n    container: 'active-users-container',\r\n    pollingInterval: 5\r\n  });\r\n\r\n\r\n  /**\r\n   * Add CSS animation to visually show the when users come and go.\r\n   */\r\n  activeUsers.once('success', function() {\r\n    var element = this.container.firstChild;\r\n    var timeout;\r\n\r\n    this.on('change', function(data) {\r\n      var element = this.container.firstChild;\r\n      var animationClass = data.delta > 0 ? 'is-increasing' : 'is-decreasing';\r\n      element.className += (' ' + animationClass);\r\n\r\n      clearTimeout(timeout);\r\n      timeout = setTimeout(function() {\r\n        element.className =\r\n            element.className.replace(/ is-(increasing|decreasing)/g, '');\r\n      }, 3000);\r\n    });\r\n  });\r\n\r\n\r\n  /**\r\n   * Create a new ViewSelector2 instance to be rendered inside of an\r\n   * element with the id \"view-selector-container\".\r\n   */\r\n  var viewSelector = new gapi.analytics.ext.ViewSelector2({\r\n    container: 'view-selector-container',\r\n  })\r\n  .execute();\r\n\r\n\r\n  /**\r\n   * Update the activeUsers component, the Chartjs charts, and the dashboard\r\n   * title whenever the user changes the view.\r\n   */\r\n  viewSelector.on('viewChange', function(data) {\r\n    var title = document.getElementById('view-name');\r\n    title.innerHTML = data.property.name + ' (' + data.view.name + ')';\r\n\r\n    // Start tracking active users for this view.\r\n    activeUsers.set(data).execute();\r\n\r\n    // Render all the of charts for this view.\r\n    renderWeekOverWeekChart(data.ids);\r\n    renderYearOverYearChart(data.ids);\r\n    renderTopBrowsersChart(data.ids);\r\n    renderTopCountriesChart(data.ids);\r\n  });\r\n\r\n\r\n  /**\r\n   * Draw the a chart.js line chart with data from the specified view that\r\n   * overlays session data for the current week over session data for the\r\n   * previous week.\r\n   */\r\n  function renderWeekOverWeekChart(ids) {\r\n\r\n    // Adjust `now` to experiment with different days, for testing only...\r\n    var now = moment(); // .subtract(3, 'day');\r\n\r\n    var thisWeek = query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:date,ga:nthDay',\r\n      'metrics': 'ga:sessions',\r\n      'start-date': moment(now).subtract(1, 'day').day(0).format('YYYY-MM-DD'),\r\n      'end-date': moment(now).format('YYYY-MM-DD')\r\n    });\r\n\r\n    var lastWeek = query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:date,ga:nthDay',\r\n      'metrics': 'ga:sessions',\r\n      'start-date': moment(now).subtract(1, 'day').day(0).subtract(1, 'week')\r\n          .format('YYYY-MM-DD'),\r\n      'end-date': moment(now).subtract(1, 'day').day(6).subtract(1, 'week')\r\n          .format('YYYY-MM-DD')\r\n    });\r\n\r\n    Promise.all([thisWeek, lastWeek]).then(function(results) {\r\n\r\n      var data1 = results[0].rows.map(function(row) { return +row[2]; });\r\n      var data2 = results[1].rows.map(function(row) { return +row[2]; });\r\n      var labels = results[1].rows.map(function(row) { return +row[0]; });\r\n\r\n      labels = labels.map(function(label) {\r\n        return moment(label, 'YYYYMMDD').format('ddd');\r\n      });\r\n\r\n      var data = {\r\n        labels : labels,\r\n        datasets : [\r\n          {\r\n            label: 'Last Week',\r\n            fillColor : \"rgba(220,220,220,0.5)\",\r\n            strokeColor : \"rgba(220,220,220,1)\",\r\n            pointColor : \"rgba(220,220,220,1)\",\r\n            pointStrokeColor : \"#fff\",\r\n            data : data2\r\n          },\r\n          {\r\n            label: 'This Week',\r\n            fillColor : \"rgba(151,187,205,0.5)\",\r\n            strokeColor : \"rgba(151,187,205,1)\",\r\n            pointColor : \"rgba(151,187,205,1)\",\r\n            pointStrokeColor : \"#fff\",\r\n            data : data1\r\n          }\r\n        ]\r\n      };\r\n\r\n      new Chart(makeCanvas('chart-1-container')).Line(data);\r\n      generateLegend('legend-1-container', data.datasets);\r\n    });\r\n  }\r\n\r\n\r\n  /**\r\n   * Draw the a chart.js bar chart with data from the specified view that\r\n   * overlays session data for the current year over session data for the\r\n   * previous year, grouped by month.\r\n   */\r\n  function renderYearOverYearChart(ids) {\r\n\r\n    // Adjust `now` to experiment with different days, for testing only...\r\n    var now = moment(); // .subtract(3, 'day');\r\n\r\n    var thisYear = query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:month,ga:nthMonth',\r\n      'metrics': 'ga:users',\r\n      'start-date': moment(now).date(1).month(0).format('YYYY-MM-DD'),\r\n      'end-date': moment(now).format('YYYY-MM-DD')\r\n    });\r\n\r\n    var lastYear = query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:month,ga:nthMonth',\r\n      'metrics': 'ga:users',\r\n      'start-date': moment(now).subtract(1, 'year').date(1).month(0)\r\n          .format('YYYY-MM-DD'),\r\n      'end-date': moment(now).date(1).month(0).subtract(1, 'day')\r\n          .format('YYYY-MM-DD')\r\n    });\r\n\r\n    Promise.all([thisYear, lastYear]).then(function(results) {\r\n      var data1 = results[0].rows.map(function(row) { return +row[2]; });\r\n      var data2 = results[1].rows.map(function(row) { return +row[2]; });\r\n      var labels = ['Jan','Feb','Mar','Apr','May','Jun',\r\n                    'Jul','Aug','Sep','Oct','Nov','Dec'];\r\n\r\n      // Ensure the data arrays are at least as long as the labels array.\r\n      // Chart.js bar charts don't (yet) accept sparse datasets.\r\n      for (var i = 0, len = labels.length; i < len; i++) {\r\n        if (data1[i] === undefined) data1[i] = null;\r\n        if (data2[i] === undefined) data2[i] = null;\r\n      }\r\n\r\n      var data = {\r\n        labels : labels,\r\n        datasets : [\r\n          {\r\n            label: 'Last Year',\r\n            fillColor : \"rgba(220,220,220,0.5)\",\r\n            strokeColor : \"rgba(220,220,220,1)\",\r\n            data : data2\r\n          },\r\n          {\r\n            label: 'This Year',\r\n            fillColor : \"rgba(151,187,205,0.5)\",\r\n            strokeColor : \"rgba(151,187,205,1)\",\r\n            data : data1\r\n          }\r\n        ]\r\n      };\r\n\r\n      new Chart(makeCanvas('chart-2-container')).Bar(data);\r\n      generateLegend('legend-2-container', data.datasets);\r\n    })\r\n    .catch(function(err) {\r\n      console.error(err.stack);\r\n    })\r\n  }\r\n\r\n\r\n  /**\r\n   * Draw the a chart.js doughnut chart with data from the specified view that\r\n   * show the top 5 browsers over the past seven days.\r\n   */\r\n  function renderTopBrowsersChart(ids) {\r\n\r\n    query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:browser',\r\n      'metrics': 'ga:pageviews',\r\n      'sort': '-ga:pageviews',\r\n      'max-results': 5\r\n    })\r\n    .then(function(response) {\r\n\r\n      var data = [];\r\n      var colors = ['#4D5360','#949FB1','#D4CCC5','#E2EAE9','#F7464A'];\r\n\r\n      response.rows.forEach(function(row, i) {\r\n        data.push({ value: +row[1], color: colors[i], label: row[0] });\r\n      });\r\n\r\n      new Chart(makeCanvas('chart-3-container')).Doughnut(data);\r\n      generateLegend('legend-3-container', data);\r\n    });\r\n  }\r\n\r\n\r\n  /**\r\n   * Draw the a chart.js doughnut chart with data from the specified view that\r\n   * compares sessions from mobile, desktop, and tablet over the past seven\r\n   * days.\r\n   */\r\n  function renderTopCountriesChart(ids) {\r\n    query({\r\n      'ids': ids,\r\n      'dimensions': 'ga:country',\r\n      'metrics': 'ga:sessions',\r\n      'sort': '-ga:sessions',\r\n      'max-results': 5\r\n    })\r\n    .then(function(response) {\r\n\r\n      var data = [];\r\n      var colors = ['#4D5360','#949FB1','#D4CCC5','#E2EAE9','#F7464A'];\r\n\r\n      response.rows.forEach(function(row, i) {\r\n        data.push({\r\n          label: row[0],\r\n          value: +row[1],\r\n          color: colors[i]\r\n        });\r\n      });\r\n\r\n      new Chart(makeCanvas('chart-4-container')).Doughnut(data);\r\n      generateLegend('legend-4-container', data);\r\n    });\r\n  }\r\n\r\n\r\n  /**\r\n   * Extend the Embed APIs `gapi.analytics.report.Data` component to\r\n   * return a promise the is fulfilled with the value returned by the API.\r\n   * @param {Object} params The request parameters.\r\n   * @return {Promise} A promise.\r\n   */\r\n  function query(params) {\r\n    return new Promise(function(resolve, reject) {\r\n      var data = new gapi.analytics.report.Data({query: params});\r\n      data.once('success', function(response) { resolve(response); })\r\n          .once('error', function(response) { reject(response); })\r\n          .execute();\r\n    });\r\n  }\r\n\r\n\r\n  /**\r\n   * Create a new canvas inside the specified element. Set it to be the width\r\n   * and height of its container.\r\n   * @param {string} id The id attribute of the element to host the canvas.\r\n   * @return {RenderingContext} The 2D canvas context.\r\n   */\r\n  function makeCanvas(id) {\r\n    var container = document.getElementById(id);\r\n    var canvas = document.createElement('canvas');\r\n    var ctx = canvas.getContext('2d');\r\n\r\n    container.innerHTML = '';\r\n    canvas.width = container.offsetWidth;\r\n    canvas.height = container.offsetHeight;\r\n    container.appendChild(canvas);\r\n\r\n    return ctx;\r\n  }\r\n\r\n\r\n  /**\r\n   * Create a visual legend inside the specified element based off of a\r\n   * Chart.js dataset.\r\n   * @param {string} id The id attribute of the element to host the legend.\r\n   * @param {Array.<Object>} items A list of labels and colors for the legend.\r\n   */\r\n  function generateLegend(id, items) {\r\n    var legend = document.getElementById(id);\r\n    legend.innerHTML = items.map(function(item) {\r\n      var color = item.color || item.fillColor;\r\n      var label = item.label;\r\n      return '<li><i style=\"background:' + color + '\"></i>' + label + '</li>';\r\n    }).join('');\r\n  }\r\n\r\n\r\n  // Set some global Chart.js defaults.\r\n  Chart.defaults.global.animationSteps = 60;\r\n  Chart.defaults.global.animationEasing = 'easeInOutQuart';\r\n  Chart.defaults.global.responsive = true;\r\n  Chart.defaults.global.maintainAspectRatio = false;\r\n\r\n});\r\n</script>\r\n</html>\r\n```"},"comment":{"url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/comments/88362999","html_url":"https://github.com/googleanalytics/ga-dev-tools/issues/51#issuecomment-88362999","issue_url":"https://api.github.com/repos/googleanalytics/ga-dev-tools/issues/51","id":88362999,"user":{"login":"kulander","id":11746036,"avatar_url":"https://avatars.githubusercontent.com/u/11746036?v=3","gravatar_id":"","url":"https://api.github.com/users/kulander","html_url":"https://github.com/kulander","followers_url":"https://api.github.com/users/kulander/followers","following_url":"https://api.github.com/users/kulander/following{/other_user}","gists_url":"https://api.github.com/users/kulander/gists{/gist_id}","starred_url":"https://api.github.com/users/kulander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kulander/subscriptions","organizations_url":"https://api.github.com/users/kulander/orgs","repos_url":"https://api.github.com/users/kulander/repos","events_url":"https://api.github.com/users/kulander/events{/privacy}","received_events_url":"https://api.github.com/users/kulander/received_events","type":"User","site_admin":false},"created_at":"2015-04-01T06:06:01Z","updated_at":"2015-04-01T06:06:01Z","body":"In terms of the color for the legends, I believe they don't show at all:\r\n```\r\n<li>\r\n<i style=\"background:rgba(220,220,220,0.5)\"></i>\r\nLast Week\r\n</li>\r\n```\r\nThe words \"Last week\" are correctly displayed, but not the label with the square color."}}