| 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\Metrics; |
| 13 |
|
| 14 |
use FireBox\Core\Analytics\QueryBuilders\ConversionRate\ConversionRateQueryStrategyFactory; |
| 15 |
|
| 16 |
if (!defined('ABSPATH')) |
| 17 |
{ |
| 18 |
exit; // Exit if accessed directly. |
| 19 |
} |
| 20 |
|
| 21 |
class ConversionRate extends Metric |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Get data using strategy pattern |
| 25 |
*/ |
| 26 |
public function getData() |
| 27 |
{ |
| 28 |
$strategy = $this->createQueryStrategy(); |
| 29 |
|
| 30 |
$sql = "SELECT |
| 31 |
{$strategy->getSelect()} |
| 32 |
FROM |
| 33 |
{$this->table_logs} as l |
| 34 |
LEFT JOIN |
| 35 |
{$this->table_details} as bld ON bld.log_id = l.id AND bld.event = 'conversion' |
| 36 |
WHERE |
| 37 |
1 |
| 38 |
{$strategy->getWherePeriod()} |
| 39 |
{$strategy->getWhere()} |
| 40 |
{$strategy->getFilters()} |
| 41 |
{$strategy->getGroupBy()} |
| 42 |
{$strategy->getHaving()} |
| 43 |
{$strategy->getOrderBy()} |
| 44 |
{$strategy->getLimitOffset()} |
| 45 |
"; |
| 46 |
|
| 47 |
$results = $this->executeQuery($sql); |
| 48 |
|
| 49 |
if ($this->type === 'count') |
| 50 |
{ |
| 51 |
return isset($results[0]->total) ? (float) $results[0]->total : 0; |
| 52 |
} |
| 53 |
|
| 54 |
return $results; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Create query strategy for this metric |
| 59 |
*/ |
| 60 |
protected function createQueryStrategy() |
| 61 |
{ |
| 62 |
return ConversionRateQueryStrategyFactory::create($this->type, $this); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Override executeQuery to handle conversion rate calculation properly |
| 67 |
* The base class executeQuery uses get_col() for count type which gets the first column, |
| 68 |
* but we need the 'total' column which contains the conversion rate percentage |
| 69 |
*/ |
| 70 |
protected function executeQuery(string $sql) |
| 71 |
{ |
| 72 |
return $this->wpdb->get_results($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Indicates this class handles timezone conversion in SQL |
| 77 |
*/ |
| 78 |
public function hasTimezoneSQLConversion() |
| 79 |
{ |
| 80 |
return true; |
| 81 |
} |
| 82 |
} |