Create a test Server Action, and put there:
Set Value env = {{$_ENV}}
Set Value server = {{$_SERVER}}
Try to find the current (sub)domain in one of those variables, so there you have how to find the current subdomain being accessed.
On your DNS provider you have to make a wildcard DNS entry (like *.example.com) to point to your server’s IP address.
If you click on Globals, these are Steps that run on every page. There, check the current subdomain (from variable like $_SERVER.something), do a database query to get the business_id from the subdomain string
Now you have access to business_id on every page