#wixStores #onlineStore #productPage
Interested in finding possible ’ non-deceptive ’ ways to have a feature like ’ x people are viewing this item ’ for either Wix Stores product pages or any Custom Corvid Store product pages we create using database collections and dynamic pages?
I was thinking we create an item in the database every-time a user lands on the page and save the user id, product id and the current unix timestamp. Each 30-40 seconds the page updates the timestamp based on the user id using a setInterval() function.
We can then have a job scheduler running every minute (yeah I know but there is a workaround to run jobs almost every minute on a site) which will clear out items older than 60-70 seconds than the current timestamp. If the user left the page, the unix timestamp will not be updated.
On the page, a query runs every 10 seconds updating the count on the page based on the items in the liveUsers database. Although I feel this is not the proper way to do it, its too ‘heavy’ and will involve 3rd party API integration along with using the Wix Data API to make network calls so I was looking for a much ‘lighter’ solution which will not consume so many resources.
Not talking about what the developer in the screenshot did although this is clever to be honest, they might have gotten away with it if they did this on a backend file.