Laravel revenue attribution

Step-by-step guide for attributing revenue in Laravel applications.

Back to revenue attribution

1. Install the pixel

Add the attribu.tech tracking script to your Blade layout. If you've already done this, skip to step 2.

<!-- resources/views/layouts/app.blade.php -->
<head>
  ...
  <script
    defer
    data-website-id="YOUR_SITE_ID"
    data-domain="yourdomain.com"
    src="https://attribu.tech/js/script.js"
  ></script>
</head>

See the full Laravel installation guide for environment variable setup and advanced options.

2. Connect Stripe

Go to Settings > Revenue in your attribu.tech dashboard and paste your Stripe restricted API key. This lets attribu.tech read charges and link them to visitors.

See Connect Stripe for detailed instructions on creating a restricted key.

3. Pass cookies in checkout

When creating a Stripe Checkout Session, read the attribu.tech cookies from the request and pass them as metadata:

Stripe Checkout

// app/Http/Controllers/CheckoutController.php
use Illuminate\Http\Request;

public function createCheckout(Request $request)
{
    $checkout = \Stripe\Checkout\Session::create([
        'line_items' => [[
            'price' => 'price_xxx',
            'quantity' => 1,
        ]],
        'mode' => 'payment', // or 'subscription'
        'success_url' => route('checkout.success') . '?session_id={CHECKOUT_SESSION_ID}',
        'cancel_url' => route('checkout.cancel'),
        'metadata' => [
            'attribu_visitor_id' => $request->cookie('attribu_visitor_id') ?? '',
            'attribu_session_id' => $request->cookie('attribu_session_id') ?? '',
        ],
    ]);

    return redirect($checkout->url);
}
The metadata field must be on the Checkout Session itself, not on the line item or product. attribu.tech reads session-level metadata from the Stripe webhook.

LemonSqueezy

If you use LemonSqueezy instead of Stripe, pass the cookies as custom data in the checkout creation:

// Using LemonSqueezy API
$response = Http::withToken(env('LEMONSQUEEZY_API_KEY'))
    ->post('https://api.lemonsqueezy.com/v1/checkouts', [
        'data' => [
            'type' => 'checkouts',
            'attributes' => [
                'checkout_data' => [
                    'custom' => [
                        'attribu_visitor_id' => $request->cookie('attribu_visitor_id') ?? '',
                        'attribu_session_id' => $request->cookie('attribu_session_id') ?? '',
                    ],
                ],
                'product_options' => [
                    'redirect_url' => route('checkout.success'),
                ],
            ],
            'relationships' => [
                'store' => [
                    'data' => [
                        'type' => 'stores',
                        'id' => env('LEMONSQUEEZY_STORE_ID'),
                    ],
                ],
                'variant' => [
                    'data' => [
                        'type' => 'variants',
                        'id' => $variantId,
                    ],
                ],
            ],
        ],
    ]);
That's it. Once a payment goes through, the charge appears in your attribu.tech dashboard attributed to the traffic source that brought the visitor.

What's next

Copied