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