/
index.blade.php
executable file
·672 lines (519 loc) · 15.6 KB
/
index.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
@extends('admin.master')
@section('content')
<style type="text/css">
.panel-options{
}
#view-selector-container table{
float:left;
width:260px !important;
}
#view-selector-container table td:nth-child(2){
width:200px !important;
}
#view-selector-container table td:first-child{
text-align:right;
width:90px !important;
padding-right:10px;
}
#view-selector-container table td .dcs-p-dcs-jd-dcs-y-dcs-g{
min-width:190px;
max-width:190px;
}
#view-selector-container table td .dcs-p-dcs-jd-dcs-y-dcs-g-dcs-ne{
max-width:165px;
}
.ViewSelector2-item select{
border: 1px solid #d4d2d0;
border-radius: 4px;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: inherit;
font-weight: 400;
height: 2.4285714285714284em;
line-height: 1.4285714285714286em;
padding: .42857142857142855em;
max-width:200px;
}
.ViewSelector2-item{
float:left;
}
.ViewSelector2-item label{
margin-left: 15px;
margin-right: 5px;
}
.ViewSelector .ViewSelector2-item:nth-child(3){
display:none;
}
#charts_env .panel-options{
padding-top:6px;
padding-right:6px;
}
.Chartjs-figure{
height:250px;
}
#chart-1-container, #chart-3-container, #chart-4-container, #active-users-container{
width:auto;
height:250px;
display:block;
position:relative;
}
.Chartjs-legend {
list-style: none;
margin: 0;
padding: 1em 0 0;
text-align: center;
}
.Chartjs-legend>li {
display: inline-block;
padding: .25em .5em;
}
.Chartjs-legend>li>i {
display: inline-block;
height: 1em;
margin-right: .5em;
vertical-align: -.1em;
width: 1em;
}
.chart1-panel{
height:315px;
}
/********** Active Users **********/
.ActiveUsers {
background: #f4f2f0;
border: 0px solid #d4d2d0;
border-radius: 0px;
font-weight: 300;
padding: .5em 1.5em;
white-space: nowrap;
height:315px;
text-align:center;
padding-top:75px;
}
.active-users-panel{
padding:0px;
height:315px;
}
.ActiveUsers-value{
font-size: 80px;
display: block;
text-align: center;
}
.ActiveUsers.is-increasing {
-webkit-animation: increase 3s;
animation: increase 3s;
}
.ActiveUsers.is-decreasing {
-webkit-animation: decrease 3s;
animation: decrease 3s;
}
@-webkit-keyframes increase {
10% {
background-color: #eaffea;
border-color: hsla(120, 100%, 25%, .5);
color: hsla(120, 100%, 25%, 1)
}
}
@keyframes increase {
10% {
background-color: #eaffea;
border-color: hsla(120, 100%, 25%, .5);
color: hsla(120, 100%, 25%, 1)
}
}
@-webkit-keyframes decrease {
10% {
background-color: #ffeaea;
border-color: hsla(0, 100%, 50%, .5);
color: red
}
}
@keyframes decrease {
10% {
background-color: #ffeaea;
border-color: hsla(0, 100%, 50%, .5);
color: red
}
}
#google_analytics_login_container{
position:relative;
z-index:2;
}
#google_analytics_login{
position: absolute;
width: 100%;
}
#google_analytics_login img{
width:100%;
}
.gapi-analytics-auth-styles-signinbutton-image{
width: 45px;
height: 50px;
float: left;
margin-left: 15px;
}
.gapi-analytics-auth-styles-signinbutton{
position: absolute;
top: 50%;
left: 50%;
margin-left: -200px;
width: 400px;
font-size: 30px;
text-align: center;
margin-top: -22px;
cursor:pointer;
}
</style>
<div class="row">
<div class="col-sm-3 col-xs-6">
<div class="tile-stats tile-red">
<div class="icon"><i class="entypo-users"></i></div>
<div class="num" data-start="0" data-end="{{ $total_subscribers }}" data-postfix="" data-duration="1500" data-delay="0">0</div>
<h3>Total Subscribers</h3>
<p>The total amount of subscribers on your site.</p>
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="tile-stats tile-green">
<div class="icon"><i class="entypo-user-add"></i></div>
<div class="num" data-start="0" data-end="{{ $new_subscribers }}" data-postfix="" data-duration="1500" data-delay="600">0</div>
<h3>New Subscribers</h3>
<p>New Subscribers for today.</p>
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="tile-stats tile-aqua">
<div class="icon"><i class="entypo-video"></i></div>
<div class="num" data-start="0" data-end="{{ $total_videos }}" data-postfix="" data-duration="1500" data-delay="1200">0</div>
<h3>Videos</h3>
<p>Total videos on your site.</p>
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="tile-stats tile-blue">
<div class="icon"><i class="entypo-doc-text"></i></div>
<div class="num" data-start="0" data-end="{{ $total_posts }}" data-postfix="" data-duration="1500" data-delay="1800">0</div>
<h3>Posts</h3>
<p>Total Posts/Articles on your site.</p>
</div>
</div>
</div>
<br />
<div id="google_analytics_login_container">
<div id="google_analytics_login">
<img src="{{ URL::to('/') }}/application/assets/admin/images/admin-bg.jpg" />
<div id="embed-api-auth-container"></div>
</div>
</div>
<script>
(function(w,d,s,g,js,fs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
</script>
<script src="{{ URL::to('/') }}/application/assets/admin/js/ganalytics/Chart.min.js"></script>
<script src="{{ URL::to('/') }}/application/assets/admin/js/ganalytics/moment.min.js"></script>
<script src="{{ URL::to('/') }}/application/assets/admin/js/ganalytics/active-users.js"></script>
<script src="{{ URL::to('/') }}/application/assets/admin/js/ganalytics/view-selector2.js"></script>
<div class="row">
<div class="col-sm-8">
<div class="panel panel-primary" id="charts_env">
<div class="panel-heading">
<div class="panel-title">This Week vs. Last Week</div>
<div class="panel-options">
<div class="ViewSelector" id="view-selector-container"></div>
</div>
</div>
<div class="panel-body chart1-panel">
<div class="tab-content">
<div id="chart-1-container"></div>
<div class="Chartjs-legend" id="legend-1-container"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="panel panel-primary" id="charts_env">
<div class="panel-heading">
<div class="panel-title">Real-time Visitors</div>
</div>
<div class="panel-body active-users-panel">
<div class="tab-content">
<div id="active-users-container"></div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="panel panel-primary" id="charts_env">
<div class="panel-heading">
<div class="panel-title">Top Browsers by Pageviews</div>
</div>
<div class="panel-body">
<div class="tab-content">
<div id="chart-3-container"></div>
<div class="Chartjs-legend" id="legend-3-container"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-primary" id="charts_env">
<div class="panel-heading">
<div class="panel-title">Top Countries by Sessions</div>
</div>
<div class="panel-body">
<div class="tab-content">
<div id="chart-4-container"></div>
<div class="Chartjs-legend" id="legend-4-container"></div>
</div>
</div>
</div>
</div>
</div>
<script>
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".
*/
gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: '{{ $settings->google_oauth_key }}',
});
/**
* Create a new ActiveUsers instance to be rendered inside of an
* element with the id "active-users-container" and poll for changes every
* five seconds.
*/
var activeUsers = new gapi.analytics.ext.ActiveUsers({
container: 'active-users-container',
pollingInterval: 5
});
/**
* Add CSS animation to visually show the when users come and go.
*/
activeUsers.once('success', function() {
var element = this.container.firstChild;
var timeout;
this.on('change', function(data) {
var element = this.container.firstChild;
var animationClass = data.delta > 0 ? 'is-increasing' : 'is-decreasing';
element.className += (' ' + animationClass);
clearTimeout(timeout);
timeout = setTimeout(function() {
element.className =
element.className.replace(/ is-(increasing|decreasing)/g, '');
}, 3000);
});
});
/**
* 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.
//viewSelector.execute();
/**
* 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': 'today'
},
chart: {
container: 'chart-container',
type: 'LINE',
options: {
width: '100%'
}
}
});
function renderTopBrowsersChart(ids) {
query({
'ids': ids,
'dimensions': 'ga:browser',
'metrics': 'ga:pageviews',
'sort': '-ga:pageviews',
'max-results': 5
})
.then(function(response) {
//console.log(response.rows);
var data = [];
var colors = ['#4D5360','#949FB1','#D4CCC5','#E2EAE9','#F7464A'];
response.rows.forEach(function(row, i) {
data.push({ value: +row[1], color: colors[i], label: row[0] });
});
new Chart(makeCanvas('chart-3-container')).Doughnut(data);
generateLegend('legend-3-container', data);
});
}
/**
* Extend the Embed APIs `gapi.analytics.report.Data` component to
* return a promise the is fulfilled with the value returned by the API.
* @param {Object} params The request parameters.
* @return {Promise} A promise.
*/
function query(params) {
return new Promise(function(resolve, reject) {
var data = new gapi.analytics.report.Data({query: params});
data.once('success', function(response) { resolve(response); })
.once('error', function(response) { reject(response); })
.execute();
});
}
/**
* Create a new canvas inside the specified element. Set it to be the width
* and height of its container.
* @param {string} id The id attribute of the element to host the canvas.
* @return {RenderingContext} The 2D canvas context.
*/
function makeCanvas(id) {
var container = document.getElementById(id);
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
container.innerHTML = '';
canvas.width = container.offsetWidth;
canvas.height = container.offsetHeight;
container.appendChild(canvas);
return ctx;
}
/**
* Draw the a chart.js line chart with data from the specified view that
* overlays session data for the current week over session data for the
* previous week.
*/
function renderWeekOverWeekChart(ids) {
// Adjust `now` to experiment with different days, for testing only...
var now = moment(); // .subtract(3, 'day');
var thisWeek = query({
'ids': ids,
'dimensions': 'ga:date,ga:nthDay',
'metrics': 'ga:sessions',
'start-date': moment(now).subtract(1, 'day').day(0).format('YYYY-MM-DD'),
'end-date': moment(now).format('YYYY-MM-DD')
});
var lastWeek = query({
'ids': ids,
'dimensions': 'ga:date,ga:nthDay',
'metrics': 'ga:sessions',
'start-date': moment(now).subtract(1, 'day').day(0).subtract(1, 'week')
.format('YYYY-MM-DD'),
'end-date': moment(now).subtract(1, 'day').day(6).subtract(1, 'week')
.format('YYYY-MM-DD')
});
Promise.all([thisWeek, lastWeek]).then(function(results) {
var data1 = results[0].rows.map(function(row) { return +row[2]; });
var data2 = results[1].rows.map(function(row) { return +row[2]; });
var labels = results[1].rows.map(function(row) { return +row[0]; });
labels = labels.map(function(label) {
return moment(label, 'YYYYMMDD').format('ddd');
});
var data = {
labels : labels,
datasets : [
{
label: 'Last Week',
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : data2
},
{
label: 'This Week',
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : data1
}
]
};
new Chart(makeCanvas('chart-1-container')).Line(data);
generateLegend('legend-1-container', data.datasets);
});
}
/**
* Draw the a chart.js doughnut chart with data from the specified view that
* compares sessions from mobile, desktop, and tablet over the past seven
* days.
*/
function renderTopCountriesChart(ids) {
query({
'ids': ids,
'dimensions': 'ga:country',
'metrics': 'ga:sessions',
'sort': '-ga:sessions',
'max-results': 5
})
.then(function(response) {
var data = [];
var colors = ['#4D5360','#949FB1','#D4CCC5','#E2EAE9','#F7464A'];
response.rows.forEach(function(row, i) {
data.push({
label: row[0],
value: +row[1],
color: colors[i]
});
});
new Chart(makeCanvas('chart-4-container')).Doughnut(data);
generateLegend('legend-4-container', data);
});
}
/**
* Create a visual legend inside the specified element based off of a
* Chart.js dataset.
* @param {string} id The id attribute of the element to host the legend.
* @param {Array.<Object>} items A list of labels and colors for the legend.
*/
function generateLegend(id, items) {
var legend = document.getElementById(id);
legend.innerHTML = items.map(function(item) {
var color = item.color || item.fillColor;
var label = item.label;
return '<li><i style="background:' + color + '"></i>' + label + '</li>';
}).join('');
}
// Set some global Chart.js defaults.
Chart.defaults.global.animationSteps = 60;
Chart.defaults.global.animationEasing = 'easeInOutQuart';
Chart.defaults.global.responsive = true;
Chart.defaults.global.maintainAspectRatio = false;
/**
* Create a new ViewSelector2 instance to be rendered inside of an
* element with the id "view-selector-container".
*/
var viewSelector = new gapi.analytics.ext.ViewSelector2({
container: 'view-selector-container',
})
.execute();
/**
* Update the activeUsers component, the Chartjs charts, and the dashboard
* title whenever the user changes the view.
*/
viewSelector.on('viewChange', function(data) {
//var title = document.getElementById('view-name');
//title.innerHTML = data.property.name + ' (' + data.view.name + ')';
// Start tracking active users for this view.
activeUsers.set(data).execute();
// Render all the of charts for this view.
renderWeekOverWeekChart(data.ids);
renderTopBrowsersChart(data.ids);
renderTopCountriesChart(data.ids);
$('#google_analytics_login_container').fadeOut();
});
});
</script>
@stop