Jake Vanderwerf
2026-01-22 58e8ae0759ccfa97c478ccae4e0778bdce70966f
inc/managers/UmamiMetrics.php
@@ -37,7 +37,7 @@
        $this->website_id = get_option('jvb_umami_website_id', UMAMI_WEBSITE_ID);
        // Initialize cache manager
        $this->cache = new CacheManager('umami_metrics', DAY_IN_SECONDS);
        $this->cache = CacheManager::for('umami_metrics', DAY_IN_SECONDS);
        // Register hooks
        add_action('jvb_daily_umami_collection', [$this, 'collectDailyData']);
@@ -330,7 +330,7 @@
            );
            // Clear cache for the processed date
            $this->cache->invalidate('metrics_' . $date);
            $this->cache->invalidate();
        } catch (Exception $e) {
            $results['errors'][] = 'Exception during data collection: ' . $e->getMessage();
@@ -1516,56 +1516,54 @@
        $month_data = $this->getUserMetrics($user_id, $month_start, $today);
        // Build quick summary for dashboard
        $summary = [
            'today' => [
                'total_views' => $today_data['totals']['total_views'],
                'profile_views' => $today_data['totals']['profile_views'],
                'favourites' => $today_data['totals']['favourites'],
                'karma' => $today_data['totals']['karma']
            ],
            'yesterday' => [
                'total_views' => $yesterday_data['totals']['total_views'],
                'profile_views' => $yesterday_data['totals']['profile_views'],
                'favourites' => $yesterday_data['totals']['favourites'],
                'karma' => $yesterday_data['totals']['karma']
            ],
            'this_week' => [
                'total_views' => $week_data['totals']['total_views'],
                'profile_views' => $week_data['totals']['profile_views'],
                'favourites' => $week_data['totals']['favourites'],
                'karma' => $week_data['totals']['karma']
            ],
            'this_month' => [
                'total_views' => $month_data['totals']['total_views'],
                'profile_views' => $month_data['totals']['profile_views'],
                'favourites' => $month_data['totals']['favourites'],
                'karma' => $month_data['totals']['karma']
            ],
            'growth' => [
                'day_over_day' => [
                    'total_views' => $this->calculatePercentageChange(
                        $yesterday_data['totals']['total_views'],
                        $today_data['totals']['total_views']
                    ),
                    'profile_views' => $this->calculatePercentageChange(
                        $yesterday_data['totals']['profile_views'],
                        $today_data['totals']['profile_views']
                    ),
                    'favourites' => $this->calculatePercentageChange(
                        $yesterday_data['totals']['favourites'],
                        $today_data['totals']['favourites']
                    ),
                    'karma' => $this->calculateAbsoluteChange(
                        $yesterday_data['totals']['karma'],
                        $today_data['totals']['karma']
                    )
                ]
            ],
            'top_content' => $this->simplifyTopContent($week_data['top_content']),
            'sources' => $week_data['source_breakdown']
        ];
        return $summary;
      return [
         'today' => [
            'total_views' => $today_data['totals']['total_views'],
            'profile_views' => $today_data['totals']['profile_views'],
            'favourites' => $today_data['totals']['favourites'],
            'karma' => $today_data['totals']['karma']
         ],
         'yesterday' => [
            'total_views' => $yesterday_data['totals']['total_views'],
            'profile_views' => $yesterday_data['totals']['profile_views'],
            'favourites' => $yesterday_data['totals']['favourites'],
            'karma' => $yesterday_data['totals']['karma']
         ],
         'this_week' => [
            'total_views' => $week_data['totals']['total_views'],
            'profile_views' => $week_data['totals']['profile_views'],
            'favourites' => $week_data['totals']['favourites'],
            'karma' => $week_data['totals']['karma']
         ],
         'this_month' => [
            'total_views' => $month_data['totals']['total_views'],
            'profile_views' => $month_data['totals']['profile_views'],
            'favourites' => $month_data['totals']['favourites'],
            'karma' => $month_data['totals']['karma']
         ],
         'growth' => [
            'day_over_day' => [
               'total_views' => $this->calculatePercentageChange(
                  $yesterday_data['totals']['total_views'],
                  $today_data['totals']['total_views']
               ),
               'profile_views' => $this->calculatePercentageChange(
                  $yesterday_data['totals']['profile_views'],
                  $today_data['totals']['profile_views']
               ),
               'favourites' => $this->calculatePercentageChange(
                  $yesterday_data['totals']['favourites'],
                  $today_data['totals']['favourites']
               ),
               'karma' => $this->calculateAbsoluteChange(
                  $yesterday_data['totals']['karma'],
                  $today_data['totals']['karma']
               )
            ]
         ],
         'top_content' => $this->simplifyTopContent($week_data['top_content']),
         'sources' => $week_data['source_breakdown']
      ];
    }
    /**