Online Store Product Page Live Visitor Tracker - Wix Stores & Corvid Stores

#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 :rofl::rofl: although this is clever to be honest, they might have gotten away with it if they did this on a backend file.

Yeah putting that in the backend would have been a better thing :stuck_out_tongue:

I think what you describe would better fit the realtime API. I’m not an expert on realtime but you could do something like:

  1. Create one channel per product.

  2. Every time a user displays a product subscribe him to the product channel

  3. Every time someone subscribes to the product channel add a record to the collection “trackers” (timestamp, productID). (I don’t think you need to store the user ID)

  4. Then count all the trackers that have the same productID as the new subscriber and with timestamps less than 3 minutes,

  5. Notify all subscribe with the new count.

  6. On the product page, listen to the realtime API and filter the message for the current productID

There is probably a more efficient way to use the realtime API but at least, you’ll have the most realistic feature ever. The counter will live update as more people come around.

What do you think?

I haven’t started using realtime, will take a look at it and update.