| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.13 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Analytics\Ajax; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use \FireBox\Core\Helpers\BoxHelper; |
| 20 |
|
| 21 |
class Analytics |
| 22 |
{ |
| 23 |
use Shared; |
| 24 |
|
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
add_action('wp_ajax_firebox_analytics_most_popular_campaigns', [$this, 'firebox_analytics_most_popular_campaigns']); |
| 28 |
|
| 29 |
add_action('wp_ajax_firebox_analytics_get_campaign', [$this, 'firebox_analytics_get_campaign']); |
| 30 |
|
| 31 |
add_action('wp_ajax_firebox_analytics_get_popular_view_items', [$this, 'firebox_analytics_get_popular_view_items']); |
| 32 |
|
| 33 |
add_action('wp_ajax_firebox_analytics_get_day_of_the_week', [$this, 'firebox_analytics_get_day_of_the_week']); |
| 34 |
|
| 35 |
add_action('wp_ajax_firebox_analytics_get_shared_data', [$this, 'firebox_analytics_get_shared_data']); |
| 36 |
|
| 37 |
add_action('wp_ajax_firebox_analytics_get_conversions_data', [$this, 'firebox_analytics_get_conversions_data']); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Most Popular Campaigns |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function firebox_analytics_most_popular_campaigns() |
| 46 |
{ |
| 47 |
if (!current_user_can('read_fireboxes')) |
| 48 |
{ |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 53 |
|
| 54 |
// verify nonce |
| 55 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 56 |
{ |
| 57 |
return false; |
| 58 |
} |
| 59 |
|
| 60 |
$start_date = isset($_POST['start_date']) ? sanitize_text_field(wp_unslash($_POST['start_date'])) : ''; |
| 61 |
$end_date = isset($_POST['end_date']) ? sanitize_text_field(wp_unslash($_POST['end_date'])) : ''; |
| 62 |
|
| 63 |
if (!$start_date || $start_date === 'false' || !$end_date || $end_date === 'false') |
| 64 |
{ |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
echo wp_json_encode([ |
| 72 |
'pro' => true |
| 73 |
]); |
| 74 |
wp_die(); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
/** |
| 81 |
* Get single campaign data |
| 82 |
* |
| 83 |
* @return void |
| 84 |
*/ |
| 85 |
public function firebox_analytics_get_campaign() |
| 86 |
{ |
| 87 |
if (!current_user_can('read_fireboxes')) |
| 88 |
{ |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 93 |
|
| 94 |
// verify nonce |
| 95 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 96 |
{ |
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
$campaign = isset($_POST['campaign']) ? intval($_POST['campaign']) : ''; |
| 101 |
if (!$campaign) |
| 102 |
{ |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
// Get campaign |
| 107 |
$campaign = BoxHelper::getBoxData($campaign); |
| 108 |
if (!$campaign) |
| 109 |
{ |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
// Get campaign meta |
| 114 |
$campaign->params = BoxHelper::getMeta($campaign->ID); |
| 115 |
|
| 116 |
// Get last date viewed |
| 117 |
$campaign->last_date_viewed = BoxHelper::getCampaignLastDateViewed($campaign->ID); |
| 118 |
|
| 119 |
echo wp_json_encode([ |
| 120 |
'error' => false, |
| 121 |
'campaign' => $campaign |
| 122 |
]); |
| 123 |
wp_die(); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Get popular view times data |
| 128 |
* |
| 129 |
* @return void |
| 130 |
*/ |
| 131 |
public function firebox_analytics_get_popular_view_items() |
| 132 |
{ |
| 133 |
if (!current_user_can('read_fireboxes')) |
| 134 |
{ |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 139 |
|
| 140 |
// verify nonce |
| 141 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 142 |
{ |
| 143 |
return false; |
| 144 |
} |
| 145 |
|
| 146 |
$start_date = isset($_POST['start_date']) ? sanitize_text_field(wp_unslash($_POST['start_date'])) : ''; |
| 147 |
$end_date = isset($_POST['end_date']) ? sanitize_text_field(wp_unslash($_POST['end_date'])) : ''; |
| 148 |
$weekday = isset($_POST['weekday']) ? intval($_POST['weekday']) : false; |
| 149 |
|
| 150 |
if (!$start_date || $start_date === 'false' || !$end_date || $end_date === 'false') |
| 151 |
{ |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
echo wp_json_encode([ |
| 159 |
'pro' => true |
| 160 |
]); |
| 161 |
wp_die(); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Get Day of the week data |
| 167 |
* |
| 168 |
* @return void |
| 169 |
*/ |
| 170 |
public function firebox_analytics_get_day_of_the_week() |
| 171 |
{ |
| 172 |
if (!current_user_can('read_fireboxes')) |
| 173 |
{ |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 178 |
|
| 179 |
// verify nonce |
| 180 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 181 |
{ |
| 182 |
return false; |
| 183 |
} |
| 184 |
|
| 185 |
$start_date = isset($_POST['start_date']) ? sanitize_text_field(wp_unslash($_POST['start_date'])) : ''; |
| 186 |
$end_date = isset($_POST['end_date']) ? sanitize_text_field(wp_unslash($_POST['end_date'])) : ''; |
| 187 |
|
| 188 |
if (!$start_date || $start_date === 'false' || !$end_date || $end_date === 'false') |
| 189 |
{ |
| 190 |
return; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
echo wp_json_encode([ |
| 197 |
'pro' => true |
| 198 |
]); |
| 199 |
wp_die(); |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Get shared data. |
| 205 |
* |
| 206 |
* Countries |
| 207 |
* Referrers |
| 208 |
* Devices |
| 209 |
* Events |
| 210 |
* Pages |
| 211 |
* |
| 212 |
* @return void |
| 213 |
*/ |
| 214 |
public function firebox_analytics_get_shared_data() |
| 215 |
{ |
| 216 |
if (!current_user_can('read_fireboxes')) |
| 217 |
{ |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 222 |
|
| 223 |
// verify nonce |
| 224 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 225 |
{ |
| 226 |
return false; |
| 227 |
} |
| 228 |
|
| 229 |
$start_date = isset($_POST['start_date']) ? sanitize_text_field(wp_unslash($_POST['start_date'])) : ''; |
| 230 |
$end_date = isset($_POST['end_date']) ? sanitize_text_field(wp_unslash($_POST['end_date'])) : ''; |
| 231 |
|
| 232 |
if (!$start_date || $start_date === 'false' || !$end_date || $end_date === 'false') |
| 233 |
{ |
| 234 |
return; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
echo wp_json_encode([ |
| 241 |
'pro' => true |
| 242 |
]); |
| 243 |
wp_die(); |
| 244 |
|
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Get conversions and conversion rate data per popup. |
| 249 |
* |
| 250 |
* @return void |
| 251 |
*/ |
| 252 |
public function firebox_analytics_get_conversions_data() |
| 253 |
{ |
| 254 |
if (!current_user_can('read_fireboxes')) |
| 255 |
{ |
| 256 |
return; |
| 257 |
} |
| 258 |
|
| 259 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 260 |
|
| 261 |
// verify nonce |
| 262 |
if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce')) |
| 263 |
{ |
| 264 |
return false; |
| 265 |
} |
| 266 |
|
| 267 |
$start_date = isset($_POST['start_date']) ? sanitize_text_field(wp_unslash($_POST['start_date'])) : ''; |
| 268 |
$end_date = isset($_POST['end_date']) ? sanitize_text_field(wp_unslash($_POST['end_date'])) : ''; |
| 269 |
|
| 270 |
if (!$start_date || $start_date === 'false' || !$end_date || $end_date === 'false') |
| 271 |
{ |
| 272 |
return; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
echo wp_json_encode([ |
| 279 |
'pro' => true |
| 280 |
]); |
| 281 |
wp_die(); |
| 282 |
|
| 283 |
} |
| 284 |
} |
| 285 |
|