dothiv/clickcounter-backend — pull request #5 by coderbyheart (2014-05-06 21:14:56+00:00)
Title: feat(counting): refactor the way counting works

The current implementation increases the number of visits for a domain if
- the request is made by the base script `from=outside`
- and it is the first time a user visits the domain `firstvisit=true`

This is **not** how we want to count visits to .HIV domains.

We want to count **every** visit to a .HIV domain within a configurable threshold between consecutive visits.

As we are currently not storing user state in the backend we require clients (the banners) to send information about recurring users. In order to be flexible about the threshold and adapt our counting backend in the feature without needing to change the request the following changes have been made to the request:
- clients **MUST** send the timestamp of the visit in the parameter `ct`, e.g. `ct=1397341234000`
- clients **SHOULD** send the timestamp of the previous visit in the parameter `pt`, e.g. `ct=1397340001000`. If it cannot be determined they must send an empty value: `pt=`. Clients should use cookies with a lifetime of 30 days to track the last visit.

For simplicity timestamps are expressed as integers (unix timestamps in **microseconds**) in the users timezone.

If the previous timestamp *is present*, we calculate the diff in seconds and if it is greater than the configured threashhold, we count a click. If the previous timestamp *is not present* we count a click.

The new format makes request parameters absolut thus enabling us in the future to drop already applied request or enable throttling mechanisms based on the time.