2026-03-18 10:56:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Website;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
|
|
|
|
class TrackingScriptController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function script(string $trackingId): Response
|
|
|
|
|
{
|
|
|
|
|
$website = Website::where('tracking_id', $trackingId)
|
|
|
|
|
->where('is_active', true)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if (! $website) {
|
|
|
|
|
return response('', 404)
|
|
|
|
|
->header('Content-Type', 'application/javascript');
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 22:42:31 +02:00
|
|
|
// Use ad-blocker resistant endpoint if script is loaded from /cdn/resources/
|
|
|
|
|
// Otherwise use the original endpoint for backward compatibility
|
|
|
|
|
$currentRoute = request()->route()->getName();
|
2026-03-28 13:21:29 +02:00
|
|
|
// $collectUrl = $currentRoute === 'tracking.script.alt'
|
|
|
|
|
// ? 'route('collect.store.alt')'
|
|
|
|
|
// : route('collect.store');
|
|
|
|
|
$collectUrl = 'https://assets.libremetrics.com/assets/client/data';
|
2026-03-18 10:56:35 +02:00
|
|
|
|
|
|
|
|
$js = view('tracking.tracker', [
|
|
|
|
|
'trackingId' => $trackingId,
|
|
|
|
|
'collectUrl' => $collectUrl,
|
|
|
|
|
])->render();
|
|
|
|
|
|
|
|
|
|
return response($js)
|
|
|
|
|
->header('Content-Type', 'application/javascript')
|
|
|
|
|
->header('Cache-Control', 'public, max-age=3600');
|
|
|
|
|
}
|
|
|
|
|
}
|