PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
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 3 months ago ConversionDimension.php 3 months ago DimensionMetadataProvider.php 1 year ago VisitDimension.php 3 months ago
ActionDimension.php
113 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 *
48 * @return false|mixed
49 * @api
50 */
51 public function onLookupAction(Request $request, Action $action)
52 {
53 return \false;
54 }
55 /**
56 * An action id. The value returned by the lookup action will be associated with this id in the log_action table.
57 * @return int
58 * @throws Exception in case not implemented
59 */
60 public function getActionId()
61 {
62 throw new Exception('You need to overwrite the getActionId method in case you implement the onLookupAction method in class: ' . get_class($this));
63 }
64 /**
65 * This event is triggered before a new action is logged to the `log_link_visit_action` table. It overwrites any
66 * looked up action so it makes usually no sense to implement both methods but it sometimes does. You can assign
67 * any value to the column or return boolan false in case you do not want to save any value.
68 *
69 *
70 * @return mixed|false
71 * @api
72 */
73 public function onNewAction(Request $request, Visitor $visitor, Action $action)
74 {
75 return \false;
76 }
77 /**
78 * Get all action dimensions that are defined by all activated plugins.
79 * @return ActionDimension[]
80 * @ignore
81 */
82 public static function getAllDimensions()
83 {
84 $cacheId = CacheId::pluginAware('ActionDimensions');
85 $cache = PiwikCache::getTransientCache();
86 if (!$cache->contains($cacheId)) {
87 $plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated();
88 $instances = array();
89 foreach ($plugins as $plugin) {
90 foreach (self::getDimensions($plugin) as $instance) {
91 $instances[] = $instance;
92 }
93 }
94 $cache->save($cacheId, $instances);
95 }
96 return $cache->fetch($cacheId);
97 }
98 /**
99 * Get all action dimensions that are defined by the given plugin.
100 * @return ActionDimension[]
101 * @ignore
102 */
103 public static function getDimensions(Plugin $plugin)
104 {
105 $dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\Dimension\\ActionDimension');
106 $instances = array();
107 foreach ($dimensions as $dimension) {
108 $instances[] = new $dimension();
109 }
110 return $instances;
111 }
112 }
113