Plugin Directory

Changeset 3437494


Ignore:
Timestamp:
01/12/2026 09:17:40 AM (2 months ago)
Author:
andre.luiz
Message:

Versao 2.8.0 com correcao de viewed_at e diagnostico de sessoes

Location:
digi-report/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • digi-report/trunk/digi-report.php

    r3436293 r3437494  
    33Plugin Name: Digi Report
    44Description: A plugin that generates and sends WordPress maintenance reports via email (Integrated with Independent Analytics).
    5 Version: 2.7.8
     5Version: 2.8.0
    66Author: DigiPerforma - Marketing Digital [digiperforma.com.br]
    77License: GPLv2 or later
     
    9898            </div>
    9999
    100             <?php if ($analytics['views'] == 0): ?>
     100            <?php if ($analytics['visitors'] == 0): ?>
    101101                <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;">
    102                     <p><strong>Diagnóstico de Colunas (Copie a lista abaixo e me mande):</strong></p>
     102                    <p><strong>Diagnóstico da Tabela de Sessões:</strong></p>
     103                    <p>Precisamos saber o nome da coluna de data da tabela de sessões para contar os visitantes corretamente. Copie a lista abaixo:</p>
    103104                    <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 200px; overflow: auto;">
    104                         <strong>Colunas encontradas na tabela <?php echo esc_html($analytics['debug_table']); ?>:</strong><br>
     105                        <strong>Colunas em <?php echo esc_html($analytics['debug_table_sessions']); ?>:</strong><br>
    105106                        <?php
    106                         if (!empty($analytics['debug_columns'])) {
     107                        if (!empty($analytics['debug_columns_sessions'])) {
    107108                            echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">';
    108                             foreach ($analytics['debug_columns'] as $col) {
     109                            foreach ($analytics['debug_columns_sessions'] as $col) {
    109110                                echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>';
    110111                            }
    111112                            echo '</ul>';
    112113                        } else {
    113                             echo 'Nenhuma coluna listada.';
     114                            echo 'Erro ao ler colunas.';
    114115                        }
    115116                        ?>
     
    118119            <?php endif; ?>
    119120
     121            <?php if (!empty($analytics['top_pages'])): ?>
    120122            <div class="digi-card-row">
    121123                <div class="digi-card" style="text-align: left;">
     
    132134                </div>
    133135            </div>
     136            <?php endif; ?>
    134137
    135138        <?php else: ?>
    136139            <div class="notice notice-warning inline" style="display:block;">
    137140                <p><strong>Status do Analytics:</strong> Não detectado.</p>
    138                 <p>O sistema não encontrou tabelas com o final <code>_independent_analytics_views</code> no banco de dados.</p>
    139141            </div>
    140142        <?php endif; ?>
     
    161163
    162164// =========================================================
    163 // 2. FUNÇÃO: AUTO-DETECÇÃO + LISTA DE COLUNAS
     165// 2. FUNÇÃO: CORREÇÃO V2.0 (VIEWED_AT)
    164166// =========================================================
    165167function digi_report_get_analytics_data() {
    166168    global $wpdb;
    167169
    168     // 1. PROCURA A TABELA CORRETA
    169     $found_views_table = $wpdb->get_var("SHOW TABLES LIKE '%independent_analytics_views'");
    170     $found_sessions_table = $wpdb->get_var("SHOW TABLES LIKE '%independent_analytics_sessions'");
     170    // NOMES DAS TABELAS
     171    $table_views = $wpdb->prefix . 'independent_analytics_views';
     172    $table_sessions = $wpdb->prefix . 'independent_analytics_sessions';
    171173
    172174    // Datas (Últimos 30 dias)
    173     $start_date = date('Y-m-d', strtotime('-30 days'));
    174     $end_date   = date('Y-m-d');
    175 
    176     if (!$found_views_table) {
     175    $start_date = date('Y-m-d H:i:s', strtotime('-30 days'));
     176    $end_date   = date('Y-m-d H:i:s');
     177
     178    // 1. Verifica se tabela views existe
     179    if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) {
    177180        return array('active' => false);
    178181    }
    179182
    180     // --- DEBUG: PEGA AS COLUNAS DA TABELA ---
    181     $columns = $wpdb->get_results("SHOW COLUMNS FROM $found_views_table");
    182     // ----------------------------------------
    183 
    184     // Busca Oficial (Tentando usar 'date' - se falhar vai dar zero)
    185     $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_views_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date));
    186     $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_sessions_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date));
    187 
    188     // Se a busca por data falhou (views=0), vamos tentar pegar sem filtro só pra garantir que o SELECT funciona
    189     // (Lógica removida pra simplificar, vamos focar nas colunas)
    190 
    191     $top_pages = $wpdb->get_results($wpdb->prepare(
    192         "SELECT page_path as name, COUNT(*) as views FROM $found_views_table WHERE `date` BETWEEN %s AND %s GROUP BY page_path ORDER BY views DESC LIMIT 3",
    193         $start_date, $end_date
    194     ), ARRAY_A);
    195 
    196     $top_cities = $wpdb->get_results($wpdb->prepare(
    197         "SELECT city, COUNT(*) as visitors FROM $found_sessions_table WHERE `date` BETWEEN %s AND %s AND city != '' GROUP BY city ORDER BY visitors DESC LIMIT 3",
    198         $start_date, $end_date
    199     ), ARRAY_A);
     183    // 2. BUSCA VISUALIZAÇÕES (Agora usando a coluna CERTA: viewed_at)
     184    $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `viewed_at` BETWEEN %s AND %s", $start_date, $end_date));
     185
     186    // 3. BUSCA VISITANTES (Tentando adivinhar 'start_time', se falhar, retorna 0 e pedimos debug)
     187    // Suprime erro temporariamente para não quebrar o site se a coluna for outra
     188    $wpdb->suppress_errors();
     189    $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `start_time` BETWEEN %s AND %s", $start_date, $end_date));
     190    $wpdb->suppress_errors(false);
     191
     192    // Se falhou (null), tenta pegar colunas para debug
     193    $debug_columns_sessions = array();
     194    if ($visitors === null) {
     195        $visitors = 0;
     196        $debug_columns_sessions = $wpdb->get_results("SHOW COLUMNS FROM $table_sessions");
     197    }
     198
     199    // TOP PÁGINAS E CIDADES DESATIVADOS TEMPORARIAMENTE (Retornam array vazio)
     200    // Motivo: Requer JOIN complexo com novas tabelas (wp_independent_analytics_resources / cities)
     201    // Vamos focar em fazer os totais funcionarem primeiro.
    200202
    201203    return array(
     
    203205        'views' => number_format_i18n((int)$views),
    204206        'visitors' => number_format_i18n((int)$visitors),
    205         'top_pages' => $top_pages ?: array(),
    206         'top_cities' => $top_cities ?: array(),
    207         // Dados de Debug
    208         'debug_table' => $found_views_table,
    209         'debug_columns' => $columns
     207        'top_pages' => array(), // Em breve
     208        'top_cities' => array(), // Em breve
     209        // Debug
     210        'debug_table_sessions' => $table_sessions,
     211        'debug_columns_sessions' => $debug_columns_sessions
    210212    );
    211213}
    212214
    213215// =========================================================
    214 // 3. ENVIO DE E-MAIL (Sem alterações)
     216// 3. ENVIO DE E-MAIL
    215217// =========================================================
    216218function meu_plugin_relatorios_enviar() {
     
    241243    $html_analytics = '';
    242244    if ($analytics['active']) {
    243         $li_pages = '';
    244         foreach($analytics['top_pages'] as $p) $li_pages .= "<li>{$p['name']} <strong>({$p['views']})</strong></li>";
    245         if(empty($li_pages)) $li_pages = '<li>Sem dados suficientes</li>';
    246 
    247         $li_cities = '';
    248         foreach($analytics['top_cities'] as $c) $li_cities .= "<li>{$c['city']} <strong>({$c['visitors']})</strong></li>";
    249         if(empty($li_cities)) $li_cities = '<li>Sem dados suficientes</li>';
    250 
     245        // Layout simplificado (sem Top Pages por enquanto)
    251246        $html_analytics = '
    252247        <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3>
     
    266261                </td>
    267262            </tr>
    268         </table>
    269         <table style="width: 100%; border-collapse: collapse; margin-top: 10px;">
    270             <tr>
    271                 <td style="padding: 5px; vertical-align: top; width: 50%;">
    272                     <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;">
    273                         <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Páginas</div>
    274                         <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_pages.'</ul>
    275                     </div>
    276                 </td>
    277                 <td style="padding: 5px; vertical-align: top; width: 50%;">
    278                     <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;">
    279                         <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Cidades</div>
    280                         <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_cities.'</ul>
    281                     </div>
    282                 </td>
    283             </tr>
    284263        </table>';
    285264    }
     
    331310    }
    332311}
    333 
    334312// Ganchos (Manter iguais)
    335313function meu_plugin_relatorios_agendar() { if (!wp_next_scheduled('meu_plugin_relatorios_gancho')) wp_schedule_event(time(), 'daily', 'meu_plugin_relatorios_gancho'); }
  • digi-report/trunk/readme.txt

    r3436293 r3437494  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.7.8
     6Stable tag: 2.8.0
    77Requires PHP: 7.2
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.