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 / classes / WpMatomo / Report / Metadata.php
matomo / classes / WpMatomo / Report Last commit date
views 3 months ago Data.php 2 months ago Dates.php 1 year ago Metadata.php 1 year ago Renderer.php 2 months ago
Metadata.php
155 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 * @package matomo
8 */
9
10 namespace WpMatomo\Report;
11
12 use Piwik\API\Request;
13 use WpMatomo\Bootstrap;
14 use WpMatomo\Site;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // if accessed directly
18 }
19
20 class Metadata {
21
22 public static $cache_all_reports = [];
23 public static $cache_all_report_pages = [];
24
25 public function get_all_reports() {
26 if ( ! empty( self::$cache_all_reports ) ) {
27 return self::$cache_all_reports;
28 }
29
30 $site = new Site();
31 $idsite = $site->get_current_matomo_site_id();
32
33 $report_dates = new Dates();
34 $report_date = $report_dates->get_date_from_query();
35 [ $period, $date ] = $report_dates->detect_period_and_date( $report_date );
36
37 if ( $idsite ) {
38 Bootstrap::do_bootstrap();
39
40 $all_reports = Request::processRequest(
41 'API.getReportMetadata',
42 [
43 'idSite' => $idsite,
44 'filter_limit' => - 1,
45 'period' => $period,
46 'date' => $date,
47 ]
48 );
49 foreach ( $all_reports as $single_report ) {
50 if ( isset( $single_report['uniqueId'] ) ) {
51 self::$cache_all_reports[ $single_report['uniqueId'] ] = $single_report;
52 }
53 }
54 }
55
56 return self::$cache_all_reports;
57 }
58
59 /**
60 * @internal
61 * tests only
62 */
63 public static function clear_cache() {
64 self::$cache_all_reports = [];
65 self::$cache_all_report_pages = [];
66 }
67
68 public function find_report_by_unique_id( $unique_id ) {
69 if ( Renderer::CUSTOM_UNIQUE_ID_VISITS_OVER_TIME === $unique_id ) {
70 return [
71 'uniqueId' => Renderer::CUSTOM_UNIQUE_ID_VISITS_OVER_TIME,
72 'name' => 'Visits over time',
73 ];
74 }
75 $all_reports = self::get_all_reports();
76
77 if ( isset( $all_reports[ $unique_id ] ) ) {
78 return $all_reports[ $unique_id ];
79 }
80 }
81
82 public function get_all_report_pages() {
83 if ( ! empty( self::$cache_all_report_pages ) ) {
84 return self::$cache_all_report_pages;
85 }
86
87 $site = new Site();
88 $idsite = $site->get_current_matomo_site_id();
89
90 if ( $idsite ) {
91 Bootstrap::do_bootstrap();
92
93 self::$cache_all_report_pages = Request::processRequest(
94 'API.getReportPagesMetadata',
95 [
96 'idSite' => $idsite,
97 'filter_limit' => - 1,
98 ]
99 );
100 }
101
102 return self::$cache_all_report_pages;
103 }
104
105 public function find_report_page_params_by_report_metadata( $report_metadata ) {
106 if ( empty( $report_metadata['module'] )
107 || empty( $report_metadata['action'] ) ) {
108 return [];
109 }
110
111 $report_pages = self::get_all_report_pages();
112
113 foreach ( $report_pages as $report_page ) {
114 if ( ! empty( $report_page['widgets'] ) ) {
115 foreach ( $report_page['widgets'] as $widget ) {
116 if ( ! empty( $widget['module'] ) && $widget['module'] === $report_metadata['module']
117 && ! empty( $widget['action'] ) && $widget['action'] === $report_metadata['action'] ) {
118 return [
119 'category' => $report_page['category']['id'],
120 'subcategory' => $report_page['subcategory']['id'],
121 ];
122 }
123 }
124 }
125 }
126
127 // we can't resolve all automatically since reportId != widgetId and the used action may differe etc...
128 // we're hard coding some manually
129
130 if ( 'Actions_get' === $report_metadata['uniqueId'] ) {
131 return [
132 'category' => 'General_Visitors',
133 'subcategory' => 'General_Overview',
134 ];
135 } elseif ( 'Goals_get' === $report_metadata['uniqueId'] ) {
136 return [
137 'category' => 'Goals_Goals',
138 'subcategory' => 'General_Overview',
139 ];
140 } elseif ( 'Goals_get_idGoal--ecommerceOrder' === $report_metadata['uniqueId'] ) {
141 return [
142 'category' => 'Goals_Ecommerce',
143 'subcategory' => 'General_Overview',
144 ];
145 } elseif ( 'Goals_getItemsName' === $report_metadata['uniqueId'] ) {
146 return [
147 'category' => 'Goals_Ecommerce',
148 'subcategory' => 'Goals_Products',
149 ];
150 }
151
152 return [];
153 }
154 }
155