simplestats-io/laravel-client

Client for SimpleStats!

v2.0.14 2024-10-31 14:46 UTC

README

Latest Version on Packagist Tests Check & fix styling License

This is the official Laravel client to send tracking data to https://simplestats.io

Introduction

SimpleStats is a streamlined statistics tool tailored for Laravel applications, transcending mere counts of views and visits. It offers precise insights into user origins and behaviors. With default tracking and filtering via UTM codes, you gain detailed analysis of marketing campaigns, identifying which efforts drive revenue. Effortlessly evaluate campaign ROI, discover cost-effective user acquisition channels, and pinpoint the most effective performance channels. SimpleStats ensures full GDPR compliance and a minimalistic and straightforward installation process.

screenshot

Installation

You can install the client package via composer:

composer require simplestats-io/laravel-client

You should publish the config file with:

php artisan vendor:publish --tag="simplestats-client-config"

This is the default content of the config file, tweak it to your needs:

use App\Models\User;
use Illuminate\Auth\Events\Login;

return [

    /*
     |--------------------------------------------------------------------------
     | SimpleStats Settings
     |--------------------------------------------------------------------------
     |
     | SimpleStats is enabled by default. Be aware that if you turn disable it,
     | you may lose important tracking data. In most cases, leave it enabled!
     |
     | You can provide an array of URI's that must be ignored (eg. 'api/*')
     */

    'enabled' => env('SIMPLESTATS_ENABLED', true),
    
    'except' => [
        'telescope*',
        'horizon*',
        'admin*',
        'api*',
    ],

    /*
     |--------------------------------------------------------------------------
     | SimpleStats API Credentials
     |--------------------------------------------------------------------------
     |
     | Define your API credentials here. If you are not told to change the API URL,
     | just keep the default. It's important to set an API token! You'll receive
     | one, after creating an Instance for a Project on https://simplestats.io
     |
     */

    'api_url' => env('SIMPLESTATS_API_URL', 'https://simplestats.io/api/v1/'),

    'api_token' => env('SIMPLESTATS_API_TOKEN'),

    /*
     |--------------------------------------------------------------------------
     | SimpleStats Queue
     |--------------------------------------------------------------------------
     |
     | To avoid the tracking API calls block the whole request and for fault tolerance,
     | we highly recommend to use Laravel's built-in queue-system. Here you can define
     | to which queue the tracking API calls should be dispatched and handled by.
     |
     */

    'queue' => env('SIMPLESTATS_QUEUE', 'default'),

    /*
     |--------------------------------------------------------------------------
     | SimpleStats Tracking Codes
     |--------------------------------------------------------------------------
     |
     | Below you can set your tracking code URL param names. We already set some
     | classical defaults for you, but you're free to change them as you like.
     | Note that only the params which are listed here are getting tracked!
     |
     */

    'tracking_codes' => [
        'source' => ['utm_source', 'ref', 'referer', 'referrer'],
        'medium' => ['utm_medium', 'adGroup', 'adGroupId'],
        'campaign' => ['utm_campaign'],
        'term' => ['utm_term'],
        'content' => ['utm_content'],
    ],

    /*
     |--------------------------------------------------------------------------
     | SimpleStats Tracking Types
     |--------------------------------------------------------------------------
     |
     | Here you can set three different tracking types. The first is the login
     | event. If this event gets dispatched, we track a login. The second is
     | the user model. If such a model is created, we track a registration.
     |
     | As the payment model is named very individually, we did not set any default here.
     | Give it the name of the model which holds your payments or transactions data.
     |
     | See: https://simplestats.io/docs
     |
     */

    'tracking_types' => [
        'login' => [
            'event' => Login::class,
        ],

        // Make sure this model implements the TrackableUser or
        // the TrackableUserWithCondition contract
        'user' => [
            'model' => User::class,
        ],

        // Make sure this model implements the TrackablePayment or
        // the TrackablePaymentWithCondition contract
        'payment' => [
            'model' => null,
        ],
    ],
];

Documentation

Check out the full documentation here: Official SimpleStats.io Documentation

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

GNU General Public License v3.0 or later. Please see License File for more information.