panchania83/laravel-nova-google-analytics-4

Google Analytics 4 integration with Laravel Nova

1.0.1 2023-10-31 09:35 UTC

This package is auto-updated.

Last update: 2024-10-30 02:16:27 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require panchania83/laravel-nova-google-analytics-4

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --tag="analytics-config"

The following config file will be published in config/analytics.php

return [

    /*
     * The property id of which you want to display data.
     */
    'property_id' => env('PROPERTY_ID'),

    /*
     * Path to the client secret json file. Take a look at the README of this package
     * to learn how to get this file. You can also pass the credentials as an array
     * instead of a file path.
     */
    'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),
];

Also add this to the .env for your Nova app:

PROPERTY_ID=

Usage

Next up, you must register the card with Nova. This is typically done in the cards method of the NovaServiceProvider.

// in app/Providers/NovaServiceProvider.php

// ...

public function cards()
{
    return [
        // ...
        new \panchania83\LaravelNovaGoogleAnalytics4\VisitorsMetric,
        new \panchania83\LaravelNovaGoogleAnalytics4\GoogleAnalyticsCard,
    ];
}

License

The MIT License (MIT). Please see License File for more information.