Plugin Directory

Changeset 3437504


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

Versao 2.8.1 correcao de visitantes

Location:
digi-report/trunk
Files:
2 edited

Legend:

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

    r3437494 r3437504  
    33Plugin Name: Digi Report
    44Description: A plugin that generates and sends WordPress maintenance reports via email (Integrated with Independent Analytics).
    5 Version: 2.8.0
     5Version: 2.8.1
    66Author: DigiPerforma - Marketing Digital [digiperforma.com.br]
    77License: GPLv2 or later
     
    9898            </div>
    9999
    100             <?php if ($analytics['visitors'] == 0): ?>
     100            <?php if (empty($analytics['top_pages'])): ?>
    101101                <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;">
    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>
    104                     <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 200px; overflow: auto;">
    105                         <strong>Colunas em <?php echo esc_html($analytics['debug_table_sessions']); ?>:</strong><br>
    106                         <?php
    107                         if (!empty($analytics['debug_columns_sessions'])) {
    108                             echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">';
    109                             foreach ($analytics['debug_columns_sessions'] as $col) {
    110                                 echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>';
    111                             }
    112                             echo '</ul>';
    113                         } else {
    114                             echo 'Erro ao ler colunas.';
    115                         }
    116                         ?>
     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']); ?>
    117110                    </div>
    118111                </div>
     
    162155}
    163156
    164 // =========================================================
    165 // 2. FUNÇÃO: CORREÇÃO V2.0 (VIEWED_AT)
     157function 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
    166171// =========================================================
    167172function digi_report_get_analytics_data() {
     
    171176    $table_views = $wpdb->prefix . 'independent_analytics_views';
    172177    $table_sessions = $wpdb->prefix . 'independent_analytics_sessions';
    173 
    174     // Datas (Últimos 30 dias)
     178    // Tabelas Auxiliares (Adivinhando nomes padrão para debug)
     179    $table_resources = $wpdb->prefix . 'independent_analytics_resources';
     180    $table_cities = $wpdb->prefix . 'independent_analytics_cities';
     181
    175182    $start_date = date('Y-m-d H:i:s', strtotime('-30 days'));
    176183    $end_date   = date('Y-m-d H:i:s');
    177184
    178     // 1. Verifica se tabela views existe
    179185    if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) {
    180186        return array('active' => false);
    181187    }
    182188
    183     // 2. BUSCA VISUALIZAÇÕES (Agora usando a coluna CERTA: viewed_at)
     189    // 1. VISUALIZAÇÕES (OK - viewed_at)
    184190    $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `viewed_at` BETWEEN %s AND %s", $start_date, $end_date));
    185191
    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.
    202 
     192    // 2. VISITANTES (CORRIGIDO - created_at)
     193    $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `created_at` BETWEEN %s AND %s", $start_date, $end_date));
     194
     195    // TOP PÁGINAS E CIDADES (Desativados, aguardando nomes das colunas)
     196   
    203197    return array(
    204198        'active' => true,
    205199        'views' => number_format_i18n((int)$views),
    206200        'visitors' => number_format_i18n((int)$visitors),
    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
     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
    212206    );
    213207}
     
    243237    $html_analytics = '';
    244238    if ($analytics['active']) {
    245         // Layout simplificado (sem Top Pages por enquanto)
    246239        $html_analytics = '
    247240        <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3>
  • digi-report/trunk/readme.txt

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