antwerpes/laravel-event-store
最新稳定版本:1.2.0
Composer 安装命令:
composer require antwerpes/laravel-event-store
包简介
Store for tracking events in laravel applications
README 文档
README
Simple store for tracking events (e.g. for Google Tag Manager) in Laravel. Fire events from anywhere in your application and later retrieve them in your frontend.
Installation
You can install the package via composer:
composer require antwerpes/laravel-event-store
You must also add the middleware to your web group, at the end of the stack:
protected $middlewareGroups = [ 'web' => [ ... \Antwerpes\LaravelEventStore\Middleware\FlashEventStore::class, ], ];
You can optionally publish the config file with:
php artisan vendor:publish --tag="laravel-event-store-config"
This is the contents of the published config file:
return [ 'session_key' => '_eventStore', ];
Usage
From anywhere in your application, you can fire events like this:
use Antwerpes\LaravelEventStore\Facades\EventStore; EventStore::push('event-name'); // Or with additional data EventStore::push('event-name', ['foo' => 'bar']);
Events that you don't retrieve during the current request cycle will be flashed to the session and made available to the next request. That way, you can also fire events and retrieve them after a redirect.
// This will work EventStore::push('event-name'); return view('some-view'); // This will also work EventStore::push('event-name'); return redirect()->route('some-route');
In your frontend, you can dump the events like this:
{!! EventStore::dumpForGTM() !!}
which will output something like this:
<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'event-name', 'foo': 'bar' }); </script>
In case you want to use a different variable name, you can pass it as a parameter:
{!! EventStore::dumpForGTM('myDataLayer') !!}
You can also pull the events as an array and use them however you like:
EventStore::pullEvents();
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Leave an issue on GitHub, or create a Pull Request.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 186
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-12