-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoverview.php
958 lines (719 loc) · 23.2 KB
/
overview.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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Overview Summary</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>
<?php
use TANIOS\Airtable\Airtable;
// displays all errors
//ini_set('display_errors', 1);
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
// Adobe Analytics
$time = microtime(true);
$succ = 0;
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
require_once('./php/getToken.php');
$succ = 1;
}
else if (time() - $_SESSION['CREATED'] > 86400) {
session_regenerate_id(true);
$_SESSION['CREATED'] = time();
require_once('./php/getToken.php');
$succ = 1;
}
if ( isset($_SESSION["token"]) ) {
$succ = 1;
}
if ( $succ === 1 ) {
require_once('./php/api_post.php');
$config = include('./php/config-aa.php');
$data = include ('./php/data-aa.php');
// Get Date for AA
$iso = 'Y-m-d\TH:i:s.v';
$previousWeekStart = strtotime("last sunday midnight", strtotime("-2 week +1 day") );
$previousWeekEnd = strtotime("next sunday", $previousWeekStart);
$previousWeekStart = date( $iso , $previousWeekStart);
$previousWeekEnd = date( $iso , $previousWeekEnd);
$weekStart = strtotime("last sunday midnight", strtotime("-1 week +1 day") );
$weekEnd = strtotime("next sunday", $weekStart);
$weekStart = date( $iso , $weekStart);
$weekEnd = date( $iso , $weekEnd);
$monthStart = ( new DateTime("first day of last month midnight") )->format($iso);
$monthEnd = ( new DateTime("first day of this month midnight") )->format($iso);
$previousMonthStart = ( new DateTime("first day of -2 month midnight") )->format($iso);
$previousMonthEnd = $monthStart;
// Get date for GSC
$iso = 'Y-m-d';
$startLastGSC = ( new DateTime ( $previousWeekStart ) )->format( $iso );
$endLastGSC = ( new DateTime ( $previousWeekEnd ) )->modify( '-1 days' )->format( $iso );
$startGSC = ( new DateTime ( $weekStart ) )->format( $iso );
$endGSC = ( new DateTime ( $weekEnd ) )->modify( '-1 days' )->format( $iso );
$dates = [ [ $startLastGSC, $endLastGSC ], [ $startGSC, $endGSC ] ];
?>
<h1>Overview - Summary</h1>
<p><strong>Date range:</strong> <?=$dates[1][0]?> to <?=$dates[1][1]?></p>
<p><strong>Compared to:</strong> <?=$dates[0][0]?> to <?=$dates[0][1]?></p>
</div>
</div>
</div>
<?php
$urls = "";
if (substr($url, 0, 8) == "https://") {
$urls = substr($url, 8, strlen($url));
} else {
$urls = $url;
}
$r = new ApiClient($config[0]['ADOBE_API_KEY'], $config[0]['COMPANY_ID'], $_SESSION['token']);
$temp = [ 'aa-ovrvw-smmry-metrics', 'aa-ovrvw-smmry-fwylf', 'aa-ovrvw-smmry-trnd', 'aa-ovrvw-smmry-tsks' ]; //, 'fwylf' ];
$result = array();
$j = array();
foreach ( $temp as $t ) {
$json = $data[$t];
$json = sprintf($json, $urls);
$json = str_replace(
array( "*previousMonthStart*", "*previousMonthEnd*", "*monthStart*", "*monthEnd*", "*previousWeekStart*", "*previousWeekEnd*", "*weekStart*", "*weekEnd*" ),
array( $previousMonthStart, $previousMonthEnd, $monthStart, $monthEnd, $previousWeekStart, $previousWeekEnd, $weekStart, $weekEnd ),
$json );
//$result = api_post($config[0]['ADOBE_API_KEY'], $config[0]['COMPANY_ID'], $_SESSION['token'], $api);
$result[] = $r->requestEntity( $json );
$j[] = $json;
}
//echo var_dump($result[0]);
foreach ( $result as $r ) {
}
$res = json_decode( $result[0], true );
$metrics = $res["summaryData"]["filteredTotals"];
$res2 = json_decode( $result[1], true );
$metrics2 = $res2["summaryData"]["filteredTotals"];
$aaResultTrend = json_decode( $result[2], true );
$aaMetricsTrend = $aaResultTrend["rows"];
$aaTrendWeeks = array_slice($aaMetricsTrend, -14);
$aaTrendLastWeek = array_slice($aaTrendWeeks, 0, 7);
$aaTrendWeek = array_slice($aaTrendWeeks, -7);
$aaTasks = json_decode( $result[3], true );
$aaTasksStats = $aaTasks["rows"];
$taskArray = array();
foreach ( $aaTasksStats as $task ) {
$taskArray[] = $task['value'];
}
$fwylfYes = 0;
$fwylfNo = 4;
$pv = 8;
$visitors = 12;
$visits = 16;
function differ ( $old, $new ) {
return (($new - $old) / $old); //(1 - $old / $new) * 100; // ( ( $new - $orig ) / $orig ) * 100;
}
function posOrNeg ( $num ) {
if ( $num > 0 ) return 'fa-arrow-up:green';
else return 'fa-arrow-down:red';
}
function percent( $num ){
return round ( $num * 100, 0 ) . '%';
}
$diff = differ ( $metrics[ $visitors + 2 ], $metrics[ $visitors + 3 ] );
$pos = posOrNeg($diff);
$pieces = explode(":", $pos);
$diff = abs($diff);
$fwylfICantFindTheInfo = 0;
$fwylfOtherReason = 4;
$fwylfInfoHardToUnderstand = 8;
$fwylfError = 12;
?>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Unique Visitors</h5>
<p class="card-text"><?=number_format($metrics[ $visitors + 3 ])?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
<?php
$diff = differ ( $metrics[ $visits + 2 ], $metrics[ $visits + 3 ] );
$pos = posOrNeg($diff);
$pieces = explode(":", $pos);
$diff = abs($diff);
?>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Visits to all CRA pages</h5>
<p class="card-text"><?=number_format($metrics[ $visits + 3 ])?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
<?php
$diff = differ ( $metrics[ $pv + 2 ], $metrics[ $pv + 3 ] );
$pos = posOrNeg($diff);
$pieces = explode(":", $pos);
$diff = abs($diff);
?>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Page Views</h5>
<p class="card-text"><?=number_format($metrics[ $pv + 3 ])?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="table-responsive">
<table class="table">
<caption>Last Week</caption>
<thead>
<th>Date</th>
<th>Value</th>
</thead>
<tbody>
<?php
foreach ( $aaTrendLastWeek as $trend ) {
?>
<tr>
<td><?=$trend['value']?></td>
<td><?=number_format($trend['data'][1])?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="col-sm-6">
<div class="table-responsive">
<table class="table">
<caption>Week</caption>
<thead>
<th>Date</th>
<th>Value</th>
</thead>
<tbody>
<?php
foreach ( $aaTrendWeek as $trend ) {
?>
<tr>
<td><?=$trend['value']?></td>
<td><?=number_format($trend['data'][1])?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
// GSC
require 'vendor/autoload.php';
$data = include ('./php/data-gsc.php');
$type = [ 'ovrvw-smmry-totals', 'ovrvw-smmry-qryAll' ];
$results = 5;
$gscArr = array();
$gscResp = array();
$start2 = microtime(true);
foreach ( $type as $t ) {
foreach ($dates as $d) {
$analytics = initializeAnalytics();
$response = getReport( $d[0], $d[1], $results, $url, $t );
$u = printResults($analytics, $response, $t);
$u = json_decode( $u, true );
$gscArr[] = $u;
$gscResp[] = $response;
}
}
$time_elapsed_secs = microtime(true) - $start2;
//totals
$gscTotals = $gscArr[0];
$lastClicks = $gscTotals['rows'][0]['clicks'];
$lastCtr = $gscTotals['rows'][0]['ctr'];
$lastImp = $gscTotals['rows'][0]['impressions'];
$lastPos = $gscTotals['rows'][0]['position'];
$gscTotals = $gscArr[1];
$clicks = $gscTotals['rows'][0]['clicks'];
$ctr = $gscTotals['rows'][0]['ctr'];
$imp = $gscTotals['rows'][0]['impressions'];
$pos = $gscTotals['rows'][0]['position'];
$diff = differ ( $lastImp, $imp );
$posi = posOrNeg($diff);
$pieces = explode(":", $posi);
$diff = abs($diff);
?>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Total impressions from Google</h5>
<p class="card-text"><?=number_format($imp)?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
<?php
$diff = differ ( $lastCtr, $ctr );
$posi = posOrNeg($diff);
$pieces = explode(":", $posi);
$diff = abs($diff);
?>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Click through rate from Google</h5>
<p class="card-text"><?=percent($ctr)?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
<?php
$diff = differ ( $lastPos, $pos );
$posi = posOrNeg($diff);
$pieces = explode(":", $posi);
$diff = abs($diff);
?>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Average rank on Google</h5>
<p class="card-text"><?=number_format($pos)?></p>
<p><i class="fas <?=$pieces[0]?>" style="color: <?=$pieces[1]?>;"></i> <?=percent($diff)?> compared to previous 7 days</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
//query
$lastClicks = $gscArr[2]['rows'][0]['clicks'];
$clicks = $gscArr[3]['rows'][0]['clicks'];
$ctr = $gscArr[3]['rows'][0]['ctr'];
$imp = $gscArr[3]['rows'][0]['impressions'];
$pos = $gscArr[3]['rows'][0]['position'];
$term = $gscArr[3]['rows'][0]['keys'][0];
$diff = differ ( $lastImp, $imp );
$posi = posOrNeg($diff);
$pieces = explode(":", $posi);
$diff = abs($diff);
/*
function implode_recursive(string $separator, array $array): string
{
$string = '';
foreach ($array as $i => $a) {
if (is_array($a)) {
$string .= implode_recursive($separator, $a);
} else {
$string .= $a;
if ($i < count($array) - 1) {
$string .= $separator;
}
}
}
return $string;
}
*/
function implode_recursive($g, $p) {
return is_array($p) ?
implode($g, array_map(__FUNCTION__, array_fill(0, count($p), $g), $p)) :
$p;
}
echo "<h3>Top 5 search terms from Google</h3>";
$qry = $gscArr[3]['rows'];
if (count($qry) > 0): ?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($qry))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($qry as $row): array_map('htmlentities', null, $row); ?>
<tr>
<td><?=implode_recursive('</td><td>', $row);?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif;
?>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h3>Top 10 tasks</h3>
<?php
$qry = $aaTasksStats;
//var_dump($qry);
if (count($qry) > 0): ?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Task</th>
<th>Task Success Survey Completed</th>
</tr>
</thead>
<tbody>
<?php foreach ($qry as $row): array_map('htmlentities', null, $row); ?>
<tr>
<td><?=$row['value'];?></td>
<td><?=$row['data'][3]?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif;
?>
</div>
</div>
</div>
<?php
$config = include('./php/config-at.php');
$start2 = microtime(true);
$airtable = new Airtable( $config );
//var_dump($taskArray);
// Tasks in AirTable
$params = array( "filterByFormula" => 'SEARCH(Task, "'.implode($taskArray, ',').'") != ""');
//print_r($params);
$table = 'Top Task Survey (PP)';
$request = getContentRecursive( $airtable, $table, $params );
$lo = [ 'fields', [ 'Task', 'Tasks' ] ];
$con = parseJSON2( $request, $lo );
//echo "<br /><br /> Connection Main: ";
//var_dump ( $con );
// Enquiry Lines in AirTable
$params = array( ); // array( "filterByFormula" => 'SEARCH(Task, "'.implode($taskArray, ',').'") != ""');
//print_r($params);
$table = 'Weekly Calls (2021)';
$fullArray = [];
$request = $airtable->getContent( $table, $params);
do {
$response = $request->getResponse();
$fullArray = array_merge($fullArray , ( $response->records ) );
}
while( $request = $response->next() );
//var_dump($fullArray);
$m = [ 'fields', 'Equiry Line' ];
$l = [ 'fields', 'Total Calls' ];
$con1 = parseJSON( $fullArray, $l );
//var_dump($con1);
$con2 = parseJSON( $fullArray, $m );
//var_dump($con2);
$arrFinal = array();
for ($i = 0; $i < count($con1) - 1; $i++) {
if(isset( $arrFinal[ ( $con2[$i] ) ] ))
$arrFinal[ ( $con2[$i] ) ] += $con1[$i];
else
$arrFinal += array($con2[$i] => $con1[$i]);
}
//var_dump($arrFinal);
if (count($arrFinal) > 0): ?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h3>Total calls by inquiry line</h3>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Inquiry Line</th>
<th>Number of calls</th>
</tr>
</thead>
<tbody>
<?php foreach ($arrFinal as $key => $value) {
if ( $key !== '' ) {
?>
<tr>
<td><?=$key;?></td>
<td><?=number_format($value);?></td>
</tr>
<?php }
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php endif;
$params = array( ); // array( "filterByFormula" => 'SEARCH(Task, "'.implode($taskArray, ',').'") != ""');
//print_r($params);
$table = 'User Testing';
$fullArray = [];
$request = $airtable->getContent( $table, $params);
do {
$response = $request->getResponse();
$fullArray = array_merge($fullArray , ( $response->records ) );
}
while( $request = $response->next() );
//var_dump($fullArray);
$m = [ 'fields', '# of Users' ];
$l = [ 'fields', 'Success Rate' ];
$con1 = parseJSON( $fullArray, $m );
$con2 = parseJSON( $fullArray, $l );
$totalTasks = number_format( count($fullArray) );
$avgSuccessRate = percent( array_sum( $con2 ) / $totalTasks );
$sumNumUsers = number_format( array_sum( $con1 ) );
//echo 'total tasks: ' . $totalTasks . "<br /><br />avg success rate: " . $avgSuccessUsers . '<br />br />sum of users: ' . $sumNumUsers;
?>
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="table-responsive">
<table class="table">
<thead>
<th>Metrics</th>
<th>Previous Month</th>
<th>Month</th>
<th>Previous Week</th>
<th>Week</th>
</thead>
<tbody>
<tr>
<td>FWYLF - Yes</td>
<td><?=number_format($metrics[ $fwylfYes + 0 ])?></td>
<td><?=number_format($metrics[ $fwylfYes + 1 ])?></td>
<td><?=number_format($metrics[ $fwylfYes + 2 ])?></td>
<td><?=number_format($metrics[ $fwylfYes + 3 ])?></td>
</tr>
<tr>
<td>FWYLF - No</td>
<td><?=number_format($metrics[ $fwylfNo + 0 ])?></td>
<td><?=number_format($metrics[ $fwylfNo + 1 ])?></td>
<td><?=number_format($metrics[ $fwylfNo + 2 ])?></td>
<td><?=number_format($metrics[ $fwylfNo + 3 ])?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-sm-6">
<div class="table-responsive">
<table class="table">
<thead>
<th>Metrics</th>
<th>Previous Month</th>
<th>Month</th>
<th>Previous Week</th>
<th>Week</th>
</thead>
<tbody>
<tr>
<td>FWYLF - I can't find the information</td>
<td><?=number_format($metrics2[ $fwylfICantFindTheInfo + 0 ])?></td>
<td><?=number_format($metrics2[ $fwylfICantFindTheInfo + 1 ])?></td>
<td><?=number_format($metrics2[ $fwylfICantFindTheInfo + 2 ])?></td>
<td><?=number_format($metrics2[ $fwylfICantFindTheInfo + 3 ])?></td>
</tr>
<tr>
<td>FWYLF - Other reason</td>
<td><?=number_format($metrics2[ $fwylfOtherReason + 0 ])?></td>
<td><?=number_format($metrics2[ $fwylfOtherReason + 1 ])?></td>
<td><?=number_format($metrics2[ $fwylfOtherReason + 2 ])?></td>
<td><?=number_format($metrics2[ $fwylfOtherReason + 3 ])?></td>
</tr>
<tr>
<td>FWYLF - Information hard to understand</td>
<td><?=number_format($metrics2[ $fwylfInfoHardToUnderstand + 0 ])?></td>
<td><?=number_format($metrics2[ $fwylfInfoHardToUnderstand + 1 ])?></td>
<td><?=number_format($metrics2[ $fwylfInfoHardToUnderstand + 2 ])?></td>
<td><?=number_format($metrics2[ $fwylfInfoHardToUnderstand + 3 ])?></td>
</tr>
<tr>
<td>FWYLF - Error/something didn't work</td>
<td><?=number_format($metrics2[ $fwylfError + 0 ])?></td>
<td><?=number_format($metrics2[ $fwylfError + 1 ])?></td>
<td><?=number_format($metrics2[ $fwylfError + 2 ])?></td>
<td><?=number_format($metrics2[ $fwylfError + 3 ])?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Total tasks</h5>
<p class="card-text"><?=$totalTasks;?></p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Total users</h5>
<p class="card-text"><?=$sumNumUsers;?></p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Average success rate</h5>
<p class="card-text"><?=$avgSuccessRate;?></p>
</div>
</div>
</div>
</div>
</div>
<?php
//for if at line 55 : if ( $succ === 1 ) {
} else {
echo "<p>No data</p>";
}
?>
</div>
<?php
/**
* Initializes an Analytics Reporting API V4 service object.
*
* @return An authorized Analytics Reporting API V4 service object.
*/
function initializeAnalytics()
{
// Use the developers console and download your service account
// credentials in JSON format. Place them in this directory or
// change the key file location if necessary.
$KEY_FILE_LOCATION = __DIR__ . '/php/service-account-credentials.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/webmasters.readonly']);
return $client;
}
/**
* Queries the Analytics Reporting API V4.
*
* @param service An authorized Analytics Reporting API V4 service object.
* @return The Analytics Reporting API V4 response.
*/
function getReport( $start, $end, $results, $url, $t ) {
global $data;
$json = $data[$t];
if ( $t == "ovrvw-smmry-totals" || $t == "ovrvw-smmry-qryAll" ) {
$json = sprintf($json, $start, $end, $results);
} else {
$json = sprintf($json, $start, $end, $url, $results);
}
$array = json_decode( $json, true);
return new Google_Service_Webmasters_SearchAnalyticsQueryRequest( $array );
}
/**
* Parses and prints the Analytics Reporting API V4 response.
*
* @param An Analytics Reporting API V4 response.
*/
function printResults($client, $q, $t) {
try {
$service = new Google_Service_Webmasters($client);
$u = $service->searchanalytics->query('https://www.canada.ca/', $q);
return json_encode($u);
} catch(\Exception $e ) {
echo $e->getMessage();
}
}
?>
<?php
// Recursive version of Airtable PHP client's getContent() method
// Including some built-in friendly debugging
function getContentRecursive($db_inventory, $table_name, $filters = []) {
// Fetch the first response
$response = $db_inventory->getContent($table_name, $filters)->getResponse();
// If there's an error, show it and return an empty array.
if ($response->error) {
var_dump($response->error->type.': '.$response->error->message);
return [];
}
$content = $response->records;
return $content;
}
function parseJSON ( $content, $array ) {
$cnt = count($array);
$records = [];
//echo '<BR /><br />CONTENT: <br /><br />';
//var_dump( $content );
foreach ($content as $key => $val) {
//var_dump("VALUE: " . $val);
if ( $cnt == 1 ) {
$a = $val->{$array[0]};
} else if ( $cnt == 2 ) {
$a = $val->{$array[0]}->{$array[1]};
} else if ( $cnt == 3 ) {
$a = $val->{$array[0]}->{$array[1]}->{$array[2]};
}
if ( is_array($a) ) {
$a = implode($a, '');
}
array_push($records, $a);
}
return $records;
}
function parseJSON2 ( $content, $array ) {
$cnt = count($array);
$records = [];
//echo '<BR /><br />CONTENT: <br /><br />';
//var_dump( $content );
if ( is_array( $array[1] ) ) {
foreach ($content as $key => $val) {
$temp = [];
foreach ( $array[1] as $arr ) {
$a = $val->{$array[0]}->{$arr};
$temp[$arr] = $a;
}
$records[] = $temp;
}
} /* else {
//var_dump("VALUE: " . $val);
if ( $cnt == 1 ) {
$a = $val->{$array[0]};
} else if ( $cnt == 2 ) {
$a = $val->{$array[0]}->{$array[1]};
} else if ( $cnt == 3 ) {
$a = $val->{$array[0]}->{$array[1]}->{$array[2]};
}
if ( is_array($a) ) {
$a = implode($a, '');
}
array_push($records, $a);
}
}
*/
return $records;
}
?>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>