PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.5
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.5
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 / FB / Track.php

Track.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.0.5, at Inc/Core/FB/Track.php

195 lines 4.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 1.0.5 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2021 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\FB;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Track
20 {
21 public function __construct()
22 {
23 $this->setupAjax();
24 }
25
26 /**
27 * Setup ajax requests
28 *
29 * @return void
30 */
31 public function setupAjax()
32 {
33 // FB Track event AJAX
34 add_action('wp_ajax_fb_trackevent', [$this, 'fb_trackevent']);
35 add_action('wp_ajax_nopriv_fb_trackevent', [$this, 'fb_trackevent']);
36 }
37
38 /**
39 * Box Track Event
40 *
41 * @return string
42 */
43 public function fb_trackevent()
44 {
45 $nonce = isset($_GET['nonce']) ? sanitize_text_field($_GET['nonce']) : '';
46
47 // verify nonce
48 if (!$verify = wp_verify_nonce($nonce, 'fbox_js_nonce'))
49 {
50 return false;
51 }
52
53 $event = isset($_GET['event']) ? sanitize_text_field($_GET['event']) : '';
54 $box_id = isset($_GET['box']) ? sanitize_text_field($_GET['box']) : '';
55 $page = '';
56 $referrer = '';
57 $box_log_id = '';
58
59 $response['success'] = false;
60
61 // ensure non-empty values
62 if (empty($event) || empty($box_id))
63 {
64 echo json_encode($response);
65 wp_die();
66 }
67
68 // ensure valid event
69 if (!in_array($event, ['open', 'close']))
70 {
71 echo json_encode($response);
72 wp_die();
73 }
74
75 // If its a close event, it should also provide the box log ID in order to add close date of box
76 if ($event == 'close')
77 {
78 if (!isset($_GET['box_log_id']))
79 {
80 return;
81 }
82
83 $box_log_id = sanitize_text_field($_GET['box_log_id']);
84 }
85 else if ($event == 'open')
86 {
87 if (!isset($_GET['page']) && !isset($_GET['referrer']))
88 {
89 return;
90 }
91
92 $page = sanitize_text_field($_GET['page']);
93 $referrer = sanitize_text_field($_GET['referrer']);
94 }
95
96 // Load box settings
97 if (!$box = firebox()->box->get($box_id))
98 {
99 return;
100 }
101
102 /**
103 * Trigger Open & Close Event.
104 */
105 do_action('firebox/box/on_' . $event, $box);
106
107 // get options
108 $options = isset($_GET['options']) ? wp_unslash($_GET['options']) : [];
109
110 $response['success'] = true;
111
112 if ($event == 'open')
113 {
114 $response['box_log_id'] = $this->handleOpenEvent($box, $box_id, $page, $referrer);
115 }
116
117 // Log impression in the database
118 if ($event == 'close')
119 {
120 $this->handleCloseEvent($box, $box_id, $box_log_id, $options, $response);
121 }
122
123 echo json_encode($response);
124 wp_die();
125 }
126
127 /**
128 * Handle Open Event
129 *
130 * @param object $box
131 * @param int $box_id
132 * @param string $page
133 * @param string $referrer
134 *
135 * @return void
136 */
137 protected function handleOpenEvent($box, $box_id, $page, $referrer)
138 {
139 // Do not track when box is on test mode
140 if (!$box->params->get('testmode'))
141 {
142 return firebox()->box->logOpenEvent($box_id, $page, $referrer);
143 }
144 }
145
146 /**
147 * Handle Close Event
148 *
149 * @param object $box
150 * @param int $box_id
151 * @param int $box_log_id
152 * @param array $options
153 * @param array $response
154 *
155 * @return void
156 */
157 protected function handleCloseEvent($box, $box_id, $box_log_id, $options, &$response)
158 {
159 // Do not track when box is on test mode
160 if (!$box->params->get('testmode'))
161 {
162 firebox()->box->logCloseEvent($box_id, $box_log_id);
163 }
164
165 // Do not set any cookie if box is on test mode
166 if (!$box->params->get('testmode') && !isset($options['temporary']))
167 {
168 // allow to prevent cookie from being set
169 if (!apply_filters('firebox/box/close/cookie_set', true, $box_id))
170 {
171 return;
172 }
173
174 if ($this->cookieExist($box_id))
175 {
176 $response['action'] = 'stop';
177 }
178 }
179 }
180
181 /**
182 * Check whether the cookie exists.
183 *
184 * @param int $box_id
185 *
186 * @return bool
187 */
188 protected function cookieExist($box_id)
189 {
190 $cookie = new \FireBox\Core\FB\Cookie($box_id);
191 $cookie->set();
192
193 return $cookie->exist();
194 }
195 }