PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / Dimension / ActionDimension.php
matomo / app / core / Plugin / Dimension Last commit date
ActionDimension.php 1 month ago ConversionDimension.php 1 month ago DimensionMetadataProvider.php 1 year ago VisitDimension.php 3 months ago
ActionDimension.php
111 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Plugin\Dimension;
10
11 use Piwik\CacheId;
12 use Piwik\Cache as PiwikCache;
13 use Piwik\Columns\Dimension;
14 use Piwik\Plugin\Manager as PluginManager;
15 use Piwik\Plugin;
16 use Piwik\Tracker\Action;
17 use Piwik\Tracker\Request;
18 use Piwik\Tracker\Visitor;
19 use Exception;
20 /**
21 * Defines a new action dimension that records any information during tracking for each action.
22 *
23 * You can record any action information by implementing one of the following events: {@link onLookupAction()} and
24 * {@link getActionId()} or {@link onNewAction()}. By defining a {@link $columnName} and {@link $columnType} a new
25 * column will be created in the database (table `log_link_visit_action`) automatically and the values you return in
26 * the previous mentioned events will be saved in this column.
27 *
28 * You can create a new dimension using the console command `./console generate:dimension`.
29 *
30 * @api
31 * @since 2.5.0
32 */
33 abstract class ActionDimension extends Dimension
34 {
35 public const INSTALLER_PREFIX = 'log_link_visit_action.';
36 protected $dbTableName = 'log_link_visit_action';
37 protected $category = 'General_Actions';
38 /**
39 * If the value you want to save for your dimension is something like a page title or page url, you usually do not
40 * want to save the raw value over and over again to save bytes in the database. Instead you want to save each value
41 * once in the log_action table and refer to this value by its ID in the log_link_visit_action table. You can do
42 * this by returning an action id in "getActionId()" and by returning a value here. If a value should be ignored
43 * or not persisted just return boolean false. Please note if you return a value here and you implement the event
44 * "onNewAction" the value will be probably overwritten by the other event. So make sure to implement only one of
45 * those.
46 *
47 * @return false|mixed
48 * @api
49 */
50 public function onLookupAction(Request $request, Action $action)
51 {
52 return \false;
53 }
54 /**
55 * An action id. The value returned by the lookup action will be associated with this id in the log_action table.
56 * @return int
57 * @throws Exception in case not implemented
58 */
59 public function getActionId()
60 {
61 throw new Exception('You need to overwrite the getActionId method in case you implement the onLookupAction method in class: ' . get_class($this));
62 }
63 /**
64 * This event is triggered before a new action is logged to the `log_link_visit_action` table. It overwrites any
65 * looked up action so it makes usually no sense to implement both methods but it sometimes does. You can assign
66 * any value to the column or return boolan false in case you do not want to save any value.
67 *
68 * @return mixed|false
69 * @api
70 */
71 public function onNewAction(Request $request, Visitor $visitor, Action $action)
72 {
73 return \false;
74 }
75 /**
76 * Get all action dimensions that are defined by all activated plugins.
77 * @return ActionDimension[]
78 * @ignore
79 */
80 public static function getAllDimensions()
81 {
82 $cacheId = CacheId::pluginAware('ActionDimensions');
83 $cache = PiwikCache::getTransientCache();
84 if (!$cache->contains($cacheId)) {
85 $plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated();
86 $instances = array();
87 foreach ($plugins as $plugin) {
88 foreach (self::getDimensions($plugin) as $instance) {
89 $instances[] = $instance;
90 }
91 }
92 $cache->save($cacheId, $instances);
93 }
94 return $cache->fetch($cacheId);
95 }
96 /**
97 * Get all action dimensions that are defined by the given plugin.
98 * @return ActionDimension[]
99 * @ignore
100 */
101 public static function getDimensions(Plugin $plugin)
102 {
103 $dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\Dimension\\ActionDimension');
104 $instances = array();
105 foreach ($dimensions as $dimension) {
106 $instances[] = new $dimension();
107 }
108 return $instances;
109 }
110 }
111