| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.12 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\UsageTracking; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class UsageTracking |
| 20 |
{ |
| 21 |
private $settings = []; |
| 22 |
|
| 23 |
private $pluginData = []; |
| 24 |
|
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
$this->settings = get_option('firebox_settings', []); |
| 28 |
$this->pluginData = new PluginData(); |
| 29 |
} |
| 30 |
|
| 31 |
public function getData() |
| 32 |
{ |
| 33 |
global $wpdb; |
| 34 |
|
| 35 |
$theme_data = wp_get_theme(); |
| 36 |
$database_version = $wpdb->db_version(); |
| 37 |
|
| 38 |
$payload = [ |
| 39 |
// Generic Data |
| 40 |
'url' => home_url(), |
| 41 |
'email' => get_option('admin_email'), |
| 42 |
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, |
| 43 |
'wp_version' => get_bloginfo('version'), |
| 44 |
'database_type' => $this->getDatabaseType($database_version), |
| 45 |
'database_driver' => $this->getDatabaseDriver(), |
| 46 |
'database_version' => $database_version, |
| 47 |
'server_version' => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
| 48 |
'is_debug' => defined('WP_DEBUG') && WP_DEBUG, |
| 49 |
'is_ssl' => is_ssl(), |
| 50 |
'is_multisite' => is_multisite(), |
| 51 |
'is_network_activated' => $this->is_active_for_network(), |
| 52 |
'is_wpcom' => defined('IS_WPCOM') && IS_WPCOM, |
| 53 |
'is_wpcom_vip' => (defined('WPCOM_IS_VIP_ENV') && WPCOM_IS_VIP_ENV) || (function_exists('wpcom_is_vip') && wpcom_is_vip()), |
| 54 |
'is_wp_cache' => defined('WP_CACHE') && WP_CACHE, |
| 55 |
'sites_count' => $this->get_sites_total(), |
| 56 |
'active_plugins' => $this->get_active_plugins(), |
| 57 |
'theme_name' => $theme_data->get('Name'), |
| 58 |
'theme_version' => $theme_data->get('Version'), |
| 59 |
'locale' => get_locale(), |
| 60 |
'timezone_offset' => wp_timezone_string(), |
| 61 |
// FireBox Specific Data |
| 62 |
'firebox_version' => FBOX_VERSION, |
| 63 |
'firebox_license_key' => \FireBox\Core\Helpers\License::getKey(), |
| 64 |
'firebox_license_type' => FBOX_LICENSE_TYPE, |
| 65 |
'firebox_license_plan' => FBOX_LICENSE_PLAN, |
| 66 |
'firebox_license_status' => \FireBox\Core\Helpers\License::getStatus(), |
| 67 |
'firebox_is_pro' => FBOX_LICENSE_TYPE === 'pro', |
| 68 |
'firebox_connected_integrations' => $this->getConnectedIntegrations(), |
| 69 |
'firebox_views' => $this->pluginData->getViews(), |
| 70 |
'firebox_dimensions' => $this->pluginData->getDimensionsData(), |
| 71 |
'firebox_campaigns_published' => $this->pluginData->getCampaigns('publish'), |
| 72 |
'firebox_campaigns_draft' => $this->pluginData->getCampaigns('draft'), |
| 73 |
'firebox_campaigns_trash' => $this->pluginData->getCampaigns('trash'), |
| 74 |
'firebox_ttf_draft_sec' => $this->pluginData->getTimeToFirstCampaignDraft(), |
| 75 |
'firebox_ttf_publish_sec' => $this->pluginData->getTimeToFirstCampaignPublish(), |
| 76 |
'firebox_submissions' => $this->pluginData->getSubmissions(), |
| 77 |
'firebox_view_through_revenue' => $this->pluginData->getViewThroughRevenue(), |
| 78 |
'firebox_click_through_revenue' => $this->pluginData->getClickThroughRevenue(), |
| 79 |
'firebox_classic_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'popup'), |
| 80 |
'firebox_mode_slide_in' => $this->pluginData->getTotalsBySetting('mode', 'slide-in'), |
| 81 |
'firebox_mode_fullscreen' => $this->pluginData->getTotalsBySetting('mode', 'fullscreen'), |
| 82 |
'firebox_mode_stickybar' => $this->pluginData->getTotalsBySetting('mode', 'stickybar'), |
| 83 |
'firebox_pageslide_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'pageslide'), |
| 84 |
'firebox_mode_floating' => $this->pluginData->getTotalsBySetting('mode', 'floating'), |
| 85 |
'firebox_mode_sidebar' => $this->pluginData->getTotalsBySetting('mode', 'sidebar'), |
| 86 |
'firebox_embed_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'embed'), |
| 87 |
'firebox_campaigns_pageload' => $this->pluginData->getTotalsBySetting('triggermethod', 'pageload'), |
| 88 |
'firebox_campaigns_scroll_depth' => $this->pluginData->getTotalsBySetting('triggermethod', 'pageheight'), |
| 89 |
'firebox_campaigns_element_visibility' => $this->pluginData->getTotalsBySetting('triggermethod', 'element'), |
| 90 |
'firebox_campaigns_exit_intent' => $this->pluginData->getTotalsBySetting('triggermethod', 'userleave'), |
| 91 |
'firebox_campaigns_click' => $this->pluginData->getTotalsBySetting('triggermethod', 'onclick'), |
| 92 |
'firebox_campaigns_external_link_click' => $this->pluginData->getTotalsBySetting('triggermethod', 'onexternallink'), |
| 93 |
'firebox_campaigns_hover' => $this->pluginData->getTotalsBySetting('triggermethod', 'elementHover'), |
| 94 |
'firebox_campaigns_adblock_detect' => $this->pluginData->getTotalsBySetting('triggermethod', 'onAdBlockDetect'), |
| 95 |
'firebox_campaigns_idle' => $this->pluginData->getTotalsBySetting('triggermethod', 'onIdle'), |
| 96 |
'firebox_campaigns_floating_button' => $this->pluginData->getTotalsBySetting('triggermethod', 'floatingbutton'), |
| 97 |
'firebox_campaigns_manual' => $this->pluginData->getTotalsBySetting('triggermethod', 'ondemand'), |
| 98 |
'firebox_show_frequency_always' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'always'), |
| 99 |
'firebox_show_frequency_session' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'session'), |
| 100 |
'firebox_show_frequency_day' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'day'), |
| 101 |
'firebox_show_frequency_week' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'week'), |
| 102 |
'firebox_show_frequency_custom' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'custom'), |
| 103 |
'firebox_cookie_never' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'never'), |
| 104 |
'firebox_cookie_ever' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'ever'), |
| 105 |
'firebox_cookie_session' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'session'), |
| 106 |
'firebox_cookie_custom' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'custom'), |
| 107 |
'firebox_auto_close' => $this->pluginData->getTotalsBySetting('box_auto_close', 'boolean'), |
| 108 |
'firebox_auto_focus' => $this->pluginData->getTotalsBySetting('autofocus', 'boolean'), |
| 109 |
'firebox_close_with_esc' => $this->pluginData->getTotalsBySetting('close_on_esc', 'boolean'), |
| 110 |
'firebox_display_conditions_all' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'all'), |
| 111 |
'firebox_display_conditions_mirror' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'mirror'), |
| 112 |
'firebox_display_conditions_custom' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'custom'), |
| 113 |
'firebox_campaigns_with_sound' => $this->pluginData->getTotalsBySetting('opening_sound.source', 'cond:not:none'), |
| 114 |
'firebox_cond_date' => $this->pluginData->getTotalsByCondition('Date\Date'), |
| 115 |
'firebox_cond_day_of_week' => $this->pluginData->getTotalsByCondition('Date\Day'), |
| 116 |
'firebox_cond_month' => $this->pluginData->getTotalsByCondition('Date\Month'), |
| 117 |
'firebox_cond_time' => $this->pluginData->getTotalsByCondition('Date\Time'), |
| 118 |
'firebox_cond_user' => $this->pluginData->getTotalsByCondition('WP\UserID'), |
| 119 |
'firebox_cond_menu' => $this->pluginData->getTotalsByCondition('WP\Menu'), |
| 120 |
'firebox_cond_user_group' => $this->pluginData->getTotalsByCondition('WP\UserGroup'), |
| 121 |
'firebox_cond_post' => $this->pluginData->getTotalsByCondition('WP\Posts'), |
| 122 |
'firebox_cond_page' => $this->pluginData->getTotalsByCondition('WP\Pages'), |
| 123 |
'firebox_cond_post_tag' => $this->pluginData->getTotalsByCondition('WP\Tags'), |
| 124 |
'firebox_cond_post_category' => $this->pluginData->getTotalsByCondition('WP\Categories'), |
| 125 |
'firebox_cond_cpt' => $this->pluginData->getTotalsByCondition('WP\CustomPostTypes'), |
| 126 |
'firebox_cond_homepage' => $this->pluginData->getTotalsByCondition('WP\Homepage'), |
| 127 |
'firebox_cond_device' => $this->pluginData->getTotalsByCondition('Device'), |
| 128 |
'firebox_cond_browser' => $this->pluginData->getTotalsByCondition('Browser'), |
| 129 |
'firebox_cond_os' => $this->pluginData->getTotalsByCondition('OS'), |
| 130 |
'firebox_cond_city' => $this->pluginData->getTotalsByCondition('Geo\City'), |
| 131 |
'firebox_cond_country' => $this->pluginData->getTotalsByCondition('Geo\Country'), |
| 132 |
'firebox_cond_region' => $this->pluginData->getTotalsByCondition('Geo\Region'), |
| 133 |
'firebox_cond_continent' => $this->pluginData->getTotalsByCondition('Geo\Continent'), |
| 134 |
'firebox_cond_fb_view_campaign' => $this->pluginData->getTotalsByCondition('FireBox\Popup'), |
| 135 |
'firebox_cond_fb_submitted_form' => $this->pluginData->getTotalsByCondition('FireBox\Form'), |
| 136 |
'firebox_cond_edd_products_in_cart' => $this->pluginData->getTotalsByCondition('EDD\CartContainsProducts'), |
| 137 |
'firebox_cond_edd_cart_items_count' => $this->pluginData->getTotalsByCondition('EDD\CartContainsXProducts'), |
| 138 |
'firebox_cond_edd_amount_in_cart' => $this->pluginData->getTotalsByCondition('EDD\CartValue'), |
| 139 |
'firebox_cond_edd_current_product' => $this->pluginData->getTotalsByCondition('EDD\Product'), |
| 140 |
'firebox_cond_edd_purchased_product' => $this->pluginData->getTotalsByCondition('EDD\PurchasedProduct'), |
| 141 |
'firebox_cond_edd_last_purchased_date' => $this->pluginData->getTotalsByCondition('EDD\LastPurchaseDate'), |
| 142 |
'firebox_cond_edd_current_product_price' => $this->pluginData->getTotalsByCondition('EDD\CurrentProductPrice'), |
| 143 |
'firebox_cond_edd_total_spend' => $this->pluginData->getTotalsByCondition('EDD\TotalSpend'), |
| 144 |
'firebox_cond_edd_current_product_category' => $this->pluginData->getTotalsByCondition('EDD\Category'), |
| 145 |
'firebox_cond_edd_category' => $this->pluginData->getTotalsByCondition('EDD\CategoryView'), |
| 146 |
'firebox_cond_woo_products_in_cart' => $this->pluginData->getTotalsByCondition('WooCommerce\CartContainsProducts'), |
| 147 |
'firebox_cond_woo_cart_items_count' => $this->pluginData->getTotalsByCondition('WooCommerce\CartContainsXProducts'), |
| 148 |
'firebox_cond_woo_amount_in_cart' => $this->pluginData->getTotalsByCondition('WooCommerce\CartValue'), |
| 149 |
'firebox_cond_woo_current_product' => $this->pluginData->getTotalsByCondition('WooCommerce\Product'), |
| 150 |
'firebox_cond_woo_purchased_product' => $this->pluginData->getTotalsByCondition('WooCommerce\PurchasedProduct'), |
| 151 |
'firebox_cond_woo_last_purchased_date' => $this->pluginData->getTotalsByCondition('WooCommerce\LastPurchaseDate'), |
| 152 |
'firebox_cond_woo_current_product_price' => $this->pluginData->getTotalsByCondition('WooCommerce\CurrentProductPrice'), |
| 153 |
'firebox_cond_woo_total_spend' => $this->pluginData->getTotalsByCondition('WooCommerce\TotalSpend'), |
| 154 |
'firebox_cond_woo_current_product_category' => $this->pluginData->getTotalsByCondition('WooCommerce\Category'), |
| 155 |
'firebox_cond_woo_category' => $this->pluginData->getTotalsByCondition('WooCommerce\CategoryView'), |
| 156 |
'firebox_cond_url' => $this->pluginData->getTotalsByCondition('URL'), |
| 157 |
'firebox_cond_referrer' => $this->pluginData->getTotalsByCondition('Referrer'), |
| 158 |
'firebox_cond_ip' => $this->pluginData->getTotalsByCondition('IP'), |
| 159 |
'firebox_cond_pageviews' => $this->pluginData->getTotalsByCondition('Pageviews'), |
| 160 |
'firebox_cond_cookies' => $this->pluginData->getTotalsByCondition('Cookie'), |
| 161 |
'firebox_cond_php' => $this->pluginData->getTotalsByCondition('PHP'), |
| 162 |
'firebox_cond_wpml_language' => $this->pluginData->getTotalsByCondition('Language'), |
| 163 |
'firebox_cond_timeonsite' => $this->pluginData->getTotalsByCondition('TimeOnSite'), |
| 164 |
'firebox_cond_new_returning_visitor' => $this->pluginData->getTotalsByCondition('NewReturningVisitor'), |
| 165 |
'firebox_actions' => $this->pluginData->getTotalsBySetting('actions', 'cond:not:emptyArray'), |
| 166 |
'firebox_php_scripts_on_before' => $this->pluginData->getTotalsBySetting('phpscripts.beforerender', 'cond:not:empty'), |
| 167 |
'firebox_php_scripts_on_after' => $this->pluginData->getTotalsBySetting('phpscripts.afterrender', 'cond:not:empty'), |
| 168 |
'firebox_php_scripts_on_open' => $this->pluginData->getTotalsBySetting('phpscripts.open', 'cond:not:empty'), |
| 169 |
'firebox_php_scripts_on_close' => $this->pluginData->getTotalsBySetting('phpscripts.close', 'cond:not:empty'), |
| 170 |
'firebox_php_scripts_on_form_success' => $this->pluginData->getTotalsBySetting('phpscripts.formsuccess', 'cond:not:empty'), |
| 171 |
'firebox_custom_css' => $this->pluginData->getTotalsBySetting('customcss', 'cond:not:empty'), |
| 172 |
'firebox_custom_javascript' => $this->pluginData->getTotalsBySetting('customcode', 'cond:not:empty'), |
| 173 |
'firebox_test_mode' => $this->pluginData->getTotalsBySetting('testmode', 'boolean'), |
| 174 |
'firebox_prevent_page_scrollling' => $this->pluginData->getTotalsBySetting('preventpagescroll', 'boolean'), |
| 175 |
'firebox_settings' => $this->getSettings() |
| 176 |
]; |
| 177 |
|
| 178 |
return $payload; |
| 179 |
} |
| 180 |
|
| 181 |
private function getDatabaseType($database_version = '') |
| 182 |
{ |
| 183 |
$database_version = strtolower(trim((string) $database_version)); |
| 184 |
$database_driver = strtolower((string) $this->getDatabaseDriver()); |
| 185 |
|
| 186 |
if (strpos($database_version, 'mariadb') !== false || strpos($database_driver, 'mariadb') !== false) |
| 187 |
{ |
| 188 |
return 'MariaDB'; |
| 189 |
} |
| 190 |
|
| 191 |
if ( |
| 192 |
strpos($database_driver, 'mysql') !== false || |
| 193 |
strpos($database_driver, 'mysqli') !== false || |
| 194 |
strpos($database_driver, 'pdo_mysql') !== false || |
| 195 |
strpos($database_driver, 'pdo\\mysql') !== false |
| 196 |
) |
| 197 |
{ |
| 198 |
return 'MySQL'; |
| 199 |
} |
| 200 |
|
| 201 |
if ($database_version !== '') |
| 202 |
{ |
| 203 |
return 'MySQL'; |
| 204 |
} |
| 205 |
|
| 206 |
return 'Unknown'; |
| 207 |
} |
| 208 |
|
| 209 |
private function getDatabaseDriver() |
| 210 |
{ |
| 211 |
global $wpdb; |
| 212 |
|
| 213 |
if (is_object($wpdb->dbh)) |
| 214 |
{ |
| 215 |
// mysqli or PDO |
| 216 |
$extension = get_class($wpdb->dbh); |
| 217 |
} |
| 218 |
else |
| 219 |
{ |
| 220 |
// Unknown sql extension |
| 221 |
$extension = null; |
| 222 |
} |
| 223 |
|
| 224 |
return $extension; |
| 225 |
} |
| 226 |
|
| 227 |
private function getSettings() |
| 228 |
{ |
| 229 |
$excluded_keys = [ |
| 230 |
'api_key', |
| 231 |
'geo_license_key', |
| 232 |
'license_key', |
| 233 |
'cloudflare_turnstile_site_key', |
| 234 |
'cloudflare_turnstile_secret_key', |
| 235 |
'recaptcha_v2_checkbox_site_key', |
| 236 |
'recaptcha_v2_checkbox_secret_key', |
| 237 |
'recaptcha_v2_invisible_site_key', |
| 238 |
'recaptcha_v2_invisible_secret_key', |
| 239 |
'recaptcha_v3_site_key', |
| 240 |
'recaptcha_v3_secret_key', |
| 241 |
'hcaptcha_site_key', |
| 242 |
'hcaptcha_secret_key', |
| 243 |
'openai_api_key', |
| 244 |
'stripe_test_secret_key', |
| 245 |
'stripe_test_publishable_key', |
| 246 |
'stripe_live_secret_key', |
| 247 |
'stripe_live_publishable_key', |
| 248 |
'stripe_webhooks_secret_test', |
| 249 |
'stripe_webhooks_secret_live', |
| 250 |
'stripe_webhooks_id_test', |
| 251 |
'stripe_webhooks_id_live', |
| 252 |
]; |
| 253 |
|
| 254 |
$excluded_keys = array_merge( |
| 255 |
$excluded_keys, |
| 256 |
\FireBox\Core\Helpers\Integrations::getSettingsKeys() |
| 257 |
); |
| 258 |
|
| 259 |
return array_diff_key( |
| 260 |
$this->settings, |
| 261 |
array_flip($excluded_keys) |
| 262 |
); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Returns currently connected integrations. |
| 267 |
* |
| 268 |
* @return array |
| 269 |
*/ |
| 270 |
private function getConnectedIntegrations() |
| 271 |
{ |
| 272 |
$connected_integrations = []; |
| 273 |
$integrations = \FireBox\Core\Helpers\Integrations::getSettingsManagedIntegrations(); |
| 274 |
if (!is_array($integrations)) |
| 275 |
{ |
| 276 |
return $connected_integrations; |
| 277 |
} |
| 278 |
|
| 279 |
foreach ($integrations as $integration) |
| 280 |
{ |
| 281 |
if (!is_array($integration) || empty($integration['slug']) || empty($integration['connected'])) |
| 282 |
{ |
| 283 |
continue; |
| 284 |
} |
| 285 |
|
| 286 |
$connected_integrations[] = (string) $integration['slug']; |
| 287 |
} |
| 288 |
|
| 289 |
return $connected_integrations; |
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* Determines whether the plugin is active for the entire network. |
| 294 |
* |
| 295 |
* @return bool |
| 296 |
*/ |
| 297 |
private function is_active_for_network() |
| 298 |
{ |
| 299 |
// Stop if not multisite |
| 300 |
if (!is_multisite()) |
| 301 |
{ |
| 302 |
return false; |
| 303 |
} |
| 304 |
|
| 305 |
// Get all active plugins |
| 306 |
$plugins = get_site_option('active_sitewide_plugins'); |
| 307 |
|
| 308 |
// Stop if the plugin is active for the entire network |
| 309 |
if (isset($plugins[plugin_basename(FBOX_PLUGIN_BASE_FILE)])) |
| 310 |
{ |
| 311 |
return true; |
| 312 |
} |
| 313 |
|
| 314 |
return false; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Total number of sites. |
| 319 |
* |
| 320 |
* @return int |
| 321 |
*/ |
| 322 |
private function get_sites_total() |
| 323 |
{ |
| 324 |
return function_exists('get_blog_count') ? (int) get_blog_count() : 1; |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* Get the list of active plugins. |
| 329 |
* |
| 330 |
* @return array |
| 331 |
*/ |
| 332 |
private function get_active_plugins() |
| 333 |
{ |
| 334 |
if (!function_exists('get_plugins')) |
| 335 |
{ |
| 336 |
include ABSPATH . '/wp-admin/includes/plugin.php'; |
| 337 |
} |
| 338 |
|
| 339 |
$active = is_multisite() ? |
| 340 |
array_merge(get_option('active_plugins', []), array_flip(get_site_option('active_sitewide_plugins', []))) : |
| 341 |
get_option('active_plugins', []); |
| 342 |
$plugins = array_intersect_key(get_plugins(), array_flip($active)); |
| 343 |
|
| 344 |
return array_map( |
| 345 |
static function ($plugin) |
| 346 |
{ |
| 347 |
if (isset($plugin['Version'])) |
| 348 |
{ |
| 349 |
return $plugin['Version']; |
| 350 |
} |
| 351 |
|
| 352 |
return 'Not Set'; |
| 353 |
}, |
| 354 |
$plugins |
| 355 |
); |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* Return the User Agent used in the API request. |
| 360 |
* |
| 361 |
* @return string |
| 362 |
*/ |
| 363 |
public function get_user_agent() |
| 364 |
{ |
| 365 |
return 'FireBox/' . FBOX_VERSION . '; ' . get_bloginfo('url'); |
| 366 |
} |
| 367 |
} |
| 368 |
|