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
firebox / Inc / Core / Analytics / Data.php

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

178 lines 4.0 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.1.4 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Analytics;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Data
20 {
21 private $start_date = null;
22
23 private $end_date = null;
24
25 private $metrics = [];
26
27 private $filters = [];
28
29 private $offset = null;
30
31 private $limit = null;
32
33 protected $options = [];
34
35 public function __construct($start_date = null, $end_date = null, $options = [])
36 {
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 }
53
54 $this->start_date = $start_date;
55 $this->end_date = $end_date;
56 $this->options = $options;
57 }
58
59 /**
60 * Allowed metrics:
61 *
62 * [
63 * 'impressions',
64 * 'averagetimeopen',
65 * 'submissions',
66 * 'conversionrate'
67 * ]
68 */
69 public function setMetrics($metrics = [])
70 {
71 $this->metrics = $metrics;
72 }
73
74 public function setFilters($filters = [])
75 {
76 $this->filters = $filters;
77 }
78
79 public function setOffset($offset = null)
80 {
81 $this->offset = (int) $offset;
82 }
83
84 public function setLimit($limit = null)
85 {
86 $this->limit = (int) $limit;
87 }
88
89 public function getData($type = 'list')
90 {
91 $data = array_fill_keys($this->metrics, []);
92
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;
100 }
101
102 $class = '\FireBox\Core\Analytics\Metrics\\' . $class_name;
103 $class = new $class($this->start_date, $this->end_date, $type, $this->options);
104
105 if ($this->filters)
106 {
107 $class->setFilters($this->filters);
108 }
109
110 if ($this->offset)
111 {
112 $class->setOffset($this->offset);
113 }
114
115 if ($this->limit)
116 {
117 $class->setLimit($this->limit);
118 }
119
120 $metric_data = $class->getData();
121
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 */
172
173 $class->onAfterGetData($metric_data);
174 }
175
176 return $data;
177 }
178 }