"Best analytics tool I've used in 14 years"

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 day
        return Cache::remember('datafast_script', 86400, function () {
            $response = Http::get('https://datafa.st/js/script.js');
            return response($response->body(), 200, [
                'Content-Type' => 'application/javascript',
                'Cache-Control' => 'public, max-age=86400'
            ]);
        });
    }

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

        return response($response->body(), $response->status());
    }
}
Note: If you already have an /api/events API endpoint, add data-api-url to the DataFast script tag to send events to your own API endpoint. For example, data-api-url="/datafast-events" will send events to /datafast-events instead of /api/events. Read more here

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="dfid_******"
  data-domain="your_domain.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

Troubleshooting

All visitors showing from the same location

If your analytics show all visitors from a single location (usually your server's location), your proxy isn't forwarding visitor IPs.

To fix:

  1. Use the managed proxy for automatic visitor IP handling, or review your proxy provider's forwarding settings.

✍️ Something missing? Suggest features.

🤖 AI agent or LLM? Read this page as markdown