Installation guides
Laravel
Add ProductLense to a Laravel app in the main Blade layout, then identify the signed-in user with a JSON-encoded id.
In Laravel the script goes into the Blade layout that every page extends, usually resources/views/layouts/app.blade.php. Apps that use Inertia or Livewire navigation change the URL with the history API, which ProductLense records as pageviews.
Add the script
Replace SITE_ID with the id from Settings → Sites in the ProductLense dashboard.
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<script>window.productlense=window.productlense||function(){(window.productlense.q=window.productlense.q||[]).push(arguments)}</script>
<script defer data-site="SITE_ID" src="https://api.productlense.app/a.js"></script>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
@yield('content')
</body>
</html>To keep the site id out of the template, put it in .env as PL_SITE_ID, expose it in config/services.php, and print it with {{ config('services.productlense.site_id') }}.
Identify users
Use @json, which encodes the value safely for a script block:
@auth
<script>
window.productlense('identify', String(@json(auth()->id())));
</script>
@endauthPlace it after the queue stub. Use the same id you store on the customer in your billing provider; see how payments are attributed.
Events from your server
Actions that happen only on the server, such as a queued job that converts a trial, can be sent to the Events API with an API key. API keys are on the Scale plan; see server-side events.
Verify your installation
- Deploy, then open your site in a normal browser window.
- Open the Live page in the ProductLense dashboard. Your visit appears within a few seconds.
- In the browser's developer tools, the Network tab shows a
POSTtohttps://api.productlense.app/api/ewith status204.
php artisan serve runs on localhost, where nothing is sent unless you add data-dev="true" to the tag. Ad blockers in your own browser may block the request. If the visit does not appear, follow Verify your installation.