Commit da7f3c1fe0605dd634b46a78e4e43ff345c1b826

Authored by Alex Savenko
1 parent 75f5a052

ga

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