hosmelq / laravel-logsnag
Integrate the power of LogSnag's real-time event tracking into your Laravel application.
Installs: 5 075
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 2
Forks: 3
Open Issues: 1
Requires
- php: ^8.1 || ^8.2 || ^8.3
- guzzlehttp/guzzle: ^7.7
- laravel/framework: ^10.0.0 || ^11.0.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.10
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- pestphp/pest: ^2.13
- pestphp/pest-plugin-laravel: ^2.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- rector/rector: ^1.0.0
- thecodingmachine/phpstan-safe-rule: ^1.2
README
This is an unofficial package for LogSnag.
Laravel LogSnag
Easily integrate LogSnag's event tracking into your Laravel app. Monitor user activity, get realtime analytics, and receive instant insights.
Requirements
This package requires PHP 8.1 or higher and Laravel 10.0 or higher.
Installation
You can install the package via composer:
composer require hosmelq/laravel-logsnag
Configuration
You can publish the config file with:
php artisan vendor:publish --tag="logsnag-config"
Alternatively, you may utilize the install command.
php artisan logsnag:install
Next, you should configure your LogSnag API token and project name in your application’s .env
file:
LOGSNAG_API_TOKEN=your-api-token LOGSNAG_PROJECT=your-project-name
We determine the project to send events to using LOGSNAG_PROJECT
. Alternatively, you can specify
the project name when creating an event or insight.
Usage
Publish Event
You can use the LogSnag
facade to publish events, and insights.
use HosmelQ\LogSnag\Laravel\Facades\LogSnag; LogSnag::log()->publish([ 'channel' => 'waitlist', 'event' => 'User Joined Waitlist', 'icon' => '🎉', ]);
This method returns a Log instance that provides access to the response from the LogSnag API. For more information and a list of available parameters, refer to the LogSnag documentation for Log.
Publish Insight
use HosmelQ\LogSnag\Laravel\Facades\LogSnag; LogSnag::insight()->publish([ 'icon' => '🎉', 'title' => 'Registered Users on Waitlist', 'value' => 8, ]);
This method returns an Insight instance that provides access to the response from the LogSnag API. For more information and a list of available parameters, refer to the LogSnag documentation for Insight.
User Properties
use HosmelQ\LogSnag\Laravel\Facades\LogSnag; LogSnag::identify()->publish([ 'properties' => [ 'email' => 'john@doe.com', 'name' => 'John Doe', 'plan' => 'premium', ], 'user_id' => '123', ]);
This method returns an Identify instance that provides access to the response from the LogSnag API. For more information and a list of available parameters, refer to the LogSnag documentation for Identify.
Apart from the facade, you can utilize the logsnag
helper function.
logsnag()->log()->publish([ 'channel' => 'waitlist', 'event' => 'User Joined Waitlist', 'icon' => '🎉', ]);
Credits
License
The MIT License (MIT). Please see License File for more information.