Analytics

Analytics Configuration Options

Once you've completed the basic setup, you can customize how Novus integrates with Google Analytics using various configuration options. This guide explains all available settings and how to use them effectively.

Core Configuration Options

These are the essential settings for connecting to Google Analytics:

'analytics' => [
    // Your GA4 property ID
    'property_id' => env('ANALYTICS_PROPERTY_ID', '485547706'),

    // Path to service account credentials JSON file
    'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),

    // How long to cache analytics data (in minutes)
    'cache_lifetime_in_minutes' => 60,

    // Additional settings...
],

Property ID

The property_id setting takes your Google Analytics 4 property ID. This should be in the format "G-XXXXXXXXXX" for GA4 properties.

'property_id' => env('ANALYTICS_PROPERTY_ID', '485547706'),

Best practice is to use an environment variable:

# .env file
ANALYTICS_PROPERTY_ID=G-XXXXXXXXXX

Service Account Credentials

The service_account_credentials_json setting specifies the path to your service account JSON key file:

'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),

You can customize this path, but make sure:

  • The file is not publicly accessible
  • The web server has permission to read the file
  • The file is not committed to version control

Cache Settings

To improve performance, Novus caches analytics data:

'cache_lifetime_in_minutes' => 60,  // Default: 1 hour

Cache Settings

Setting cache duration too low may result in excessive API calls, potentially hitting rate limits. We recommend a minimum of 30 minutes in production environments.

Adjust this value based on:

  • How frequently your data changes
  • How up-to-date you need the data to be
  • Your API quota considerations

Dashboard Configuration

Time Period Options

Control which time period options users can select in the analytics dashboard:

'default_period' => 30,  // Default period to show (30 days)
'available_periods' => [7, 14, 21, 30],  // Period options in days

You can customize the available periods to match your reporting needs:

'available_periods' => [1, 7, 30, 90, 365],  // Daily, weekly, monthly, quarterly, yearly

Dashboard Widgets

Here are the default widgets available on the dashboard:

'dashboard_widgets' => [
    'visitors_chart' => true,     // Visitors over time chart
    'top_pages' => true,          // Most popular pages
    'active_users' => true,       // Current active users
    'top_browsers' => true,       // Browser usage statistics
    'top_referrers' => true,      // Traffic source breakdown
],

Performance Metrics

Configure which performance metrics are tracked and displayed:

'performance_metrics' => [
    'bounce_rate' => true,        // Percentage of single-page sessions
    'session_duration' => true,   // How long users stay on your site
    'page_load_time' => true,     // How quickly pages load
    'device_categories' => true,  // Device type breakdown
],

SEO Metrics

Control which SEO-related metrics are displayed:

'seo_metrics' => [
    'search_visits' => true,      // Visits from search engines
    'keywords' => true,           // Search terms driving traffic
    'landing_pages' => true,      // Entry pages from search
    'search_engines' => true,     // Traffic by search engine
    'click_through_rate' => true, // Percentage of impressions that result in clicks
],

Clearing the Cache

To clear cached analytics data programmatically:

use Shah\Novus\Services\AnalyticsService;

$analyticsService = app(AnalyticsService::class);
$analyticsService->clearCache();

Or to clear all cached data:

php artisan cache:clear
Previous
Analytics setup guide