1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugin\Dimension;
use Piwik\CacheId;
use Piwik\Cache as PiwikCache;
use Piwik\Columns\Dimension;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Tracker\Action;
use Piwik\Tracker\GoalManager;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
use Piwik\Plugin;
/**
* Defines a new conversion dimension that records any visit related information during tracking.
*
* You can record any visit information by implementing one of the following events:
* {@link onEcommerceOrderConversion()}, {@link onEcommerceCartUpdateConversion()} or {@link onGoalConversion()}.
* By defining a {@link $columnName} and {@link $columnType} a new column will be created in the database
* (table `log_conversion`) automatically and the values you return in the previous mentioned events will be saved in
* this column.
*
* You can create a new dimension using the console command `./console generate:dimension`.
*
* @api
* @since 2.5.0
*/
abstract class ConversionDimension extends Dimension
{
public const INSTALLER_PREFIX = 'log_conversion.';
protected $dbTableName = 'log_conversion';
protected $category = 'Goals_Conversion';
/**
* Get all conversion dimensions that are defined by all activated plugins.
* @ignore
*/
public static function getAllDimensions()
{
$cacheId = CacheId::pluginAware('ConversionDimensions');
$cache = PiwikCache::getTransientCache();
if (!$cache->contains($cacheId)) {
$plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated();
$instances = array();
foreach ($plugins as $plugin) {
foreach (self::getDimensions($plugin) as $instance) {
$instances[] = $instance;
}
}
$cache->save($cacheId, $instances);
}
return $cache->fetch($cacheId);
}
/**
* Get all conversion dimensions that are defined by the given plugin.
* @return ConversionDimension[]
* @ignore
*/
public static function getDimensions(Plugin $plugin)
{
$dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\Dimension\\ConversionDimension');
$instances = array();
foreach ($dimensions as $dimension) {
$instances[] = new $dimension();
}
return $instances;
}
/**
* This event is triggered when an ecommerce order is converted. Any returned value will be persist in the database.
* Return boolean `false` if you do not want to change the value in some cases.
*
* @param Action|null $action
*
* @return mixed|false
* @api
*/
public function onEcommerceOrderConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
{
return false;
}
/**
* This event is triggered when an ecommerce cart update is converted. Any returned value will be persist in the
* database. Return boolean `false` if you do not want to change the value in some cases.
*
* @param Action|null $action
*
* @return mixed|false
* @api
*/
public function onEcommerceCartUpdateConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
{
return false;
}
/**
* This event is triggered when an any custom goal is converted. Any returned value will be persist in the
* database. Return boolean `false` if you do not want to change the value in some cases.
*
* @param Action|null $action
*
* @return mixed|false
* @api
*/
public function onGoalConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
{
return false;
}
}
|