Admin_Page.php
2 years ago
Analytics_Page.php
2 years ago
Campaign_Builder_Page.php
2 years ago
Settings_Page.php
2 years ago
Analytics_Page.php
146 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Admin_Page; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Capability_Manager; |
| 6 | use IAWP_SCOPED\IAWP\Chart; |
| 7 | use IAWP_SCOPED\IAWP\Chart_Geo; |
| 8 | use IAWP_SCOPED\IAWP\Dashboard_Options; |
| 9 | use IAWP_SCOPED\IAWP\Env; |
| 10 | use IAWP_SCOPED\IAWP\Plugin_Conflict_Detector; |
| 11 | use IAWP_SCOPED\IAWP\Quick_Stats; |
| 12 | use IAWP_SCOPED\IAWP\Real_Time; |
| 13 | use IAWP_SCOPED\IAWP\Report_Finder; |
| 14 | use IAWP_SCOPED\IAWP\Tables\Table; |
| 15 | use IAWP_SCOPED\IAWP\Tables\Table_Campaigns; |
| 16 | use IAWP_SCOPED\IAWP\Tables\Table_Devices; |
| 17 | use IAWP_SCOPED\IAWP\Tables\Table_Geo; |
| 18 | use IAWP_SCOPED\IAWP\Tables\Table_Pages; |
| 19 | use IAWP_SCOPED\IAWP\Tables\Table_Referrers; |
| 20 | use IAWP_SCOPED\IAWP\Utils\Security; |
| 21 | /** @internal */ |
| 22 | class Analytics_Page extends Admin_Page |
| 23 | { |
| 24 | protected function render_page() |
| 25 | { |
| 26 | $options = new Dashboard_Options(); |
| 27 | $date_rage = $options->get_date_range(); |
| 28 | $date_label = $date_rage->label(); |
| 29 | $columns = $options->columns(); |
| 30 | $tab = (new Env())->get_tab(); |
| 31 | if ($tab === 'views') { |
| 32 | $table = new Table_Pages($columns); |
| 33 | $statistics_class = $table->group()->statistics_class(); |
| 34 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 35 | $stats = new Quick_Stats(null, $statistics); |
| 36 | $chart = new Chart($statistics, $date_label); |
| 37 | $this->interface($table, $stats, $chart); |
| 38 | } elseif ($tab === 'referrers') { |
| 39 | $table = new Table_Referrers($columns); |
| 40 | $statistics_class = $table->group()->statistics_class(); |
| 41 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 42 | $stats = new Quick_Stats(null, $statistics); |
| 43 | $chart = new Chart($statistics, $date_label); |
| 44 | $this->interface($table, $stats, $chart); |
| 45 | } elseif ($tab === 'geo') { |
| 46 | $table = new Table_Geo($columns, $options->group()); |
| 47 | $statistics_class = $table->group()->statistics_class(); |
| 48 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 49 | $stats = new Quick_Stats(null, $statistics); |
| 50 | $table_data_class = $table->group()->rows_class(); |
| 51 | $geo_data = new $table_data_class($date_rage); |
| 52 | $chart = new Chart_Geo($geo_data->rows(), $date_label); |
| 53 | $this->interface($table, $stats, $chart); |
| 54 | } elseif ($tab === 'campaigns') { |
| 55 | $table = new Table_Campaigns($columns); |
| 56 | $statistics_class = $table->group()->statistics_class(); |
| 57 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 58 | $stats = new Quick_Stats(null, $statistics); |
| 59 | $chart = new Chart($statistics, $date_label); |
| 60 | $this->interface($table, $stats, $chart); |
| 61 | } elseif ($tab === 'devices') { |
| 62 | $table = new Table_Devices($columns, $options->group()); |
| 63 | $statistics_class = $table->group()->statistics_class(); |
| 64 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 65 | $stats = new Quick_Stats(null, $statistics); |
| 66 | $chart = new Chart($statistics, $date_label); |
| 67 | $this->interface($table, $stats, $chart); |
| 68 | } elseif ($tab === 'real-time') { |
| 69 | (new Real_Time())->render_real_time_analytics(); |
| 70 | } |
| 71 | } |
| 72 | private function interface(Table $table, $stats, $chart) |
| 73 | { |
| 74 | $options = new Dashboard_Options(); |
| 75 | $sort_configuration = $table->sanitize_sort_parameters($options->sort_column(), $options->sort_direction()); |
| 76 | ?> |
| 77 | <div data-controller="report" |
| 78 | data-report-name-value="<?php |
| 79 | echo Security::string($options->report_name()); |
| 80 | ?>" |
| 81 | data-report-relative-range-id-value="<?php |
| 82 | echo Security::attr($options->relative_range_id()); |
| 83 | ?>" |
| 84 | data-report-exact-start-value="<?php |
| 85 | echo Security::attr($options->start()); |
| 86 | ?>" |
| 87 | data-report-exact-end-value="<?php |
| 88 | echo Security::attr($options->end()); |
| 89 | ?>" |
| 90 | data-report-group-value="<?php |
| 91 | echo Security::attr($options->group()); |
| 92 | ?>" |
| 93 | data-report-filters-value="<?php |
| 94 | \esc_attr_e(Security::json_encode($options->filters())); |
| 95 | ?>" |
| 96 | data-report-chart-interval-value="<?php |
| 97 | echo Security::attr($options->chart_interval()->id()); |
| 98 | ?>" |
| 99 | data-report-sort-column-value="<?php |
| 100 | echo Security::attr($options->sort_column()); |
| 101 | ?>" |
| 102 | data-report-sort-direction-value="<?php |
| 103 | echo Security::attr($options->sort_direction()); |
| 104 | ?>" |
| 105 | data-report-columns-value="<?php |
| 106 | \esc_attr_e(Security::json_encode($table->visible_column_ids())); |
| 107 | ?>" |
| 108 | data-report-visible-datasets-value="<?php |
| 109 | \esc_attr_e(Security::json_encode($options->visible_datasets())); |
| 110 | ?>" |
| 111 | > |
| 112 | <div class="report-header-container"> |
| 113 | <?php |
| 114 | echo \IAWP_SCOPED\iawp_blade()->run('partials.report-header', ['report' => (new Report_Finder())->current(), 'can_edit' => Capability_Manager::can_edit()]); |
| 115 | ?> |
| 116 | <?php |
| 117 | $table->output_toolbar(); |
| 118 | ?> |
| 119 | </div> |
| 120 | <?php |
| 121 | echo $stats->get_html(); |
| 122 | ?> |
| 123 | <?php |
| 124 | echo $chart->get_html($options->visible_datasets()); |
| 125 | ?> |
| 126 | <?php |
| 127 | echo $table->get_table_toolbar_markup(); |
| 128 | ?> |
| 129 | <?php |
| 130 | echo $table->get_table_markup($sort_configuration->column(), $sort_configuration->direction()); |
| 131 | ?> |
| 132 | </div> |
| 133 | <div class="iawp-notices"> |
| 134 | <?php |
| 135 | $plugin_conflict_detector = new Plugin_Conflict_Detector(); |
| 136 | if (!$plugin_conflict_detector->has_conflict()) { |
| 137 | echo \IAWP_SCOPED\iawp_blade()->run('settings.notice', ['notice_text' => $plugin_conflict_detector->get_error(), 'button_text' => \false, 'notice' => 'iawp-error', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']); |
| 138 | } |
| 139 | if (\get_option('iawp_need_clear_cache')) { |
| 140 | echo \IAWP_SCOPED\iawp_blade()->run('settings.notice', ['notice_text' => \__('Please clear your cache to ensure tracking works properly.', 'independent-analytics'), 'button_text' => \__('I\'ve cleared the cache', 'independent-analytics'), 'notice' => 'iawp-warning', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']); |
| 141 | } |
| 142 | ?> |
| 143 | </div><?php |
| 144 | } |
| 145 | } |
| 146 |