AJAX
3 months ago
Admin_Page
3 months ago
Click_Tracking
5 months ago
ColumnOptions
6 months ago
Cron
9 months ago
Custom_WordPress_Columns
8 months ago
Data_Pruning
5 months ago
Date_Picker
3 months ago
Date_Range
5 months ago
Ecommerce
5 months ago
Email_Reports
3 months ago
Examiner
3 months ago
Favicon
5 months ago
Form_Submissions
5 months ago
Integrations
3 months ago
Interval
1 year ago
Journey
5 months ago
Migrations
5 months ago
Models
5 months ago
Overview
3 months ago
Public_API
5 months ago
Rows
3 months ago
Statistics
3 months ago
Tables
3 months ago
Utils
5 months ago
Views
5 months ago
WooCommerceOrderMetaBox
5 months ago
ActivationLifecycle.php
3 months ago
Admin_Bar_Stats.php
3 months ago
Appearance.php
1 year ago
Campaign_Builder.php
3 months ago
Capability_Manager.php
3 months ago
Chart.php
3 months ago
Chart_Data.php
1 year ago
Click_Tracking.php
3 months ago
ComplianzIntegration.php
3 months ago
Cron_Job.php
5 months ago
Cron_Manager.php
5 months ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
6 months ago
Dashboard_Widget.php
2 years ago
Database.php
8 months ago
Database_Manager.php
5 months ago
Empty_Report_Option.php
2 years ago
Env.php
6 months ago
Examiner_Config.php
11 months ago
FetchFaviconsJob.php
5 months ago
Filters.php
3 months ago
Geo_Database_Health_Check_Job.php
9 months ago
Geo_Database_Manager.php
6 months ago
Geoposition.php
1 year ago
Icon_Directory.php
6 months ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
10 months ago
Independent_Analytics.php
5 months ago
Interrupt.php
3 months ago
Known_Referrers.php
6 months ago
MainWP.php
1 year ago
Map.php
9 months ago
Map_Data.php
1 year ago
Migration_Fixer_Job.php
5 months ago
Patch.php
1 year ago
Payload_Validator.php
9 months ago
Plugin_Conflict_Detector.php
6 months ago
Plugin_Group.php
6 months ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
3 months ago
Quick_Stats.php
3 months ago
REST_API.php
3 months ago
Real_Time.php
3 months ago
Report.php
1 year ago
Report_Finder.php
6 months ago
Report_Options_Parser.php
9 months ago
Resource_Identifier.php
9 months ago
Settings.php
3 months ago
Sort_Configuration.php
9 months ago
Tables.php
8 months ago
Track_Resource_Changes.php
1 year ago
View_Counter.php
6 months ago
Views_Over_Time_Finder.php
1 year ago
VisitorSaltRefreshInterval.php
6 months ago
WP_Option_Cache_Bust.php
2 years ago
Report.php
121 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Form_Submissions\Form; |
| 6 | use IAWP\Statistics\Statistic; |
| 7 | use IAWP\Tables\Columns\Column; |
| 8 | use IAWP\Tables\Table; |
| 9 | use IAWPSCOPED\Illuminate\Support\Collection; |
| 10 | /** @internal */ |
| 11 | class Report |
| 12 | { |
| 13 | private $attributes; |
| 14 | public function __construct(object $attributes) |
| 15 | { |
| 16 | $this->attributes = $attributes; |
| 17 | // Convert string report ids to integers if the string is just numbers |
| 18 | if (\is_string($this->attributes->report_id) && \ctype_digit($this->attributes->report_id)) { |
| 19 | $this->attributes->report_id = \intval($this->attributes->report_id); |
| 20 | } |
| 21 | } |
| 22 | /** |
| 23 | * Will return an int for saved reports and a string for base reports |
| 24 | * |
| 25 | * @return int|string |
| 26 | */ |
| 27 | public function id() |
| 28 | { |
| 29 | return $this->attributes->report_id; |
| 30 | } |
| 31 | public function type() : string |
| 32 | { |
| 33 | return $this->attributes->type; |
| 34 | } |
| 35 | public function type_label() : string |
| 36 | { |
| 37 | $labels = ['overview' => \__('Overview', 'independent-analytics'), 'real-time' => \__('Real-Time', 'independent-analytics'), 'views' => \__('Pages', 'independent-analytics'), 'referrers' => \__('Referrers', 'independent-analytics'), 'geo' => \__('Geo', 'independent-analytics'), 'devices' => \__('Devices', 'independent-analytics'), 'campaigns' => \__('Campaigns', 'independent-analytics'), 'clicks' => \__('Clicks', 'independent-analytics')]; |
| 38 | return $labels[$this->type()] ?? 'Report'; |
| 39 | } |
| 40 | public function name() : string |
| 41 | { |
| 42 | return $this->attributes->name; |
| 43 | } |
| 44 | public function group_name() : ?string |
| 45 | { |
| 46 | return $this->attributes->group_name ?? null; |
| 47 | } |
| 48 | public function url() : string |
| 49 | { |
| 50 | if (!$this->is_saved_report()) { |
| 51 | return \IAWPSCOPED\iawp_dashboard_url(['tab' => $this->attributes->type]); |
| 52 | } |
| 53 | return \IAWPSCOPED\iawp_dashboard_url(['tab' => $this->attributes->type, 'report' => $this->attributes->report_id]); |
| 54 | } |
| 55 | public function is_saved_report() : bool |
| 56 | { |
| 57 | return \is_int($this->id()); |
| 58 | } |
| 59 | public function filters() : ?array |
| 60 | { |
| 61 | $array = (array) $this->attributes; |
| 62 | if (\array_key_exists('filters', $array) && \is_string($array['filters'])) { |
| 63 | $filters = \json_decode($array['filters'], \true); |
| 64 | if (\false !== $filters && \is_array($filters)) { |
| 65 | return $filters; |
| 66 | } |
| 67 | } |
| 68 | return null; |
| 69 | } |
| 70 | public function has_filters() : bool |
| 71 | { |
| 72 | return \is_array($this->filters()) && \count($this->filters()) > 0; |
| 73 | } |
| 74 | public function is_current() : bool |
| 75 | { |
| 76 | return (new \IAWP\Env())->is_currently_viewed($this->is_saved_report() ? $this->id() : $this->type()); |
| 77 | } |
| 78 | public function is_favorite() : bool |
| 79 | { |
| 80 | return (new \IAWP\Env())->is_favorite($this->is_saved_report() ? $this->id() : $this->type()); |
| 81 | } |
| 82 | public function to_array() : array |
| 83 | { |
| 84 | $array = (array) $this->attributes; |
| 85 | if (\array_key_exists('columns', $array) && !\is_null($array['columns'])) { |
| 86 | $array['columns'] = \json_decode($array['columns'], \true); |
| 87 | } |
| 88 | if (\array_key_exists('filters', $array) && !\is_null($array['filters'])) { |
| 89 | $array['filters'] = \json_decode($array['filters'], \true); |
| 90 | } |
| 91 | return $array; |
| 92 | } |
| 93 | /** |
| 94 | * @return Column[] |
| 95 | */ |
| 96 | public function get_supported_columns() : array |
| 97 | { |
| 98 | /** @var Table $table_class */ |
| 99 | $table_class = \IAWP\Env::get_table($this->type()); |
| 100 | $table = new $table_class($this->group_name()); |
| 101 | return \array_values($table->get_columns()); |
| 102 | } |
| 103 | public function get_supported_statistics() : array |
| 104 | { |
| 105 | $statistics = [new Statistic(['id' => 'visitors', 'name' => \__('Visitors', 'independent-analytics'), 'plugin_group' => 'general', 'is_visible_in_dashboard_widget' => \true]), new Statistic(['id' => 'views', 'name' => \__('Views', 'independent-analytics'), 'plugin_group' => 'general', 'is_visible_in_dashboard_widget' => \true]), new Statistic(['id' => 'sessions', 'name' => \__('Sessions', 'independent-analytics'), 'plugin_group' => 'general']), new Statistic(['id' => 'average_session_duration', 'name' => \__('Average Session Duration', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'time']), new Statistic(['id' => 'bounce_rate', 'name' => \__('Bounce Rate', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'percent', 'is_growth_good' => \false]), new Statistic(['id' => 'views_per_session', 'name' => \__('Views Per Session', 'independent-analytics'), 'plugin_group' => 'general', 'format' => 'decimal']), new Statistic(['id' => 'clicks', 'name' => \__('Clicks', 'independent-analytics'), 'plugin_group' => 'general', 'requires_pro' => \true]), new Statistic(['id' => 'wc_orders', 'name' => \__('Orders', 'independent-analytics'), 'plugin_group' => 'ecommerce']), new Statistic(['id' => 'wc_gross_sales', 'name' => \__('Gross Sales', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'rounded-currency']), new Statistic(['id' => 'wc_refunds', 'name' => \__('Refunds', 'independent-analytics'), 'plugin_group' => 'ecommerce']), new Statistic(['id' => 'wc_refunded_amount', 'name' => \__('Refunded Amount', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'rounded-currency']), new Statistic(['id' => 'wc_net_sales', 'name' => \__('Total Sales', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'rounded-currency']), new Statistic(['id' => 'wc_conversion_rate', 'name' => \__('Conversion Rate', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'percent']), new Statistic(['id' => 'wc_earnings_per_visitor', 'name' => \__('Earnings Per Visitor', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'currency']), new Statistic(['id' => 'wc_average_order_volume', 'name' => \__('Average Order Volume', 'independent-analytics'), 'plugin_group' => 'ecommerce', 'format' => 'rounded-currency']), new Statistic(['id' => 'form_submissions', 'name' => \__('Form Submissions', 'independent-analytics'), 'plugin_group' => 'forms']), new Statistic(['id' => 'form_conversion_rate', 'name' => \__('Form Conversion Rate', 'independent-analytics'), 'plugin_group' => 'forms', 'format' => 'percent'])]; |
| 106 | foreach (Form::get_forms() as $form) { |
| 107 | if (!$form->is_plugin_active()) { |
| 108 | continue; |
| 109 | } |
| 110 | $statistics[] = new Statistic(['id' => 'form_submissions_for_' . $form->id(), 'name' => \sprintf(\_x('%s Submissions', 'Title of the contact form', 'independent-analytics'), $form->title()), 'plugin_group' => 'forms', 'is_subgroup_plugin_active' => $form->is_plugin_active(), 'plugin_group_header' => $form->plugin_name()]); |
| 111 | $statistics[] = new Statistic(['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_subgroup_plugin_active' => $form->is_plugin_active(), 'plugin_group_header' => $form->plugin_name(), 'format' => 'percent']); |
| 112 | } |
| 113 | if ($this->type() === 'clicks') { |
| 114 | $statistics = [new Statistic(['id' => 'clicks', 'name' => \__('Clicks', 'independent-analytics'), 'plugin_group' => 'general'])]; |
| 115 | } |
| 116 | return Collection::make($statistics)->filter(function (Statistic $statistic) { |
| 117 | return $statistic->is_enabled() && $statistic->is_group_plugin_enabled() && $statistic->is_subgroup_plugin_enabled(); |
| 118 | })->values()->all(); |
| 119 | } |
| 120 | } |
| 121 |