1010class FilamentFathom
1111{
1212 /**
13- *
1413 * @throws \Exception Missing Fathom API-Token and or Site id
1514 */
1615 public function __construct ()
@@ -45,9 +44,9 @@ public function activeVisitors(Filter $filter, bool $rawData = false): array | s
4544 ->currentVisitors (true );
4645 }
4746
48- return $ this ->getCachedValue ('current-visitors- ' . $ filter ->hash (), function () use ( $ filter ) {
47+ return $ this ->getCachedValue ('current-visitors- ' . $ filter ->hash (), function () {
4948 return Fathom::site (config ('filament-fathom-dashboard-widget.site_id ' ))
50- ->currentVisitors (false )[" total " ];
49+ ->currentVisitors (false )[' total ' ];
5150 });
5251 }
5352
@@ -63,8 +62,8 @@ public function sessionDuration(Filter $filter, bool $rawData = false): array |
6362 ->aggregate (['avg_duration ' ])
6463 ->groupByMonth ()
6564 ->orderBy ('timestamp ' , 'asc ' )
66- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
67- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
65+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
66+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
6867 ->timezone ($ filter ->getTz ())
6968 ->get ();
7069 }
@@ -74,24 +73,24 @@ public function sessionDuration(Filter $filter, bool $rawData = false): array |
7473 ->aggregate (['avg_duration ' ])
7574 ->groupByMonth ()
7675 ->orderBy ('timestamp ' , 'asc ' )
77- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
78- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
76+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
77+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
7978 ->timezone ($ filter ->getTz ())
8079 ->get ();
8180
82- if (isset ($ durationDays ["message " ]))
83- {
84- return "00:00 " ;
81+ if (isset ($ durationDays ['message ' ])) {
82+ return '00:00 ' ;
8583 }
8684
8785 $ avgTimeArray = array_map (function ($ item ) {
88- return (int )$ item ['avg_duration ' ];
86+ return (int ) $ item ['avg_duration ' ];
8987 }, $ durationDays );
9088 if (count ($ avgTimeArray ) == 2 ) {
9189 $ avgDuration = array_sum ($ avgTimeArray ) / 2 ;
9290 } else {
9391 $ avgDuration = array_sum ($ avgTimeArray );
9492 }
93+
9594 return CarbonInterval::seconds ($ avgDuration )->cascade ()->format ('%I:%S ' );
9695 });
9796 }
@@ -108,8 +107,8 @@ public function visitors(Filter $filter, bool $rawData = false): array | string
108107 ->aggregate (['visits ' ])
109108 ->groupByDay ()
110109 ->orderBy ('timestamp ' , 'asc ' )
111- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
112- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
110+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
111+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
113112 ->timezone ($ filter ->getTz ())
114113 ->get ();
115114 }
@@ -119,18 +118,17 @@ public function visitors(Filter $filter, bool $rawData = false): array | string
119118 ->aggregate (['visits ' ])
120119 ->groupByDay ()
121120 ->orderBy ('timestamp ' , 'asc ' )
122- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
123- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
121+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
122+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
124123 ->timezone ($ filter ->getTz ())
125124 ->get ();
126125
127- if (isset ($ stats ["message " ]))
128- {
129- return [0 ,[0 ]];
126+ if (isset ($ stats ['message ' ])) {
127+ return [0 , [0 ]];
130128 }
131129
132130 $ visitsArray = array_map (function ($ item ) {
133- return (int )$ item ['visits ' ];
131+ return (int ) $ item ['visits ' ];
134132 }, $ stats );
135133 $ totalVisits = array_sum ($ visitsArray );
136134
@@ -153,8 +151,8 @@ public function views(Filter $filter, bool $rawData = false): array | string
153151 ->aggregate (['pageviews ' ])
154152 ->groupByDay ()
155153 ->orderBy ('timestamp ' , 'asc ' )
156- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
157- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
154+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
155+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
158156 ->timezone ($ filter ->getTz ())
159157 ->get ();
160158 }
@@ -164,18 +162,17 @@ public function views(Filter $filter, bool $rawData = false): array | string
164162 ->aggregate (['pageviews ' ])
165163 ->groupByDay ()
166164 ->orderBy ('timestamp ' , 'asc ' )
167- ->fromDate ($ filter ->getFrom ()->format (" Y-m-d H:i:s " ))
168- ->toDate ($ filter ->getTo ()->format (" Y-m-d H:i:s " ))
165+ ->fromDate ($ filter ->getFrom ()->format (' Y-m-d H:i:s ' ))
166+ ->toDate ($ filter ->getTo ()->format (' Y-m-d H:i:s ' ))
169167 ->timezone ($ filter ->getTz ())
170168 ->get ();
171169
172- if (isset ($ stats ["message " ]))
173- {
174- return [0 ,[0 ]];
170+ if (isset ($ stats ['message ' ])) {
171+ return [0 , [0 ]];
175172 }
176173
177174 $ pageViewsArray = array_map (function ($ item ) {
178- return (int )$ item ['pageviews ' ];
175+ return (int ) $ item ['pageviews ' ];
179176 }, $ stats );
180177 $ totalPageViews = array_sum ($ pageViewsArray );
181178
@@ -185,5 +182,4 @@ public function views(Filter $filter, bool $rawData = false): array | string
185182 ];
186183 });
187184 }
188-
189185}
0 commit comments