# firebox/2.1.4/Inc/Core/Analytics/Data.php

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

- Page: https://pluginprobe.com/plugins/firebox/2.1.4/code/Inc/Core/Analytics/Data.php
- Raw: https://pluginprobe.com/plugins/firebox/2.1.4/raw/Inc/Core/Analytics/Data.php
- Modified: 2024-01-26T11:44:48+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/2.1.4/code/Inc/Core/Analytics/Data.php#L10-L20`.

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

namespace FireBox\Core\Analytics;

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

class Data
{
	private $start_date = null;

	private $end_date = null;
	
	private $metrics = [];

	private $filters = [];

	private $offset = null;

	private $limit = null;

	protected $options = [];
	
	public function __construct($start_date = null, $end_date = null, $options = [])
	{
		$utcTimeZone = new \DateTimeZone('UTC');
		$tz = new \DateTimeZone(wp_timezone()->getName());

		// Make start in UTC
		if ($start_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $start_date, $tz))
		{
			$start_date_obj->setTimezone($utcTimeZone);
			$start_date = $start_date_obj->format('Y/m/d H:i:s');
		}

		// Make end_date in UTC
		if ($end_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $end_date, $tz))
		{
			$end_date_obj->setTimezone($utcTimeZone);
			$end_date = $end_date_obj->format('Y/m/d H:i:s');
		}
		
		$this->start_date = $start_date;
		$this->end_date = $end_date;
		$this->options = $options;
	}

	/**
	 * Allowed metrics:
	 * 
	 * [
	 * 	  'impressions',
	 * 	  'averagetimeopen',
	 * 	  'submissions',
	 * 	  'conversionrate'
	 * ]
	 */
	public function setMetrics($metrics = [])
	{
		$this->metrics = $metrics;
	}

	public function setFilters($filters = [])
	{
		$this->filters = $filters;
	}

	public function setOffset($offset = null)
	{
		$this->offset = (int) $offset;
	}

	public function setLimit($limit = null)
	{
		$this->limit = (int) $limit;
	}

	public function getData($type = 'list')
	{
		$data = array_fill_keys($this->metrics, []);

		foreach ($data as $metric_slug => &$metric_data)
		{
			// Validate the given metric name and abort if unknown
			if (!$class_name = \FireBox\Core\Analytics\Helpers\Metrics::getClassFromSlug($metric_slug))
			{
				unset($data[$metric_slug]);
				continue;
			}

			$class = '\FireBox\Core\Analytics\Metrics\\' . $class_name;
			$class = new $class($this->start_date, $this->end_date, $type, $this->options);

			if ($this->filters)
			{
				$class->setFilters($this->filters);
			}

			if ($this->offset)
			{
				$class->setOffset($this->offset);
			}

			if ($this->limit)
			{
				$class->setLimit($this->limit);
			}

			$metric_data = $class->getData();

			/**
			 * Get list of impressions from start_date till end_date
			 * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
			 * $metric->getData();
			 * 
			 * Output:
			 * [
			 *    'date1' => 500,
			 *    'date2' => 200
			 * ]
			 * 
			 * Get total impressions from start_date till end_date
			 * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
			 * $metric->getData('count');
			 * 
			 * Output:
			 * 700
			 * 
			 * Get total impressions from start_date till end_date with the following filters:
			 * $metric = new \FireBox\Core\Analytics\Metrics\Impressions($start_date, $end_date);
			 * $metric->setFilters($filters);
			 * $metric->getData('count');
			 * 
			 * Filters payload:
			 * [
			 *    'campaigns' => [
			 *        'value' => [5, 10, 15],
			 *    ],
			 *    'country' => [
			 *        'value' => ['GR', 'UK', 'USA', 'DE'],
			 *    ],
			 *    'device' => [
			 *        'value' => ['desktop', 'tablet'],
			 *    ],
			 *    'event' => [
			 *        'value' => ['close'],
			 *    ],
			 *    'page' => [
			 * 		  'type' => 'contains', // contains, not_contains, equals
			 *        'value' => ['/about', 'fireplugins'],
			 *    ],
			 *    'referrer' => [
			 * 		  'type' => 'contains', // contains, not_contains, equals
			 *        'value' => ['google.com', 'facebook.com'],
			 *    ]
			 * ]
			 * 
			 * Output:
			 * 50
			 */

			$class->onAfterGetData($metric_data);
		}
		
		return $data;
	}
}
```
