Passed
Push — main ( 106d28...df360d )
by PRATIK
13:25
created

topReferrersColumnChart()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Adminetic\Website\Http\Controllers;
4
5
use Adminetic\Website\Services\PostStatistic;
6
use Analytics;
0 ignored issues
show
Bug introduced by
The type Analytics was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Spatie\Analytics\Period;
8
use App\Http\Controllers\Controller;
9
10
class WebsiteAnalyticsController extends Controller
11
{
12
    public function viewByCountryColumnChart()
13
    {
14
        $analytics = Analytics::performQuery(
15
            Period::days(request()->has('days') ? (int) request()->days : 7),
16
            'ga:pageviews',
17
            [
18
                'metrics' => 'ga:sessions,ga:pageviews',
19
                'dimensions' => 'ga:country',
20
                'sort' => '-ga:pageviews'
21
            ]
22
        )->rows;
23
        return response()->json([
24
            'analytics' => $analytics
25
        ], 200);
26
    }
27
28
    public function viewByDaysColumnChart()
29
    {
30
        $analytics = Analytics::fetchTotalVisitorsAndPageViews(Period::days(request()->has('days') ? (int) request()->days : 7));
31
        return response()->json([
32
            'analytics' => $analytics
33
        ], 200);
34
    }
35
36
    public function topReferrersColumnChart()
37
    {
38
        $analytics = Analytics::fetchTopReferrers(Period::days(request()->has('days') ? (int) request()->days : 7), 5);
39
        return response()->json([
40
            'analytics' => $analytics
41
        ], 200);
42
    }
43
44
    public function newVsReturningVistorPieChart()
45
    {
46
        $analytics = Analytics::performQuery(
47
            Period::days(request()->has('days') ? (int) request()->days : 7),
48
            'ga:sessions',
49
            [
50
                'dimensions' => 'ga:userType',
51
                'metrics' => 'ga:sessions'
52
            ]
53
        )->rows;
54
        return response()->json([
55
            'analytics' => $analytics
56
        ], 200);
57
    }
58
59
    public function topBrowsersPieChart()
60
    {
61
        $analytics = Analytics::fetchTopBrowsers(Period::days(request()->has('days') ? (int) request()->days : 7), 5);
62
63
        return response()->json([
64
            'analytics' => $analytics
65
        ], 200);
66
    }
67
68
    public function mostVisitedPagesBarChart()
69
    {
70
        $analytics = Analytics::fetchMostVisitedPages(Period::days(request()->has('days') ? (int) request()->days : 7), 5);
71
72
        return response()->json([
73
            'analytics' => $analytics
74
        ], 200);
75
    }
76
77
    public function getMonthlyPostTotalView()
78
    {
79
        return response()->json(['monthly_counts' => PostStatistic::perMonthAllTotalTenentPostCount()], 200);
80
    }
81
}
82