Node.js process receiving all incoming call from Javascript Shopboard tracking code
JavaScript Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
db
referrer
routes
.gitignore
Procfile
README.md
app.js
heroku.sh
package.json

README.md

Shopboard is a real time dashboard showing which visitors are browsing in your ecommerce, what they have in there carts, and allow the shop owner to initiate a conversation using third-party live chats like Olark or Snap Engage.

shopboard/tracer is the backend tracking all the visitors on websites using Shopboard.

Routes

The app.js file creates a webserver to listen the following routes:

  • /v1/track called by Shopboard JavaScript client each time a new page is loaded in the client browser
  • /v1/ping called every 10 seconds by the Shopboard JavScript client while the user is active on a website (there is a timeout in the client which stops pinging the tracker)
  • /monitor for monitoring purpose (Pingdom)

Storage

There is no persistent storage in Shopboard, by design. Every tracking hit updates a Redis store with visitor information. It uses the following keys (see details in db/index.js):

  • c:#{trackingCode}:d:#{YYYYMM}:vid is a unique key incremented (via INCR) each time a new visitor is found. This is specific to each shop on Shopboard (with the trackingCode variable) and reset every month (hence the YYYYMM).
  • c:#{trackingCode}:d:#{YYYYMMDDHHmmss}:activity, with ss = secondes mod 5, is the key tracking all activity for a given shop aggregated by 5 seconds blocks. For each visitor found in these 5 seconds, we SADD them to this key. This way, with a SUNION, we can get all visitors seen in the last 15 seconds, by merging the visitor ids of the last 3 chunks of 5 seconds.
  • c:#{trackingCode}:v:#{visitorId} is the key for a hash storing properties for a visitor, like the number of pages views, the timestamp the first time it was seen, tags, his current state (reading, writing, idle), etc...
  • chat:c:#{trackingCode}:v:#{visitorId} is a special key storing chat information about the visitor (is there Olak enabled? has the chat begun?)

Referrer

Once valuable information when looking at the Shopboard Dashboard is to know from where the visitors are coming. We do so by analysing and parsing the document.referrer javascript variable with a special module. You can have a close look at it here.