Admin_Page.php
1 year ago
Analytics_Page.php
1 year ago
Campaign_Builder_Page.php
2 years ago
Settings_Page.php
2 years ago
Support_Page.php
1 year ago
Updates_Page.php
1 year ago
Analytics_Page.php
164 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 = Dashboard_Options::getInstance(); |
| 28 | $date_rage = $options->get_date_range(); |
| 29 | $tab = (new Env())->get_tab(); |
| 30 | if ($tab === 'views') { |
| 31 | $table = new Table_Pages(); |
| 32 | $statistics_class = $table->group()->statistics_class(); |
| 33 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 34 | $stats = new Quick_Stats($statistics); |
| 35 | $chart = new Chart($statistics); |
| 36 | $this->interface($table, $stats, $chart); |
| 37 | } elseif ($tab === 'referrers') { |
| 38 | $table = new Table_Referrers(); |
| 39 | $statistics_class = $table->group()->statistics_class(); |
| 40 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 41 | $stats = new Quick_Stats($statistics); |
| 42 | $chart = new Chart($statistics); |
| 43 | $this->interface($table, $stats, $chart); |
| 44 | } elseif ($tab === 'geo') { |
| 45 | $table = new Table_Geo($options->group()); |
| 46 | $statistics_class = $table->group()->statistics_class(); |
| 47 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 48 | $stats = new Quick_Stats($statistics); |
| 49 | $table_data_class = $table->group()->rows_class(); |
| 50 | $geo_data = new $table_data_class($date_rage); |
| 51 | $chart = new Chart_Geo($geo_data->rows()); |
| 52 | $this->interface($table, $stats, $chart); |
| 53 | } elseif ($tab === 'campaigns') { |
| 54 | $table = new Table_Campaigns(); |
| 55 | $statistics_class = $table->group()->statistics_class(); |
| 56 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 57 | $stats = new Quick_Stats($statistics); |
| 58 | $chart = new Chart($statistics); |
| 59 | $this->interface($table, $stats, $chart); |
| 60 | } elseif ($tab === 'devices') { |
| 61 | $table = new Table_Devices($options->group()); |
| 62 | $statistics_class = $table->group()->statistics_class(); |
| 63 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 64 | $stats = new Quick_Stats($statistics); |
| 65 | $chart = new Chart($statistics); |
| 66 | $this->interface($table, $stats, $chart); |
| 67 | } elseif ($tab === 'real-time') { |
| 68 | (new Real_Time())->render_real_time_analytics(); |
| 69 | } |
| 70 | } |
| 71 | private function interface(Table $table, $stats, $chart) |
| 72 | { |
| 73 | $options = Dashboard_Options::getInstance(); |
| 74 | $sort_configuration = $table->sanitize_sort_parameters($options->sort_column(), $options->sort_direction()); |
| 75 | ?> |
| 76 | <div data-controller="report" |
| 77 | data-report-name-value="<?php |
| 78 | echo Security::string($options->report_name()); |
| 79 | ?>" |
| 80 | data-report-relative-range-id-value="<?php |
| 81 | echo Security::attr($options->relative_range_id()); |
| 82 | ?>" |
| 83 | data-report-exact-start-value="<?php |
| 84 | echo Security::attr($options->start()); |
| 85 | ?>" |
| 86 | data-report-exact-end-value="<?php |
| 87 | echo Security::attr($options->end()); |
| 88 | ?>" |
| 89 | data-report-group-value="<?php |
| 90 | echo Security::attr($options->group()); |
| 91 | ?>" |
| 92 | data-report-filters-value="<?php |
| 93 | echo \esc_attr(Security::json_encode($options->filters())); |
| 94 | ?>" |
| 95 | data-report-chart-interval-value="<?php |
| 96 | echo Security::attr($options->chart_interval()->id()); |
| 97 | ?>" |
| 98 | data-report-sort-column-value="<?php |
| 99 | echo Security::attr($options->sort_column()); |
| 100 | ?>" |
| 101 | data-report-sort-direction-value="<?php |
| 102 | echo Security::attr($options->sort_direction()); |
| 103 | ?>" |
| 104 | data-report-columns-value="<?php |
| 105 | echo \esc_attr(Security::json_encode($table->visible_column_ids())); |
| 106 | ?>" |
| 107 | data-report-quick-stats-value="<?php |
| 108 | echo \esc_attr(Security::json_encode($options->visible_quick_stats())); |
| 109 | ?>" |
| 110 | data-report-primary-chart-metric-id-value="<?php |
| 111 | echo \esc_attr($options->primary_chart_metric_id()); |
| 112 | ?>" |
| 113 | data-report-secondary-chart-metric-id-value="<?php |
| 114 | echo \esc_attr($options->secondary_chart_metric_id()); |
| 115 | ?>" |
| 116 | > |
| 117 | <div id="report-header-container" class="report-header-container"> |
| 118 | <?php |
| 119 | echo \IAWPSCOPED\iawp_blade()->run('partials.report-header', ['report' => (new Report_Finder())->current(), 'can_edit' => Capability_Manager::can_edit()]); |
| 120 | ?> |
| 121 | <?php |
| 122 | $table->output_report_toolbar(); |
| 123 | ?> |
| 124 | <div class="modal-background"></div> |
| 125 | </div> |
| 126 | <?php |
| 127 | echo $stats->get_html(); |
| 128 | ?> |
| 129 | <?php |
| 130 | echo $chart->get_html(); |
| 131 | ?> |
| 132 | <?php |
| 133 | echo $table->get_table_toolbar_markup(); |
| 134 | ?> |
| 135 | <?php |
| 136 | echo $table->get_table_markup($sort_configuration->column(), $sort_configuration->direction()); |
| 137 | ?> |
| 138 | </div> |
| 139 | <?php |
| 140 | if (Env::get_tab() === 'geo') { |
| 141 | echo '<div class="geo-ip-attribution">'; |
| 142 | echo \esc_html_x('Geolocation data powered by', 'Following text is a noun: DB-IP', 'independent-analytics') . ' ' . '<a href="https://db-ip.com" target="_blank">DB-IP</a>.'; |
| 143 | echo '</div>'; |
| 144 | } |
| 145 | ?> |
| 146 | <div class="iawp-notices"> |
| 147 | <?php |
| 148 | if (Capability_Manager::can_edit()) { |
| 149 | $plugin_conflict_detector = new Plugin_Conflict_Detector(); |
| 150 | if (!$plugin_conflict_detector->has_conflict()) { |
| 151 | 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/']); |
| 152 | } |
| 153 | if (\get_option('iawp_need_clear_cache')) { |
| 154 | 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/']); |
| 155 | } |
| 156 | if (\IAWPSCOPED\iawp_db_version() > 0 && !Database::has_correct_database_privileges()) { |
| 157 | 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/']); |
| 158 | } |
| 159 | } |
| 160 | ?> |
| 161 | </div><?php |
| 162 | } |
| 163 | } |
| 164 |