Analytics

Google Analytics setup guide

This guide walks you through obtaining the necessary credentials and setting up Google Analytics integration with Novus CMS.

Step 1: Create a Google Analytics 4 Property

First, you need a Google Analytics 4 (GA4) property for your website:

  1. Log in to Google Analytics
  2. Click "Admin" in the bottom left corner
  3. In the "Account" column, select an existing account or create a new one
  4. In the "Property" column, click "Create Property"
  5. Select "Web" as the platform
  6. Enter your website details and click "Create"
  7. Follow the setup wizard to complete the creation process
  8. Important: Make note of your Property ID (it will look like "G-XXXXXXXXXX")

Step 2: Add Analytics Tracking to Your Website

Implement the Google Analytics tracking code on your website:

  1. In your GA4 property, navigate to Admin > Data Streams > Web
  2. Click on your web data stream
  3. Find the "Measurement ID" (it should look like "G-XXXXXXXXXX")
  4. Add the tracking code to your website either by:
    • Using the Global Site Tag (gtag.js) directly in your HTML
    • Using Google Tag Manager

Step 3: Create a Google Cloud Project

  1. Go to the Google Cloud Console
  2. Click the project dropdown at the top of the page
  3. Click "New Project"
  4. Enter a name for your project (e.g., "Novus Analytics")
  5. Click "Create"
  6. Make sure your new project is selected in the project dropdown

Step 4: Enable the Google Analytics Data API

  1. In your Google Cloud project, go to "APIs & Services" > "Library"
  2. Search for "Google Analytics Data API"
  3. Click on the API in the results
  4. Click "Enable"

Step 5: Create a Service Account

  1. In your Google Cloud project, go to "IAM & Admin" > "Service Accounts"
  2. Click "Create Service Account"
  3. Enter a name (e.g., "Novus Analytics")
  4. Optionally add a description
  5. Click "Create and Continue"
  6. For the role, you can skip this step (we'll grant access directly in GA)
  7. Click "Continue" and then "Done"

Step 6: Create and Download Service Account Key

  1. In the Service Accounts list, find the account you just created
  2. Click the three dots menu (⋮) at the end of the row
  3. Select "Manage keys"
  4. Click "Add Key" > "Create new key"
  5. Choose "JSON" as the key type
  6. Click "Create"
  7. A JSON key file will be downloaded to your computer

Security First!

The service account JSON file contains sensitive credentials. Never commit this file to version control, ensure it has restricted file permissions (600), and store it outside publicly accessible directories.

Step 7: Store the Service Account Credentials

  1. Create a directory in your Laravel project:

    mkdir -p storage/app/analytics
    
  2. Move the downloaded JSON key file to this directory:

    mv /path/to/downloaded-key.json storage/app/analytics/service-account-credentials.json
    
  3. Ensure the file has appropriate permissions:

    chmod 600 storage/app/analytics/service-account-credentials.json
    

Step 8: Grant Analytics Access to the Service Account

  1. Open the JSON key file and copy the client_email value

    cat storage/app/analytics/service-account-credentials.json | grep client_email
    
  2. Go to Google Analytics > Admin

  3. In the "Property" column, click "Property Access Management"

  4. Click the "+" button

  5. Paste the service account email address

  6. Select "Viewer" role (read-only access is sufficient)

  7. Click "Add"

Step 9: Configure Novus

  1. Add your GA4 property ID to your .env file:

    ANALYTICS_PROPERTY_ID=G-XXXXXXXXXX
    
  2. Ensure the service account credentials path in config/novus.php points to the correct location:

    'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),
    
  3. If you've made changes to your configuration, clear the config cache:

    php artisan config:clear
    

Step 10: Verify the Integration

  1. Log in to your Novus admin panel
  2. Navigate to the Statistics section in the sidebar
  3. You should see analytics data loading (note that it may take up to 24-48 hours for Google Analytics to start showing data for a new property)

Troubleshooting

No Data Showing

If no data appears in your analytics dashboard:

  1. Verify Google Analytics is collecting data by checking the Realtime reports in GA
  2. Confirm your Property ID is correct in the .env file
  3. Ensure the service account has Viewer access to the Analytics property
  4. Check the logs for any authentication errors
  5. Clear the cache: php artisan cache:clear

Authentication Errors

If you see authentication errors:

  1. Verify the JSON file is correctly formatted and contains all required fields
  2. Ensure the file path in your config is correct
  3. Check file permissions (the web server user needs to be able to read the file)
  4. Confirm the service account has not been deleted or disabled in Google Cloud

"Property not found" Error

If you get a "property not found" error:

  1. Double-check your property ID in the Google Analytics Admin area
  2. Ensure you're using a GA4 property ID (starts with "G-") and not a Universal Analytics property ID (starts with "UA-")
  3. Verify the service account has been granted access to this specific property
Previous
Overview