Commit a194dccd03e0030449ce2c99493c1e5d70106734

Authored by Alex Savenko
1 parent d1d49507

ga

Showing 1 changed file with 75 additions and 3 deletions   Show diff stats
backend/views/report/index.php
... ... @@ -16,9 +16,81 @@ $this->title = Yii::t('app', 'Report');
16 16 $this->params['breadcrumbs'][] = $this->title;
17 17 ?>
18 18  
19   -<div>
20   - <h1><?= Html::encode($this->title) ?></h1>
21   -</div>
  19 + <div>
  20 + <h1><?= Html::encode($this->title) ?></h1>
  21 + </div>
  22 +
  23 + <div id="embed-api-auth-container"></div>
  24 + <div id="chart-container"></div>
  25 + <div id="view-selector-container"></div>
  26 +
  27 + <script>
  28 + (function(w,d,s,g,js,fs){
  29 + g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
  30 + js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
  31 + js.src='https://apis.google.com/js/platform.js';
  32 + fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
  33 + }(window,document,'script'));
  34 + </script>
  35 +
  36 + <script>
  37 +
  38 + gapi.analytics.ready(function() {
  39 +
  40 + /**
  41 + * Authorize the user immediately if the user has already granted access.
  42 + * If no access has been created, render an authorize button inside the
  43 + * element with the ID "embed-api-auth-container".
  44 + */
  45 + gapi.analytics.auth.authorize({
  46 + container: 'embed-api-auth-container',
  47 + clientid: '119240817'
  48 + });
  49 +
  50 +
  51 + /**
  52 + * Create a new ViewSelector instance to be rendered inside of an
  53 + * element with the id "view-selector-container".
  54 + */
  55 + var viewSelector = new gapi.analytics.ViewSelector({
  56 + container: 'view-selector-container'
  57 + });
  58 +
  59 + // Render the view selector to the page.
  60 + viewSelector.execute();
  61 +
  62 +
  63 + /**
  64 + * Create a new DataChart instance with the given query parameters
  65 + * and Google chart options. It will be rendered inside an element
  66 + * with the id "chart-container".
  67 + */
  68 + var dataChart = new gapi.analytics.googleCharts.DataChart({
  69 + query: {
  70 + metrics: 'ga:sessions',
  71 + dimensions: 'ga:date',
  72 + 'start-date': '30daysAgo',
  73 + 'end-date': 'yesterday'
  74 + },
  75 + chart: {
  76 + container: 'chart-container',
  77 + type: 'LINE',
  78 + options: {
  79 + width: '100%'
  80 + }
  81 + }
  82 + });
  83 +
  84 +
  85 + /**
  86 + * Render the dataChart on the page whenever a new view is selected.
  87 + */
  88 + viewSelector.on('change', function(ids) {
  89 + dataChart.set({query: {ids: ids}}).execute();
  90 + });
  91 +
  92 + });
  93 + </script>
22 94  
23 95 <?php
24 96  
... ...