Skip to content

Cookies

VisitCookie

The VisitCookie object holds vital information about the cookie we wish to set, as well as providing some utility functions.

init()

The object is initialised with values for:

  • name: usually vscr_vid or vscr_sid depending on whether this is a visitor cookie or a session cookie
  • value: the visitor_id or session_id
  • expires: defaults to arrow.now() but is passed a datetime based on the type of cookie (two years for visitor cookies, thirty minutes for session cookies)
  • path: defaults to / (usually home) but can be configured with the path denoting the page from which the cookie is set
  • domain: the domain from which the cookie is set
  • max_age: defaults to 1800 but can be configured
  • secure: defaults to True and should always be set that way

set_on_response()

Takes the values set on init() and uses the set_cookie() function from Python's requests library to set the cookie on the browser when the response is set.

to_json()

Straightforwardly, this serialises the name, value, expires, domain and path values into a JSON format.

ThirdPartyVisitCookie

This class extends the VisitCookie class - the only difference is when setting the response the samesite parameter is set to None.