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 App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Cache;

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/web.php:

Route::get('/js/script.js', [DataFastProxyController::class, 'script']);
Route::post('/api/events', [DataFastProxyController::class, 'events']);

4. Update Your Script Tag

Replace your existing DataFast script with the proxied version:

<script
  defer
  data-website-id="yourwebsiteid"
  data-domain="yourdomain.com"
  src="/js/script.js"
></script>

5. Deploy Your Application

The proxy configuration will take effect automatically after deployment.

Verification

To verify the proxy is working:

  1. Visit your website
  2. Open the network tab in your browser's developer tools
  3. Check that analytics requests are going through your domain instead of datafa.st
Something missing? Suggest features ✍️