DataSag guides · Updated 27 October 2026
Track custom events on Laravel Blade
Use data-datasag-goal for a click goal, or call window.datasag.track after a completed action. Choose a stable event name and distinguish a click from a successful conversion. This guide applies to Laravel Blade.
Start with the Laravel Blade installation
Add the deferred external script once in the shared Blade layout under resources/views, inside its existing head. Preserve @vite, component slots and content sections. Determine whether your pages use template inheritance or a layout component before choosing the file. Deploy the view change through your normal application release.
An alternate authentication layout or a standalone Blade view may not use the same head. Livewire navigation and Inertia change the browser lifecycle; verify their route sequences separately instead of promising coverage from a normal Blade page test.
Use the public project key from the DataSag project you are inspecting. A test on a preview domain does not confirm that the production domain has the same code or settings.
Track custom events in Laravel Blade
- For a click goal in Blade, place data-datasag-goal on the actual rendered button or link. Inspect the final DOM if a component transforms attributes or replaces the element.
- For a confirmed action, use the browser success result of your actual form or frontend implementation. A successful PHP controller branch alone cannot call the visitor window, and an initial submit may still fail validation.
- Test valid and invalid input on the published route. If a frontend library updates the form without a full reload, repeat after that update. Confirm one agreed event payload and no duplicate listener introduced by the component lifecycle.
The rendered Blade element or frontend success handler records the intended observable outcome once.
Complete the collection checks
- Write the event definition first. For example, signup_click means a visitor pressed a signup link, while signup_completed means your application confirmed account creation.
- For click intent, add data-datasag-goal to the element. The tracker delegates clicks, so you do not also need a JavaScript handler for the same goal.
- For a completed action, call the JavaScript API in the success handler. Wait for the tracker to be available. An optional guard avoids a crash but intentionally drops the event if the tracker has not loaded.
- Send only the context needed for the report, such as a form or plan name. Do not include email addresses, passwords, payment details or freeform form contents.
- Complete one successful and one failed attempt. Inspect /api/track for the exact eventName and properties. Only the successful attempt should emit a completed-action event.
- Check the event report available to your plan. Collection and access to reports are separate; review current plan details before depending on a particular report.
<!-- Click intent: use this OR your own click handler -->
<a href="/signup" data-datasag-goal="signup_click">Create account</a>
// JavaScript: inside the confirmed-success handler
window.datasag?.track('signup_completed', { form: 'main_signup' });For a Blade click goal, put data-datasag-goal on the rendered element. For confirmed actions, call the browser API only after the response confirms success. PHP controller execution cannot call a visitor window.
What a successful check looks like
A controlled successful action produces one event with the agreed name. A validation failure does not emit a success event. Network evidence matches the report definition.
Record the public path you tested, the browser state, the approximate time and the observed request. Check one direct page load and one later navigation so the result covers more than the homepage.
Common mistake
A goal attribute on a submit button measures clicks, including attempts that fail. Do not report those clicks as completed signups or purchases.
Installation snippet for Laravel Blade
The shared installation belongs in the head of the shared Blade layout used by your web routes. Use this as the installation reference while checking the procedure above.
<script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>Related Laravel Blade guides
References
Official Laravel Blade documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.