For this challenge, we are building an server that returns a tracking pixel and records analytics that are sent along with that request.
Build out the server and improve the front end code to make this all work
Suppose we have a link:
<a href='/some-where' id='some-where'>A link to somewhere</a>An analytics handler written (feel free to redesign):
function onClickHandler (a) {
a.addEventListener('click', () => {
trackClick(Math.random().toString(36).slice(2), a.href)
}
}
function trackClick (id, href) {
new Image(`https://.gif?id=${id}&href=${encodeURIComponent(href)}`)
}A microservice that receives pixels and serves analytics queries. The queries (reads) may be behind the writes due to how the system/database is built–let's assume reads are 1 minute behind writes.
Fires a pixel.
Returns 200 status code with an empty gif as the body.
curl -X POST https://.gif?id=1234&href=https://google.comReturns all click events within the specified query.
Query parameters:
id- by idevent- by event typebefore- before a UNIX timestampafter- after a UNIX timestamp
curl https://?id=1234- I recommend using sqlite or even just a json file database to reduce overhead