laravel-analytics maintained by gonoware
Google Analytics for your Laravel application
Using this package you can easily add Google Analytics to your website and track page views.
Installation
This package can be installed through Composer.
composer require gonoware/laravel-analytics
Publish the compiled assets to public/vendor/analytics with one of
these commands:
php artisan vendor:publish --tag=analytics
php artisan vendor:publish --provider="GoNoWare\Analytics\AnalyticsServiceProvider" --tag=public
When updating, use the
--forceswitch to overwrite existing assets:
php artisan vendor:publish --tag=analytics --force
Optionally, you can also publish the config file of this package with this
command to config/vendor/analytics.php:
php artisan vendor:publish --provider="GoNoWare\Analytics\AnalyticsServiceProvider" --tag=config
Usage
When the installation is done set the tracking ID in your .env.
ANALYTICS_ID='UA-123456789-1'
Track a page view by adding the following directive to your
Blade template before the </body> closing tag.
@analytics
By default, Analytics runs only in production mode, when a tracking ID
is defined and APP_DEBUG=false is set in your .env or debug is set to
false in config/app.php.
You can override the value by setting ANALYTICS_ENABLED to true or
false instead of null.
Sometimes you may need to pass different values to Analytics. For this
reason, you can pass an array with keys enabled and/or id to override the
default values of the config.
@analytics(['enabled' => app()->environment('staging'), 'id' => 'UA-987654321-1'])
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email em@gonoware.com instead of using the issue tracker.
Credits
License
Copyright (c) 2018-present Go NoWare