first commit from hostslim
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Website;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class TrackingScriptController extends Controller
|
||||
{
|
||||
public function script(string $trackingId): Response
|
||||
{
|
||||
$this->log("Start ".$trackingId);
|
||||
$website = Website::where('tracking_id', $trackingId)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
|
||||
if (! $website) {
|
||||
$this->log("no website ".$trackingId);
|
||||
return response('', 404)
|
||||
->header('Content-Type', 'application/javascript');
|
||||
}
|
||||
|
||||
$collectUrl = route('collect.store');
|
||||
|
||||
$js = view('tracking.tracker', [
|
||||
'trackingId' => $trackingId,
|
||||
'collectUrl' => $collectUrl,
|
||||
])->render();
|
||||
|
||||
$this->log("response ".$trackingId);
|
||||
|
||||
return response($js)
|
||||
->header('Content-Type', 'application/javascript')
|
||||
->header('Cache-Control', 'public, max-age=3600');
|
||||
}
|
||||
|
||||
private function log($message)
|
||||
{
|
||||
$path = '/home/libremet/domains/libremetrics.com/engine/storage/logs/mihai.log';
|
||||
|
||||
$message = date('Y-m-d H:i:s') . "\n" . $message . "\n\n";
|
||||
|
||||
file_put_contents($path, $message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user