I need to add a live view count to my page on bubble, I need to add +1 to a data field when the page is loaded and -1 when the page is closed, How can i achieve this on bubble?
thank you
The first part is easy, create a ‘page-views’ thing and store the url, date and user in it. Use the ‘on page load’ to add a record to it only when that user, url and date don’t exist. That’ll prevent someone from refreshing the page 5 times making it look like there are 5 users looking at that page.
to remove, that’s tricky. If it’s a public site and users aren’t logged in, you could do a count on that ‘page-views’ table where the user unique-id is not empty. Anonymous user unique-id’s expire after a day or two (I think), so that’s not optimal, but I don’t think there’s a method for knowing when a user leaves a page, or closes the window.
I use something like this on my site, but it’s a just a “8 users today” type of thing, not a live view.
Thank you for your tips, It’s really the removing part is that is tricky for me, in my site a user can create a profile and they can share it anybody with a link so anyone with the link can view without having to login. I need a way to figure out how many people are watching live.
This is not a simple problem to solve. I would suggest installing Google Analytics (there’s an official plugin here) and use the Live View on GA. It shows the currently active users on your site.
if the users are not logged in and you still need to get “unique users” you could use an IP plugin to roughly unique them.
Add on page load is easy enough.
Remove on page close is a bit tricky but should be achievable using some custom JS and a backend workflow.
You’d need a backend workflow because the browser will not hold itself open for the workflow on the frontend to complete if the user closes it.
Possibly using the beforeunload or unload event in JS could achieve the “on close” trigger, although I haven’t tested it in bubble.
If it was me I’d be looking for a 3rd party app/plugin that handled this as it could use a lot of WU in bubble to track users like this.
If you just needed “number of users today” then a simpler approach could work.
User loads the page, write the log of user loading the page (one time), then do a search for all page loads for current date to get todays count.
Method 1 where you add and remove users gives you a live count that always changes based on open/close of the tab. This uses a lot of WU.
Method 2 writes opens only and is much more lightweight but doesn’t give a “live” count but instead a daily total unique users count.
Is there any lightweight plugin or tool you’d recommend for tracking live page views in Bubble without heavily relying on workflows or custom JavaScript?
thank you, i will take a look
Yes you’re right the page load is easy it’s the page unload which is tricky, Basically what I am trying to achieve here is to run a backend API call for a user if that specific user’s profile has at least 1 viewer, to display live results, this way the API call is only happening if someone is looking at their profile. Alternatively I tried to run the API call in the front end but this uses way too many WU and if multiple people are looking at the same profile it’s not feasible. I’m still looking for a solution, thank you.
There was a plugin for online, offlne users. I used it very long time ago so cant remember exactly how ot worked.
What i roughly remember that i used a cookie plugin and i used to write the current user ip address and save it in my database ( in case its anonymous user). The app detect the user activity as well ( if they don’t move or interact with page for certain seconds it tells you live) it also tells you when user close the browser event.
Just be mindful, workflows in page load can lead to big workload but if the app achieve live data to your customer maybe it work better.
I am not entirly sure tho lol