tightenco / nova-google-analytics
Google Analytics integration with Nova
Installs: 118 205
Dependents: 2
Suggesters: 0
Security: 0
Stars: 166
Watchers: 13
Forks: 30
Open Issues: 0
Requires
- php: ^8.1
- spatie/laravel-analytics: ^5.2
Requires (Dev)
- laravel/nova: ^4.0
- orchestra/testbench: ^8.21 | ^9.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.5
- tightenco/tlint: ^9.3
README
Google Analytics Integration with Nova
Installation
You can install the package in to a Laravel app that uses Nova via composer:
composer require tightenco/nova-google-analytics
For now, follow the directions on Spatie's Laravel Google Analytics package for getting your credentials, then put them here:
yourapp/storage/app/analytics/service-account-credentials.json
Also add this to the .env
for your Nova app:
ANALYTICS_PROPERTY_ID=
Upgrading to 4.0
Version 4.0 uses the new Google Analytics 4 Data API.
- Upgrades
spatie/laravel-analytics
tov5.2
- Drops support for PHP 8.0
- Drops support for Laravel 9
- Removes
FourteenDayActiveUsersMetric
metric which is not available in GA4
The required environment variable ANALYTICS_VIEW_ID
has been renamed to ANALYTICS_PROPERTY_ID
to match Google's usage.
Usage
You must register the cards you want to display with Nova. This is typically done in the cards
method of the Main
dashboard.
// in app/Nova/Dashboards/Main.php // ... public function cards() { return [ // ... new \Tightenco\NovaGoogleAnalytics\PageViewsMetric, new \Tightenco\NovaGoogleAnalytics\VisitorsMetric, new \Tightenco\NovaGoogleAnalytics\MostVisitedPagesCard, new \Tightenco\NovaGoogleAnalytics\ReferrersList, new \Tightenco\NovaGoogleAnalytics\OneDayActiveUsersMetric, new \Tightenco\NovaGoogleAnalytics\SevenDayActiveUsersMetric, new \Tightenco\NovaGoogleAnalytics\TwentyEightDayActiveUsersMetric, new \Tightenco\NovaGoogleAnalytics\SessionsMetric, new \Tightenco\NovaGoogleAnalytics\SessionDurationMetric, new \Tightenco\NovaGoogleAnalytics\SessionsByDeviceMetric, new \Tightenco\NovaGoogleAnalytics\SessionsByCountryMetric, ]; }
Register the tool with Nova in the tools
method of your NovaServiceProvider
:
// in app/Providers/NovaServiceProvider.php // ... public function tools() { return [ new Tightenco\NovaGoogleAnalytics\Tool(), ]; }
Features
View the Visitors and Pageview Metrics
View the Active Users Metrics
View the Sessions and Avg. Session Duration Metrics
View the Devices and Country Metrics by Session
View the lists of Most Visited Pages and Referrers
Testing
First, copy your .env.example file to a new file called .env.testing:
cp .env.example .env.testing
Make sure, in that file, to define the following variables to run all tests:
ANALYTICS_PROPERTY_ID
ANALYTICS_PROJECT_ID
ANALYTICS_PRIVATE_KEY_ID
ANALYTICS_PRIVATE_KEY
ANALYTICS_CLIENT_EMAIL_KEY
ANALYTICS_CLIENT_ID
ANALYTICS_CLIENT_CERT_URL
Add the .env.testing
file in .gitignore
so you can safely use the same analytics view ID to run the tests that you use for the card.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email matt@tighten.co instead of using the issue tracker.
Credits
Support us
Tighten is a web development firm that works in Laravel, Vue, and React. You can learn more about us on our web site
License
The MIT License (MIT). Please see License File for more information.