PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.4
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.4
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
← All changes | Inc/Core/Analytics/Data.php +110 -166 3.1.72.1.4 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 3.1.7 Free
4 + * @version 2.1.4 Free
5 5 *
6 6 * @author FirePlugins <info@fireplugins.com>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2026 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FireBox\Core\Analytics;
@@ -18,18 +18,39 @@
18 18
19 19 class Data
20 20 {
21 21 private $start_date = null;
22 +
22 23 private $end_date = null;
24 +
23 25 private $metrics = [];
26 +
24 27 private $filters = [];
28 +
25 29 private $offset = null;
30 +
26 31 private $limit = null;
32 +
27 33 protected $options = [];
28 34
29 - public function __construct($start_date = '', $end_date = '', $options = [])
35 + public function __construct($start_date = null, $end_date = null, $options = [])
30 36 {
31 - Helpers\Date::transformStartEndDateToUTC($start_date, $end_date);
37 + $utcTimeZone = new \DateTimeZone('UTC');
38 + $tz = new \DateTimeZone(wp_timezone()->getName());
39 +
40 + // Make start in UTC
41 + if ($start_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $start_date, $tz))
42 + {
43 + $start_date_obj->setTimezone($utcTimeZone);
44 + $start_date = $start_date_obj->format('Y/m/d H:i:s');
45 + }
46 +
47 + // Make end_date in UTC
48 + if ($end_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $end_date, $tz))
49 + {
50 + $end_date_obj->setTimezone($utcTimeZone);
51 + $end_date = $end_date_obj->format('Y/m/d H:i:s');
52 + }
32 53
33 54 $this->start_date = $start_date;
34 55 $this->end_date = $end_date;
35 56 $this->options = $options;
@@ -35,200 +56,123 @@
35 56 $this->options = $options;
36 57 }
37 58
38 59 /**
39 - * Fluent interface for building analytics queries
60 + * Allowed metrics:
40 61 *
41 - * @param array $metrics Array of metric slugs
42 - * @return self
62 + * [
63 + * 'impressions',
64 + * 'averagetimeopen',
65 + * 'submissions',
66 + * 'conversionrate'
67 + * ]
43 68 */
44 - public function metrics(array $metrics)
69 + public function setMetrics($metrics = [])
45 70 {
46 71 $this->metrics = $metrics;
47 - return $this;
48 72 }
49 73
50 - /**
51 - * Fluent interface for adding filters
52 - *
53 - * @param array $filters
54 - * @return self
55 - */
56 - public function filters(array $filters)
74 + public function setFilters($filters = [])
57 75 {
58 76 $this->filters = $filters;
59 - return $this;
60 77 }
61 78
62 - /**
63 - * Fluent interface for pagination
64 - *
65 - * @param int $limit
66 - * @param int $offset
67 - * @return self
68 - */
69 - public function paginate($limit, $offset = 0)
79 + public function setOffset($offset = null)
70 80 {
71 - $this->limit = (int) $limit;
72 81 $this->offset = (int) $offset;
73 - return $this;
74 82 }
75 83
76 - /**
77 - * Fluent interface for setting limit
78 - *
79 - * @param int|null $limit
80 - * @return self
81 - */
82 - public function limit($limit)
84 + public function setLimit($limit = null)
83 85 {
84 - $this->limit = $limit !== null ? (int) $limit : null;
85 - return $this;
86 + $this->limit = (int) $limit;
86 87 }
87 88
88 - /**
89 - * Fluent interface for setting offset
90 - *
91 - * @param int $offset
92 - * @return self
93 - */
94 - public function offset($offset)
95 - {
96 - $this->offset = (int) $offset;
97 - return $this;
98 - }
99 -
100 - /**
101 - * Get analytics data with improved error handling and performance
102 - *
103 - * @param string $type
104 - * @return array
105 - */
106 89 public function getData($type = 'list')
107 90 {
108 - if (empty($this->metrics)) {
109 - return [];
110 - }
91 + $data = array_fill_keys($this->metrics, []);
111 92
112 - $data = [];
113 - $metric_configs = $this->buildMetricConfigs($type);
114 -
115 - foreach ($metric_configs as $metric_slug => $config) {
116 - try {
117 - $data[$metric_slug] = $this->getMetricData($config);
118 - } catch (\Exception $e) {
119 - $data[$metric_slug] = $this->getEmptyMetricData($type);
93 + foreach ($data as $metric_slug => &$metric_data)
94 + {
95 + // Validate the given metric name and abort if unknown
96 + if (!$class_name = \FireBox\Core\Analytics\Helpers\Metrics::getClassFromSlug($metric_slug))
97 + {
98 + unset($data[$metric_slug]);
99 + continue;
120 100 }
121 - }
122 101
123 - return $data;
124 - }
102 + $class = '\FireBox\Core\Analytics\Metrics\\' . $class_name;
103 + $class = new $class($this->start_date, $this->end_date, $type, $this->options);
125 104
126 - /**
127 - * Build metric configurations for batch processing
128 - *
129 - * @param string $type
130 - * @return array
131 - */
132 - private function buildMetricConfigs($type)
133 - {
134 - $configs = [];
105 + if ($this->filters)
106 + {
107 + $class->setFilters($this->filters);
108 + }
135 109
136 - foreach ($this->metrics as $metric_slug) {
137 - $class_name = \FireBox\Core\Analytics\Helpers\Metrics::getClassFromSlug($metric_slug);
138 -
139 - if (!$class_name) {
140 - continue;
110 + if ($this->offset)
111 + {
112 + $class->setOffset($this->offset);
141 113 }
142 114
143 - $class_path = '\FireBox\Core\Analytics\Metrics\\' . $class_name;
144 -
145 - if (!class_exists($class_path)) {
146 - continue;
115 + if ($this->limit)
116 + {
117 + $class->setLimit($this->limit);
147 118 }
148 119
149 - $configs[$metric_slug] = [
150 - 'class' => $class_path,
151 - 'type' => $type,
152 - 'start_date' => $this->start_date,
153 - 'end_date' => $this->end_date,
154 - 'options' => $this->options,
155 - 'filters' => $this->filters,
156 - 'limit' => $this->limit,
157 - 'offset' => $this->offset
158 - ];
159 - }
120 + $metric_data = $class->getData();
160 121
161 - return $configs;
162 - }
122 + /**
123 + * Get list of impressions from start_date till end_date
124 + * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
125 + * $metric->getData();
126 + *
127 + * Output:
128 + * [
129 + * 'date1' => 500,
130 + * 'date2' => 200
131 + * ]
132 + *
133 + * Get total impressions from start_date till end_date
134 + * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
135 + * $metric->getData('count');
136 + *
137 + * Output:
138 + * 700
139 + *
140 + * Get total impressions from start_date till end_date with the following filters:
141 + * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
142 + * $metric->setFilters($filters);
143 + * $metric->getData('count');
144 + *
145 + * Filters payload:
146 + * [
147 + * 'campaigns' => [
148 + * 'value' => [5, 10, 15],
149 + * ],
150 + * 'country' => [
151 + * 'value' => ['GR', 'UK', 'USA', 'DE'],
152 + * ],
153 + * 'device' => [
154 + * 'value' => ['desktop', 'tablet'],
155 + * ],
156 + * 'event' => [
157 + * 'value' => ['close'],
158 + * ],
159 + * 'page' => [
160 + * 'type' => 'contains', // contains, not_contains, equals
161 + * 'value' => ['/about', 'fireplugins'],
162 + * ],
163 + * 'referrer' => [
164 + * 'type' => 'contains', // contains, not_contains, equals
165 + * 'value' => ['google.com', 'facebook.com'],
166 + * ]
167 + * ]
168 + *
169 + * Output:
170 + * 50
171 + */
163 172
164 - /**
165 - * Get data for a single metric using dependency injection
166 - *
167 - * @param array $config
168 - * @return mixed
169 - */
170 - private function getMetricData(array $config)
171 - {
172 - $metric = $this->createMetric($config);
173 - $data = $metric->getData();
173 + $class->onAfterGetData($metric_data);
174 + }
174 175
175 - // Apply transformations through the registry system
176 - if (!empty($data)) {
177 - \FireBox\Core\Analytics\Transformers\TransformerRegistry::transformData(
178 - $data,
179 - $config['type'],
180 - array_merge($config['options'], [
181 - 'is_single_day' => \FireBox\Core\Analytics\Helpers\Date::isSingleDay(
182 - $config['start_date'],
183 - $config['end_date']
184 - ),
185 - 'has_timezone_sql_conversion' => method_exists($metric, 'hasTimezoneSQLConversion') ? $metric->hasTimezoneSQLConversion() : false
186 - ])
187 - );
188 - }
189 -
190 176 return $data;
191 - }
192 -
193 - /**
194 - * Create metric instance with all dependencies injected
195 - *
196 - * @param array $config
197 - * @return object
198 - */
199 - private function createMetric(array $config)
200 - {
201 - $metric = new $config['class'](
202 - $config['start_date'],
203 - $config['end_date'],
204 - $config['type'],
205 - $config['options']
206 - );
207 -
208 - // Inject dependencies in one go
209 - if (!empty($config['filters'])) {
210 - $metric->filters($config['filters']);
211 - }
212 -
213 - if (!empty($config['limit'])) {
214 - $metric->limit($config['limit']);
215 - }
216 -
217 - if (!empty($config['offset'])) {
218 - $metric->offset($config['offset']);
219 - }
220 -
221 - return $metric;
222 - }
223 -
224 - /**
225 - * Get empty data structure for failed metrics
226 - *
227 - * @param string $type
228 - * @return mixed
229 - */
230 - private function getEmptyMetricData($type)
231 - {
232 - return $type === 'count' ? 0 : [];
233 177 }
234 178 }