AJAX
2 years ago
Admin_Page
2 years ago
Custom_WordPress_Columns
2 years ago
Date_Range
2 years ago
Filter_Lists
2 years ago
Form_Submissions
2 years ago
Interval
2 years ago
Menu_Bar_Stats
2 years ago
Migrations
2 years ago
Models
2 years ago
Public_API
2 years ago
Rows
2 years ago
Statistics
2 years ago
Tables
2 years ago
Utils
2 years ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
2 years ago
Chart.php
2 years ago
Chart_Geo.php
2 years ago
Cron_Manager.php
2 years ago
Current_Traffic_Finder.php
2 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
2 years ago
Database.php
2 years ago
Database_Manager.php
2 years ago
Email_Chart.php
2 years ago
Email_Reports.php
2 years ago
Empty_Report_Option.php
2 years ago
Env.php
2 years ago
Filters.php
2 years ago
Form.php
2 years ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
2 years ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
2 years ago
Independent_Analytics.php
2 years ago
Interrupt.php
2 years ago
Known_Referrers.php
2 years ago
Plugin_Conflict_Detector.php
2 years ago
Plugin_Group.php
2 years ago
Plugin_Group_Option.php
2 years ago
Query.php
2 years ago
Quick_Stat.php
2 years ago
Quick_Stats.php
2 years ago
REST_API.php
2 years ago
Real_Time.php
2 years ago
Report.php
2 years ago
Report_Finder.php
2 years ago
Report_Options_Parser.php
2 years ago
Resource_Identifier.php
2 years ago
Settings.php
2 years ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
2 years ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
WooCommerce_Order.php
2 years ago
WooCommerce_Referrer_Meta_Box.php
2 years ago
Quick_Stats.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Statistics\Statistics; |
| 6 | /** @internal */ |
| 7 | class Quick_Stats |
| 8 | { |
| 9 | private $statistics; |
| 10 | // private $filtered_statistics; |
| 11 | private $unfiltered_statistics; |
| 12 | private $is_dashboard_widget; |
| 13 | /** |
| 14 | * @param ?Statistics $statistics |
| 15 | * @param ?Statistics $unfiltered_statistics |
| 16 | * @param bool $is_dashboard_widget |
| 17 | */ |
| 18 | public function __construct(?Statistics $statistics, Statistics $unfiltered_statistics = null, bool $is_dashboard_widget = \false) |
| 19 | { |
| 20 | $this->statistics = $statistics; |
| 21 | $this->unfiltered_statistics = $unfiltered_statistics; |
| 22 | $this->is_dashboard_widget = $is_dashboard_widget; |
| 23 | } |
| 24 | public function make_quick_stat(array $attributes, array $lookup_information = null) : \IAWP\Quick_Stat |
| 25 | { |
| 26 | $the_statistic_method_name = $attributes['id']; |
| 27 | $has_filters = !\is_null($this->unfiltered_statistics); |
| 28 | if (!\is_null($lookup_information)) { |
| 29 | $the_method_name = $lookup_information[0]; |
| 30 | $the_argument = $lookup_information[1]; |
| 31 | $attributes['statistic'] = $this->statistics->{$the_method_name}($the_argument); |
| 32 | $attributes['unfiltered_statistic'] = $has_filters ? $this->unfiltered_statistics->{$the_method_name}($the_argument) : null; |
| 33 | } else { |
| 34 | $attributes['statistic'] = $this->statistics->{$the_statistic_method_name}(); |
| 35 | $attributes['unfiltered_statistic'] = $has_filters ? $this->unfiltered_statistics->{$the_statistic_method_name}() : null; |
| 36 | } |
| 37 | return new \IAWP\Quick_Stat($attributes); |
| 38 | } |
| 39 | public function get_quick_stats() |
| 40 | { |
| 41 | $quick_stats = [$this->make_quick_stat(['id' => 'visitors', 'name' => \__('Visitors', 'independent-analytics'), 'plugin_group' => 'general', 'is_visible_in_dashboard_widget' => \true]), $this->make_quick_stat(['id' => 'views', 'name' => \__('Views', 'independent-analytics'), 'plugin_group' => 'general', 'is_visible_in_dashboard_widget' => \true]), $this->make_quick_stat(['id' => 'sessions', 'name' => \__('Sessions', 'independent-analytics'), 'plugin_group' => 'general']), $this->make_quick_stat(['id' => 'average_session_duration', 'name' => \__('Average Session Duration', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'time']), $this->make_quick_stat(['id' => 'bounce_rate', 'name' => \__('Bounce Rate', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'percent', 'is_growth_good' => \false]), $this->make_quick_stat(['id' => 'views_per_session', 'name' => \__('Views Per Sessions', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'decimal']), $this->make_quick_stat(['id' => 'wc_orders', 'name' => \__('Orders', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce']), $this->make_quick_stat(['id' => 'wc_gross_sales', 'name' => \__('Gross Sales', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'rounded-currency']), $this->make_quick_stat(['id' => 'wc_refunds', 'name' => \__('Refunds', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce']), $this->make_quick_stat(['id' => 'wc_refunded_amount', 'name' => \__('Refunded Amount', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'rounded-currency']), $this->make_quick_stat(['id' => 'wc_net_sales', 'name' => \__('Net Sales', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'rounded-currency']), $this->make_quick_stat(['id' => 'wc_conversion_rate', 'name' => \__('Conversion Rate', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'percent']), $this->make_quick_stat(['id' => 'wc_earnings_per_visitor', 'name' => \__('Earnings Per Visitor', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'currency']), $this->make_quick_stat(['id' => 'wc_average_order_volume', 'name' => \__('Average Order Volume', 'independent-analytics'), 'plugin_group' => 'woocommerce', 'icon' => 'woocommerce', 'format' => 'rounded-currency']), $this->make_quick_stat(['id' => 'form_submissions', 'name' => \__('Form Submissions', 'independent-analytics'), 'plugin_group' => 'forms']), $this->make_quick_stat(['id' => 'form_conversion_rate', 'name' => \__('Form Conversion Rate', 'independent-analytics'), 'plugin_group' => 'forms', 'format' => 'percent'])]; |
| 42 | foreach (\IAWP\Form::get_forms() as $form) { |
| 43 | if (!$form->is_plugin_active()) { |
| 44 | continue; |
| 45 | } |
| 46 | $quick_stats[] = $this->make_quick_stat(['id' => 'form_submissions_for_' . $form->id(), 'name' => \sprintf(\_x('%s Submissions', 'Title of the contact form', 'independent-analytics'), $form->title()), 'plugin_group' => 'forms', 'is_plugin_active' => $form->is_plugin_active(), 'plugin_group_header' => $form->plugin_name(), 'icon' => $form->icon()], ['form_submissions_for', $form]); |
| 47 | $quick_stats[] = $this->make_quick_stat(['id' => 'form_conversion_rate_for_' . $form->id(), 'name' => \sprintf(\_x('%s Conversion Rate', 'Title of the contact form', 'independent-analytics'), $form->title()), 'plugin_group' => 'forms', 'is_plugin_active' => $form->is_plugin_active(), 'plugin_group_header' => $form->plugin_name(), 'icon' => $form->icon(), 'format' => 'percent'], ['form_conversion_rate_for', $form]); |
| 48 | } |
| 49 | return $quick_stats; |
| 50 | } |
| 51 | public function get_html() |
| 52 | { |
| 53 | $quick_stats = $this->get_quick_stats(); |
| 54 | $visible_quick_stats_count = \count(\array_filter($quick_stats, function (\IAWP\Quick_Stat $quick_stat) : bool { |
| 55 | return $quick_stat->is_visible() && $quick_stat->is_enabled(); |
| 56 | })); |
| 57 | $quick_stats_html_class = "quick-stats total-of-{$visible_quick_stats_count}"; |
| 58 | if (!\is_null($this->unfiltered_statistics)) { |
| 59 | $quick_stats_html_class .= ' filtered'; |
| 60 | } |
| 61 | return \IAWPSCOPED\iawp_blade()->run('quick-stats', ['is_dashboard_widget' => $this->is_dashboard_widget, 'quick_stats_html_class' => $quick_stats_html_class, 'quick_stats' => $quick_stats, 'plugin_groups' => \IAWP\Plugin_Group::get_plugin_groups()]); |
| 62 | } |
| 63 | } |
| 64 |