# firebox/3.1.14/Inc/Core/UsageTracking/SendUsage.php

FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin &amp; Cart Abandonment, version 3.1.14. 135 lines.

- Page: https://pluginprobe.com/plugins/firebox/3.1.14/code/Inc/Core/UsageTracking/SendUsage.php
- Raw: https://pluginprobe.com/plugins/firebox/3.1.14/raw/Inc/Core/UsageTracking/SendUsage.php
- Modified: 2026-10-02T13:37:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/firebox/3.1.14/code/Inc/Core/UsageTracking/SendUsage.php#L10-L20`.

```php
<?php
/**
 * @package         FireBox
 * @version         3.1.14 Free
 * 
 * @author          FirePlugins <info@fireplugins.com>
 * @link            https://www.fireplugins.com
 * @copyright       Copyright © 2026 FirePlugins All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/

namespace FireBox\Core\UsageTracking;

if (!defined('ABSPATH'))
{
	exit; // Exit if accessed directly.
}

class SendUsage
{
    /**
     * The hook name to send the tracking data.
     * 
     * @var string
     */
    private $tracking_hook = 'firebox_usage_tracking';

    /**
     * API URL to send the tracking data.
     * 
     * @var string
     */
    const API_URL = 'https://usage.fireboxwp.com/wp-json/usage-tracking/v1/track';

    public function __construct()
    {
        // Add the tracking action
        add_action($this->tracking_hook, [$this, 'track']);
    }

    public function maybeStart()
    {
        // Start only if usage tracking is enabled in settings
        $settings = get_option('firebox_settings');

        if (!isset($settings['usage_tracking']))
        {
            return;
        }

        if (!$settings['usage_tracking'])
        {
            return;
        }

        /**
         * A network is one install, so it reports once. Without this every site
         * that opts in sends its own weekly payload for the same install.
         */
        if (is_multisite() && !$this->isTrackingSite())
        {
            return;
        }

        if (wp_next_scheduled($this->tracking_hook))
        {
            return;
        }

        // Schedule event to run weekly from now
        wp_schedule_event(time(), 'weekly', $this->tracking_hook);
    }

    /**
     * Whether this site is the one that reports for the network.
     *
     * The first site to opt in claims it, so a network whose main site never
     * enables tracking still reports. The claim is released by stop().
     *
     * @return  bool
     */
    private function isTrackingSite()
    {
        $claimed = (int) get_site_option('firebox_usage_tracking_site', 0);

        if ($claimed && get_site($claimed))
        {
            return $claimed === get_current_blog_id();
        }

        update_site_option('firebox_usage_tracking_site', get_current_blog_id());

        return true;
    }
    
    public function track()
    {
        // Abort if site URL contains "fireplugins.test", "fireplugins.com", or "fireboxwp.com"
        $site_url = home_url();
        if (strpos($site_url, 'fireplugins.test') !== false || strpos($site_url, 'fireplugins.com') !== false || strpos($site_url, 'fireboxwp.com') !== false)
        {
            return;
        }
        
        $tracking = new UsageTracking();

        wp_remote_post(self::API_URL, [
            'sslverify'   => false,
            'timeout'     => 5,
            'redirection' => 5,
            'httpversion' => '1.1',
            'blocking'    => true,
            'body'        => $tracking->getData(),
            'headers'     => [
                'User-Agent' => $tracking->get_user_agent(),
            ],
        ]);
    }
    
    public function stop()
    {
        $timestamp = wp_next_scheduled($this->tracking_hook);

        if ($timestamp)
        {
            wp_unschedule_event($timestamp, $this->tracking_hook);
        }

        // Release the network claim so another site can report.
        if (is_multisite() && (int) get_site_option('firebox_usage_tracking_site', 0) === get_current_blog_id())
        {
            delete_site_option('firebox_usage_tracking_site');
        }
    }
}
```
