By Hira Ads Pro·3 min read·October 12, 2026
Laravel applications are custom, so tracking has to be designed with the developer rather than installed from a plugin. The upside is precision: events fire exactly when the application confirms something happened.
1. Add GTM to the main layout
Place the GTM snippet in your main Blade layout so it loads on every page. Initialise the dataLayer before it:
<script>window.dataLayer = window.dataLayer || [];</script>
<!-- GTM head snippet -->
Load the container ID from config so staging and production can use different containers.
2. Push events after a redirect
Most Laravel forms follow the pattern: POST, validate, save, redirect. The lead event should fire on the page after the redirect, only when the save succeeded. Flash the event data to the session in the controller:
$lead = Lead::create($validated);
return redirect()->route('thanks')->with('tracking', [
'event' => 'generate_lead',
'form_name' => 'quote_request',
'event_id' => 'lead_' . $lead->id,
]);
Then render it once in the layout:
@if (session('tracking'))
<script>
window.dataLayer.push(@json(session('tracking')));
</script>
@endif
Because flashed data lasts for one request, a page refresh will not fire the event again.
3. AJAX and SPA forms
If the form submits with JavaScript, return the event_id in the JSON response and push the dataLayer event in the success handler, never before the response arrives.
4. Send the Conversions API from the server
For Meta, send the same lead from Laravel to the Conversions API. Use a queued job so the visitor never waits for Meta’s API:
Http::post("https://graph.facebook.com/{$version}/{$pixelId}/events", [
'access_token' => config('services.meta.capi_token'),
'data' => [[
'event_name' => 'Lead',
'event_time' => now()->timestamp,
'event_id' => 'lead_' . $lead->id,
'action_source' => 'website',
'event_source_url' => $request->headers->get('referer'),
'user_data' => [
'em' => [hash('sha256', strtolower(trim($lead->email)))],
'client_ip_address' => $request->ip(),
'client_user_agent' => $request->userAgent(),
'fbp' => $request->cookie('_fbp'),
'fbc' => $request->cookie('_fbc'),
],
]],
]);
Capture IP, user agent and the _fbp/_fbc cookies in the request and pass them to the job. Use the same event_id as the browser event so Meta can deduplicate.
5. Store click IDs for offline conversions
Save gclid, gbraid, wbraid and fbclid from the landing URL on the lead record. When a lead becomes a customer, you can report it back to Google Ads and Meta as an offline conversion.
6. Respect consent
Only send ad platform data when the visitor has consented. Store consent state with the session and check it before dispatching server-side events.
Laravel tracking is usually built together with the client’s developer. See conversion tracking and web analytics.
Want this set up properly on your site?
Request an audit and get a clear plan before any changes are made.
Request an Audit →