hasjob
hasjob copied to clipboard
Moving anon user tracking from image element to form submit
Anytime the site is loaded and there is -
- a scroll event
- a mouse pointer move event
the anon user session is set using a form submit.
Fixes #409.
@iambibhas Here is how this is supposed to work.
First, we recognise three states for a user's identity:
- Unknown: We know nothing about this client. It's new, and it could be a bot or a user, but we don't know yet.
- Anon User: The client is behaving like a user using a browser, so we believe this is a human.
- User: The user has explicitly logged in.
When the user transitions from stage 2 to stage 3, we want to preserve their browsing history. This is why we do g.anon_user.user = g.user
following which we set g.anon_user = None
. The session is retained on the anon user account, because the browsing activity was anonymous, but we link the anon user account to the regular user account for future use (it's meant for keeping track of A/B test behaviour: if they were shown A or B before they logged in, we need to remember which one they were shown even after they logged in).
The transition from stage 1 to 2 is trickier. At stage 1, it could be a scraping bot causing a lot of traffic. We don't want to track session history for that, but we also don't want to lose the history of a client that turns out to be an anon user. Therefore:
- Assign a probe cookie
session['au'] = uuid4()
to every incoming request. - Create a non-persistent EventSession and give it the same user id. Save it to Redis cache with a 5 minute timeout.
- When the anonsession API endpoint is called (previously, the sniffle endpoint), create an AnonUser account with the same userid, retrieve the session from cache, and now save it to the database.
A bot will also create a Redis EventSession entry, but it will be auto-discarded in five minutes.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.