ngiraud / laravel-cookies-analytics
Add Google Analytics and cookie consent to your application.
3.0.0
2021-07-19 17:03 UTC
Requires
- php: ^7.2.5
- illuminate/support: ~5.8.0|^6.0|^7.0|^8.0
This package is auto-updated.
Last update: 2024-12-20 00:46:52 UTC
README
Installation
- Install the package via composer:
composer require ngiraud/laravel-cookies-analytics
- Install the CookieConsent plugin
yarn add cookieconsent
or
npm install cookieconsent --save
Usage
- You can activate/deactivate cookies and google analytics by settings environment variables in your
.env
file :
GOOGLE_ANALYTICS_ENABLED GOOGLE_ANALYTICS_ID (mandatory if GOOGLE_ANALYTICS_ENABLED is set to true) COOKIES_ENABLED
- Add the view to the top of your
<head>
section :
@include('analytics::scripts')
- Add the css for the CookieConsent plugin in your css file :
@import "../../node_modules/cookieconsent/build/cookieconsent.min.css";
- And these lines in your vuejs index file :
import {CookieConsent} from 'cookieconsent'; if (window.cookieSettings.enabled === true) { document.addEventListener('DOMContentLoaded', () => { cookieconsent.initialise(window.cookieSettings.content); }); }
- If you want to customize the popup and the message in the config file, you can publish and edit the config file :
php artisan vendor:publish --tag=analytics-config
Don't forget to generate and include your css & js files.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email contact@ngiraud.me instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.