PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.0
Independent Analytics – WordPress Analytics Plugin v2.15.0
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Statistics / Statistic.php
independent-analytics / IAWP / Statistics Last commit date
Intervals 5 months ago Campaign_Landing_Page_Statistics.php 9 months ago Campaign_Statistics.php 2 years ago Campaign_UTM_Campaign_Statistics.php 9 months ago Campaign_UTM_Medium_Statistics.php 9 months ago Campaign_UTM_Source_Statistics.php 9 months ago City_Statistics.php 2 years ago Click_Statistics.php 5 months ago Country_Statistics.php 2 years ago Device_Browser_Statistics.php 2 years ago Device_OS_Statistics.php 2 years ago Device_Type_Statistics.php 2 years ago Journey_Statistics.php 6 months ago Page_Statistics.php 2 years ago Referrer_Statistics.php 2 years ago Referrer_Type_Statistics.php 9 months ago Statistic.php 3 months ago Statistics.php 5 days ago
Statistic.php
177 lines
1 <?php
2
3 namespace IAWP\Statistics;
4
5 use IAWP\Capability_Manager;
6 use IAWP\Dashboard_Options;
7 use IAWP\Plugin_Group_Option;
8 use IAWP\Utils\Currency;
9 use IAWP\Utils\Number_Formatter;
10 /** @internal */
11 class Statistic implements Plugin_Group_Option
12 {
13 private $id;
14 private $name;
15 private $plugin_group;
16 private $plugin_group_header;
17 private $icon;
18 private $statistic;
19 private $previous_period_statistic;
20 private $unfiltered_statistic;
21 private $statistic_over_time;
22 private $is_visible_in_dashboard_widget;
23 private $is_invisible;
24 private $format;
25 private $is_growth_good;
26 private $is_subgroup_plugin_enabled;
27 private $requires_pro;
28 public function __construct(array $attributes)
29 {
30 $this->id = $attributes['id'];
31 $this->name = $attributes['name'];
32 $this->plugin_group = $attributes['plugin_group'];
33 $this->plugin_group_header = $attributes['plugin_group_header'] ?? null;
34 $this->icon = $attributes['icon'] ?? null;
35 $this->statistic = $attributes['statistic'] ?? 0;
36 $this->previous_period_statistic = $attributes['previous_period_statistic'] ?? 0;
37 $this->unfiltered_statistic = $attributes['unfiltered_statistic'] ?? null;
38 $this->statistic_over_time = $attributes['statistic_over_time'] ?? [];
39 $this->is_visible_in_dashboard_widget = $attributes['is_visible_in_dashboard_widget'] ?? \false;
40 $this->is_invisible = $attributes['is_invisible'] ?? \false;
41 $this->format = $attributes['format'] ?? null;
42 $this->is_growth_good = $attributes['is_growth_good'] ?? \true;
43 $this->is_subgroup_plugin_enabled = $attributes['is_subgroup_plugin_active'] ?? \true;
44 $this->requires_pro = $attributes['requires_pro'] ?? \false;
45 }
46 public function is_enabled() : bool
47 {
48 if ($this->requires_pro === \true && \IAWPSCOPED\iawp_is_free()) {
49 return \false;
50 }
51 return \true;
52 }
53 public function id() : string
54 {
55 return $this->id;
56 }
57 public function name() : string
58 {
59 return $this->name;
60 }
61 public function icon() : ?string
62 {
63 return $this->icon;
64 }
65 public function plugin_group() : string
66 {
67 return $this->plugin_group;
68 }
69 public function plugin_group_header() : ?string
70 {
71 return $this->plugin_group_header;
72 }
73 public function is_visible_in_dashboard_widget() : bool
74 {
75 return $this->is_visible_in_dashboard_widget;
76 }
77 public function is_invisible() : bool
78 {
79 return $this->is_invisible;
80 }
81 public function statistic_over_time() : array
82 {
83 return $this->statistic_over_time;
84 }
85 public function is_group_plugin_enabled() : bool
86 {
87 switch ($this->plugin_group) {
88 case "ecommerce":
89 return \IAWPSCOPED\iawp()->is_ecommerce_support_enabled();
90 case "forms":
91 return \IAWPSCOPED\iawp()->is_form_submission_support_enabled() && (\get_current_user_id() === 0 || Capability_Manager::can_view_all_analytics());
92 default:
93 return \true;
94 }
95 }
96 public function is_subgroup_plugin_enabled() : bool
97 {
98 return $this->is_subgroup_plugin_enabled;
99 }
100 public function is_visible() : bool
101 {
102 $options = Dashboard_Options::getInstance();
103 return \in_array($this->id(), $options->visible_quick_stats());
104 }
105 public function is_member_of_plugin_group(string $plugin_group) : bool
106 {
107 return $this->plugin_group === $plugin_group;
108 }
109 public function formatted_value() : string
110 {
111 return $this->format_value($this->statistic);
112 }
113 public function value()
114 {
115 return $this->statistic;
116 }
117 public function formatted_unfiltered_value() : ?string
118 {
119 if (\is_null($this->unfiltered_statistic)) {
120 return null;
121 }
122 return $this->format_value($this->unfiltered_statistic);
123 }
124 /**
125 * Growth can be good or bad depending on the quick stat. This allows it to be calculated on a
126 * at the individual quick stat level.
127 *
128 * The default behavior is "up" and "good" so you can tweak either of those as needed
129 *
130 * @return string
131 */
132 public function growth_html_class() : string
133 {
134 $html_classes = [];
135 $has_growth = $this->growth() >= 0;
136 if (!$has_growth) {
137 $html_classes[] = 'down';
138 }
139 if ($has_growth && !$this->is_growth_good || !$has_growth && $this->is_growth_good) {
140 $html_classes[] = 'bad';
141 }
142 return \implode(' ', $html_classes);
143 }
144 public function formatted_growth() : string
145 {
146 $growth = $this->growth();
147 return Number_Formatter::percent(\absint($growth));
148 }
149 public function growth()
150 {
151 if ($this->statistic == 0 && $this->previous_period_statistic != 0) {
152 return -100;
153 } elseif ($this->statistic == 0 || $this->previous_period_statistic == 0) {
154 return 0;
155 }
156 $percent_growth = ($this->statistic / $this->previous_period_statistic - 1) * 100;
157 return \round($percent_growth, 0);
158 }
159 public function format_value($value) : string
160 {
161 switch ($this->format) {
162 case 'time':
163 return Number_Formatter::second_to_minute_timestamp($value);
164 case 'percent':
165 return Number_Formatter::percent($value, 2);
166 case 'decimal':
167 return Number_Formatter::decimal($value, 2);
168 case 'currency':
169 return Currency::format($value, \false);
170 case 'rounded-currency':
171 return Currency::format($value, \true);
172 default:
173 return Number_Formatter::integer($value);
174 }
175 }
176 }
177