Changeset 3437524
- Timestamp:
- 01/12/2026 09:47:48 AM (2 months ago)
- Location:
- digi-report/trunk
- Files:
-
- 2 edited
-
digi-report.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digi-report/trunk/digi-report.php
r3437504 r3437524 3 3 Plugin Name: Digi Report 4 4 Description: A plugin that generates and sends WordPress maintenance reports via email (Integrated with Independent Analytics). 5 Version: 2.8. 15 Version: 2.8.2 6 6 Author: DigiPerforma - Marketing Digital [digiperforma.com.br] 7 7 License: GPLv2 or later … … 98 98 </div> 99 99 100 <?php if (empty($analytics['top_pages'])): ?>101 <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;">102 <p><strong>Fase Final - Mapeamento de Tabelas:</strong></p>103 <p>Ótimo! Os totais já devem estar aparecendo. Copie os dados abaixo para ativarmos os "Top Páginas" e "Top Cidades":</p>104 <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 300px; overflow: auto;">105 <strong>Tabela Resources (Páginas):</strong><br>106 <?php digi_print_columns($analytics['debug_table_resources']); ?>107 <br>108 <strong>Tabela Cities (Cidades):</strong><br>109 <?php digi_print_columns($analytics['debug_table_cities']); ?>110 </div>111 </div>112 <?php endif; ?>113 114 <?php if (!empty($analytics['top_pages'])): ?>115 100 <div class="digi-card-row"> 116 101 <div class="digi-card" style="text-align: left;"> 117 102 <h3>Top Páginas</h3> 118 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 119 <?php foreach($analytics['top_pages'] as $page) echo "<li>" . esc_html($page['name']) . " <strong>(" . esc_html($page['views']) . ")</strong></li>"; ?> 120 </ul> 103 <?php if (!empty($analytics['top_pages'])): ?> 104 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 105 <?php foreach($analytics['top_pages'] as $page) echo "<li>" . esc_html($page['name']) . " <strong>(" . esc_html($page['views']) . ")</strong></li>"; ?> 106 </ul> 107 <?php else: ?> 108 <p style="font-size: 0.9em; font-weight: normal; color: #999;">Sem dados suficientes</p> 109 <?php endif; ?> 121 110 </div> 122 111 <div class="digi-card" style="text-align: left;"> 123 112 <h3>Top Cidades</h3> 124 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 125 <?php foreach($analytics['top_cities'] as $city) echo "<li>" . esc_html($city['city']) . " <strong>(" . esc_html($city['visitors']) . ")</strong></li>"; ?> 126 </ul> 113 <?php if (!empty($analytics['top_cities'])): ?> 114 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 115 <?php foreach($analytics['top_cities'] as $city) echo "<li>" . esc_html($city['city']) . " <strong>(" . esc_html($city['visitors']) . ")</strong></li>"; ?> 116 </ul> 117 <?php else: ?> 118 <p style="font-size: 0.9em; font-weight: normal; color: #999;">Sem dados suficientes</p> 119 <?php endif; ?> 127 120 </div> 128 121 </div> 129 <?php endif; ?>130 122 131 123 <?php else: ?> 132 124 <div class="notice notice-warning inline" style="display:block;"> 133 <p><strong>Status do Analytics:</strong> Não detectado. </p>125 <p><strong>Status do Analytics:</strong> Não detectado. Certifique-se de que o plugin <em>Independent Analytics</em> está ativo.</p> 134 126 </div> 135 127 <?php endif; ?> … … 155 147 } 156 148 157 function digi_print_columns($table_name) { 158 global $wpdb; 159 $cols = $wpdb->get_results("SHOW COLUMNS FROM $table_name"); 160 if ($cols) { 161 echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">'; 162 foreach ($cols as $col) echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>'; 163 echo '</ul>'; 164 } else { 165 echo 'Tabela não encontrada ou vazia.'; 166 } 167 } 168 169 // ========================================================= 170 // 2. FUNÇÃO: VISITANTES CORRIGIDO + MAPEAMENTO 149 // ========================================================= 150 // 2. FUNÇÃO: COLETA DE DADOS COMPLETA (FINAL) 171 151 // ========================================================= 172 152 function digi_report_get_analytics_data() { 173 153 global $wpdb; 174 154 175 // NOMES DAS TABELAS 176 $table_views = $wpdb->prefix . 'independent_analytics_views'; 177 $table_sessions = $wpdb->prefix . 'independent_analytics_sessions'; 178 // Tabelas Auxiliares (Adivinhando nomes padrão para debug) 155 // DEFINIÇÃO DAS TABELAS 156 $table_views = $wpdb->prefix . 'independent_analytics_views'; 157 $table_sessions = $wpdb->prefix . 'independent_analytics_sessions'; 179 158 $table_resources = $wpdb->prefix . 'independent_analytics_resources'; 180 $table_cities = $wpdb->prefix . 'independent_analytics_cities';159 $table_cities = $wpdb->prefix . 'independent_analytics_cities'; 181 160 182 161 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); 183 162 $end_date = date('Y-m-d H:i:s'); 184 163 164 // Verifica se a tabela principal existe 185 165 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 186 166 return array('active' => false); 187 167 } 188 168 189 // 1. VISUALIZAÇÕES (OK - viewed_at)169 // 1. VISUALIZAÇÕES 190 170 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `viewed_at` BETWEEN %s AND %s", $start_date, $end_date)); 191 171 192 // 2. VISITANTES (CORRIGIDO - created_at)172 // 2. VISITANTES 193 173 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `created_at` BETWEEN %s AND %s", $start_date, $end_date)); 194 174 195 // TOP PÁGINAS E CIDADES (Desativados, aguardando nomes das colunas) 175 // 3. TOP PÁGINAS (JOIN com Resources) 176 // Traz o 'cached_title' como nome. Se não tiver título, usa 'resource' (url). 177 $query_pages = $wpdb->prepare(" 178 SELECT 179 COALESCE(NULLIF(r.cached_title, ''), r.resource) as name, 180 COUNT(*) as views 181 FROM $table_views v 182 JOIN $table_resources r ON v.resource_id = r.id 183 WHERE v.viewed_at BETWEEN %s AND %s 184 GROUP BY r.id 185 ORDER BY views DESC 186 LIMIT 3 187 ", $start_date, $end_date); 196 188 189 $top_pages = $wpdb->get_results($query_pages, ARRAY_A); 190 191 // 4. TOP CIDADES (JOIN com Cities) 192 $query_cities = $wpdb->prepare(" 193 SELECT 194 c.city, 195 COUNT(*) as visitors 196 FROM $table_sessions s 197 JOIN $table_cities c ON s.city_id = c.city_id 198 WHERE s.created_at BETWEEN %s AND %s 199 AND c.city != '' 200 GROUP BY c.city_id 201 ORDER BY visitors DESC 202 LIMIT 3 203 ", $start_date, $end_date); 204 205 $top_cities = $wpdb->get_results($query_cities, ARRAY_A); 206 197 207 return array( 198 208 'active' => true, 199 209 'views' => number_format_i18n((int)$views), 200 210 'visitors' => number_format_i18n((int)$visitors), 201 'top_pages' => array(), 202 'top_cities' => array(), 203 // Debug para próxima fase 204 'debug_table_resources' => $table_resources, 205 'debug_table_cities' => $table_cities 211 'top_pages' => $top_pages ?: array(), 212 'top_cities' => $top_cities ?: array() 206 213 ); 207 214 } … … 237 244 $html_analytics = ''; 238 245 if ($analytics['active']) { 246 // GERA LISTA DE PÁGINAS 247 $li_pages = ''; 248 if (!empty($analytics['top_pages'])) { 249 foreach($analytics['top_pages'] as $p) $li_pages .= "<li>{$p['name']} <strong>({$p['views']})</strong></li>"; 250 } else { 251 $li_pages = '<li>Sem dados suficientes</li>'; 252 } 253 254 // GERA LISTA DE CIDADES 255 $li_cities = ''; 256 if (!empty($analytics['top_cities'])) { 257 foreach($analytics['top_cities'] as $c) $li_cities .= "<li>{$c['city']} <strong>({$c['visitors']})</strong></li>"; 258 } else { 259 $li_cities = '<li>Sem dados suficientes</li>'; 260 } 261 239 262 $html_analytics = ' 240 263 <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3> … … 254 277 </td> 255 278 </tr> 279 </table> 280 <table style="width: 100%; border-collapse: collapse; margin-top: 10px;"> 281 <tr> 282 <td style="padding: 5px; vertical-align: top; width: 50%;"> 283 <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;"> 284 <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Páginas</div> 285 <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_pages.'</ul> 286 </div> 287 </td> 288 <td style="padding: 5px; vertical-align: top; width: 50%;"> 289 <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;"> 290 <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Cidades</div> 291 <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_cities.'</ul> 292 </div> 293 </td> 294 </tr> 256 295 </table>'; 257 296 } -
digi-report/trunk/readme.txt
r3437504 r3437524 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.8. 16 Stable tag: 2.8.2 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.