Track signups with Laravel

Exempt Chartsy’s cookies from encryption, then listen for the Registered event.

Before you start

The Chartsy script must already be on every page of your site, including the app where signup happens - it supplies where the visitor came from; this guide only adds the email. See the installation guides.

1Add your secret key

Store the site's secret key in .env and expose it through config/services.php.

CHARTSY_SECRET_KEY=your_secret_key
'chartsy' => [
    'secret' => env('CHARTSY_SECRET_KEY'),
],

2Let Laravel read Chartsy's cookies

Laravel encrypts cookies and discards ones it didn't set. Without this exemption your backend reads nothing and every signup shows an unknown source:

->withMiddleware(function (Middleware $middleware) {
    $middleware->encryptCookies(except: [
        'chartsy_attrib', 'chartsy_attrib_last', 'chartsy_visitor_id',
    ]);
})

On Laravel 10 and earlier, add the same three names to $except in app/Http/Middleware/EncryptCookies.php.

3Listen for the Registered event

Breeze, Jetstream and Fortify all fire it.

use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Http;

class SendSignupToChartsy
{
    public function handle(Registered $event): void
    {
        $json = fn ($name) => json_decode(urldecode(request()->cookie($name, '')), true) ?: [];
        $first = $json('chartsy_attrib');

        Http::withToken(config('services.chartsy.secret'))
            ->timeout(3)
            ->post('https://dashboard.chartsy.app/api/attribution/identify/', [
                'email' => $event->user->email,
                'attribution_first' => (object) $first,
                'attribution_last' => (object) ($json('chartsy_attrib_last') ?: $first),
                'visitor_id' => request()->cookie('chartsy_visitor_id', ''),
            ]);
    }
}

4Socialite signups

Socialite logins don't fire Registered unless you dispatch it. Do so where your callback creates the user ($user->wasRecentlyCreated).

Related articles

Chartsy Team

Written by

Chartsy Team

Analytics team at Chartsy

The Chartsy Team writes guides, product updates, and resources to help SaaS and eCommerce founders make sense of their metrics, without SQL or spreadsheets.

Chartsy
Ministry of Economy and Innovation
Startup Albania

The Chartsy program is realized with the financial support of the Albanian Government through the Ministry of Economy and Innovation, under the Grant 2026 scheme, and is implemented by the Innovation4Albania Agency.