Install on Laravel
View as MarkdownAdd Reveata to the Blade layout of a Laravel app.
On this page
Laravel renders the <head> of your pages from a Blade layout, so the snippet goes there once.
Copy the snippet from your Reveata dashboard (it contains your website’s tracking id):
<script
defer
data-website-id="ws_your_tracking_id"
src="https://reveata.com/js/script.js"
></script>Add it to your site
- Open the layout your pages use, usually
resources/views/layouts/app.blade.php(starter kits also haveresources/views/layouts/guest.blade.phpfor the sign-in pages; add it there too). With Inertia, it is the root template, usuallyresources/views/app.blade.php. - Paste the snippet before
</head>. To load it only in production, wrap it in Blade’s@productiondirective:
<head>
{{-- … --}}
@production
<script defer data-website-id="ws_your_tracking_id" src="https://reveata.com/js/script.js"></script>
@endproduction
</head>- Deploy. If you cache views (
php artisan view:cache), run it again after the change.
Inertia page changes go through the browser’s History API, which the script follows, so every page is counted.
Check it works
Open your site in a private window, then check that the visit appears in your Reveata dashboard. If it doesn’t, follow Verify your installation. The script ignores localhost by default, so local development visits stay out of your numbers.
Goals
Add data-reveata-goal="signup" to a button or link in your Blade views, or call reveata('goal', 'signup') from JavaScript. See Custom goals.
Serve it from your own domain
Two routes in routes/web.php can pass the script and events through your own domain, with the visitor’s address and your proxy secret: see Laravel in the proxy guide. Store the secret as REVEATA_PROXY_SECRET and read it through config(), so it survives php artisan config:cache. Laravel Forge and most servers also run NGINX in front, which can do it instead: Proxy through NGINX. Or use the managed proxy: one DNS record, no code.
Revenue
First connect your payment provider in Reveata (for example Stripe, which Laravel Cashier uses): see Connect a payment provider. Then pass the Reveata visitor id with each checkout, so the payment is credited to the visit that brought the buyer.
In the Blade view with your buy button, add two hidden fields and fill them when the form is sent:
<form method="post" action="{{ route('checkout') }}">
@csrf
<input type="hidden" name="reveata_visitor_id">
<input type="hidden" name="reveata_session_id">
<button>Buy</button>
</form>
<script>
document.addEventListener('submit', function (e) {
var ids = window.reveata && window.reveata.metadata ? window.reveata.metadata() : {};
Object.keys(ids).forEach(function (name) {
var input = e.target.querySelector('input[name="' + name + '"]');
if (input) input.value = ids[name];
});
});
</script>With Cashier, pass them as the Checkout Session’s metadata:
use Illuminate\Http\Request;
Route::post('/checkout', function (Request $request) {
$ids = array_filter($request->only(['reveata_visitor_id', 'reveata_session_id']));
return $request->user()->checkout(['price_123' => 1], [
'success_url' => route('thanks').'?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => route('pricing'),
'metadata' => $ids,
]);
})->middleware('auth')->name('checkout');For subscriptions, use newSubscription('default', 'price_123')->checkout([...]) with the same metadata.
Payments from your own billing. If Reveata doesn’t connect to your provider, send each payment with the Payments API:
use Illuminate\Support\Facades\Http;
Http::withToken(config('services.reveata.site_key'))
->post('https://reveata.com/api/v1/payments', [
'transactionId' => 'order_'.$order->id,
'amount' => (float) $order->total_without_tax, // major units, e.g. 49.00
'currency' => 'USD',
'email' => $order->email,
'visitorId' => $order->reveata_visitor_id, // saved from the hidden field
]);Add 'site_key' => env('REVEATA_SITE_KEY') to the reveata entry in config/services.php.
Common pitfalls
- Layouts you forgot. Starter kits have separate layouts for guest pages; Inertia apps use
resources/views/app.blade.php. The snippet goes in each layout that renders<head>. - Cached views and config. Run
php artisan view:cacheandphp artisan config:cacheagain after deploying. @production. With the snippet wrapped in it, nothing is sent from your local or staging environments. That’s on purpose; test the production site.- Counting payments twice. With your payment provider connected in Reveata, don’t also send the same payments with the Payments API.