Proxy DataFast with Laravel

Learn how to proxy DataFast analytics through your Laravel application to bypass adblockers and improve accuracy.

1. Create Proxy Controller

Create a new controller to handle the proxy requests:

php artisan make:controller DataFastProxyController

2. Implement Proxy Logic

Add the following to app/Http/Controllers/DataFastProxyController.php:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use IlluminateSupportFacadesHttp;
use IlluminateSupportFacadesCache;

class DataFastProxyController extends Controller
{
    public function script()
    {
        // Cache the script for 1 year
        return Cache::remember('datafast_script', 31536000, function () {
            $response = Http::get('https://datafa.st/js/script.js');
            return response($response->body(), 200, [
                'Content-Type' => 'application/javascript',
                'Cache-Control' => 'public, max-age=31536000'
            ]);
        });
    }

    public function events(Request $request)
    {
        $response = Http::withHeaders([
            'User-Agent' => $request->header('User-Agent'),
            'Content-Type' => 'application/json'
        ])->post('https://datafa.st/api/events', $request->all());

        return response($response->body(), $response->status());
    }
}

3. Add Routes

Add the following routes to routes/api.php:

// Stripe routes
Route::post('/stripe/webhook', [StripeWebhookController::class, 'handleWebhook']);

// LemonSqueezy routes
Route::post('/lemonsqueezy/webhook', [LemonSqueezyWebhookController::class, 'handleWebhook']);

4. Configure Services

Add the following to config/services.php:

'stripe' => [
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
    'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'),
],

'lemonsqueezy' => [
    'api_key' => env('LEMON_SQUEEZY_API_KEY'),
    'store_id' => env('LEMON_SQUEEZY_STORE_ID'),
    'webhook_secret' => env('LEMON_SQUEEZY_WEBHOOK_SECRET'),
],

5. Update Environment Variables

Add to your .env file:

STRIPE_KEY=your_stripe_key
STRIPE_SECRET=your_stripe_secret
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret

LEMON_SQUEEZY_API_KEY=your_lemonsqueezy_api_key
LEMON_SQUEEZY_STORE_ID=your_store_id
LEMON_SQUEEZY_WEBHOOK_SECRET=your_webhook_secret

Once connected and cookie data is properly passed, DataFast will automatically:

  • Track all payments from your Stripe/LemonSqueezy account
  • Attribute revenue to the correct marketing channels
  • Provide detailed analytics in your dashboard
The webhook handlers are optional but recommended for additional tracking and business logic. Always verify webhook signatures to ensure the requests are coming from Stripe/LemonSqueezy.
Something missing? Suggest features ✍️