How to Track Unique User Visits and Match with Purchases in Laravel
App\Models\Traffic.php
cast the “data” to “json” or “array”. In the data column we will store all request params, in case if some of them were not listed separately, to have everything collected.
url
we will store the current page url without query params.ref
, utm_medium
, utm_source
, utm_campaign
columns will contain the values from the eponymous query params.referer
- we will store HTTP_REFERER to know from which website user camedata
column will contain an array of all query params from the url.uuid
column will be the unique identifier for the user, will talk about it more belowbootstrap/app.php
file
app/Http/Kernel.php
file’s web middleware group
uuid
and store it in session.
I prefer to store it for 30 days, as users do not buy immediately, we still want to know from where they visited website for the first time.
Feel free to change that to any days you want.
uuid
that we stored in session.
LemonSqueezy checkout url accepts custom params, so we will pass the uuid
to the checkout url and LemonSqueezy will return it back to us in the webhook.
uuid
from session and pass to the checkout url.
uuid
in the lemon_squeezy_orders table.
Add new column to the lemon_squeezy_orders
table.
uuid
to the order.