hosmelq/laravel-logsnag

Integrate the power of LogSnag's real-time event tracking into your Laravel application.

v0.4.0 2024-04-09 20:39 UTC

This package is auto-updated.

Last update: 2024-05-09 20:54:08 UTC


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.