PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.12
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.12
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Admin / Analytics / Metrics.php

Metrics.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.0.12, at Inc/Core/Admin/Analytics/Metrics.php

181 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.0.12 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2023 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Admin\Analytics;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Registry;
20
21 class Metrics
22 {
23 /**
24 * Default active metrics
25 *
26 * @var array
27 */
28 const default_active_metrics = [
29 'impressions'
30 ];
31
32 /**
33 * Default Metrics.
34 *
35 * @var array
36 */
37 private $metrics_map = [
38 'impressions' => [
39 'class' => 'Impressions',
40 ],
41 'averagetimeopen' => [
42 'class' => 'AverageTimeOpen'
43 ],
44 'submissions' => [
45 'class' => 'Submissions'
46 ],
47 'conversionrate' => [
48 'class' => 'ConversionRate'
49 ]
50 ];
51
52 /**
53 * Metrics.
54 *
55 * @var array
56 */
57 private $metrics = [];
58
59 private $toolbar;
60
61 public function __construct($toolbar = null)
62 {
63 $this->toolbar = $toolbar;
64 }
65
66 /**
67 * Render metrics.
68 *
69 * @return void
70 */
71 public function render()
72 {
73 firebox()->renderer->admin->render('analytics/metrics/tmpl');
74 }
75
76 /**
77 * Gets all metric data with chart-related data
78 *
79 * @return array
80 */
81 public function getMetrics()
82 {
83 if (count($this->metrics))
84 {
85 return $this->metrics;
86 }
87
88 $this->initializeMetrics();
89
90 return $this->metrics;
91 }
92
93 public function getMetricsData($update = true)
94 {
95 $data = [];
96
97 $metrics = $this->getMetrics();
98
99 foreach ($metrics as $key => $metric)
100 {
101 // Metrics that require other metrics to generate data
102 if ($metric->getDataSource() === 'metrics')
103 {
104 $found_metrics = array_intersect_key($metrics, array_flip($metric->getDataSourceInput()));
105
106 if ($found_metrics)
107 {
108 // Skip fill dates
109 $metric_opts = $metric->getOptionsRaw();
110 $metric_opts['skip_filling_dates'] = true;
111 $metric->setOptions($metric_opts);
112
113 // Set custom metrics
114 $metric->setCustomMetrics($found_metrics);
115 }
116 }
117
118 if ($update)
119 {
120 $metric->update();
121 }
122
123 $data[$key] = $metric->getData();
124 }
125
126 return $data;
127 }
128
129 /**
130 * Returns the default active metrics
131 *
132 * @return array
133 */
134 public function getDefaultActiveMetrics()
135 {
136 return self::default_active_metrics;
137 }
138
139 /**
140 * Returns all metrics labels
141 *
142 * @return array
143 */
144 public function getMetricsLabels()
145 {
146 $metrics = [];
147
148 foreach ($this->getMetrics() as $key => $metric)
149 {
150 if (!$metric instanceof Metric)
151 {
152 continue;
153 }
154
155 $metrics[$key] = $metric->getCleanLabel();
156 }
157
158 return $metrics;
159 }
160
161 /**
162 * Initialize all metrics items
163 *
164 * @return array
165 */
166 private function initializeMetrics()
167 {
168 foreach ($this->metrics_map as $metric => $value)
169 {
170 $class = '\FireBox\Core\Admin\Analytics\Metrics\\' . $value['class'];
171
172 if (!class_exists($class))
173 {
174 continue;
175 }
176
177 // init metric and fetch its data
178 $this->metrics[$metric] = new $class($this->toolbar);
179 }
180 }
181 }