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