SimpleStats with Nuxt
A Nuxt marketing site in front of a Laravel app (signup, login and payments in Laravel) uses the beacon script. If your whole app frontend is built in Nuxt against a Laravel API, see Nuxt as the app frontend below.
1. Prepare your Laravel app
Enable the beacon in the .env of your Laravel app:
SIMPLESTATS_BEACON_ENABLED=trueList the domain of the marketing site in own_domains, otherwise the beacon ignores requests from it and the app records it as a referer:
// config/simplestats-client.php
'own_domains' => [
'www.my-app.com',
],2. Add the script
Add the script to every page through app.head in nuxt.config.ts:
export default defineNuxtConfig({
app: {
head: {
script: [
{ src: 'https://app.my-app.com/assets/v.js', defer: true },
],
},
},
})Or with useHead in app.vue:
<script setup>
useHead({
script: [
{ src: 'https://app.my-app.com/assets/v.js', defer: true },
],
})
</script>The script also reports client-side navigations, so you do not need to call anything on route changes.
Good to know
- Replace
app.my-app.comwith the domain of your Laravel app. If you changed the beacon path (SIMPLESTATS_BEACON_PATH), adjust the script path as well. - Marketing site and app on sibling subdomains (
www.my-app.comandapp.my-app.com) work with the defaultsessionstorage. On different registrable domains (my-app.comandmy-app.io, or a preview domain), settracking_storagetocache. - Keep the default
Referrer-Policyon the marketing site, or at leastorigin. Withno-referrerno visitors are counted.
All details and caveats: Marketing site outside Laravel and Headless, SPA & Stateless.
Nuxt as the app frontend
If signup, login and payments happen in the Nuxt app and Laravel only serves the API, switch the client package to the headless setup and add the same script as above:
// config/simplestats-client.php
'middleware_groups' => ['api'],
'tracking_storage' => 'cache',The script also reports client-side route changes. Signup and checkout must call the Laravel API from the browser, not from the Nuxt server, otherwise the registration cannot be linked to the visit. Details and the manual alternative: Headless, SPA & Stateless.