API Documentation: visitor.session

Current Session

The session property holds information on the current session. A session is a period of interaction between the visitor's browser and your website, ending when the visitor closes the browser or remains inactive for 30 minutes.

Technically, the visitor.js script uses two cookies to store information on the visitor's sessions:

Name Description Expiration
_vjs_id This cookie is created upon the first visit to the website and stores the following values: number of visits/sessions so far, timestamp of the visitor's first visit, and referring URL for the first visit. 2 Years from last update.
_vjs_ses This cookie is used to establish and continue a user session with the website. It stores the following information: entry page where the visitor first landed in the current session, timestamp when the session started, and referring URL for the session. 30 minutes from last update.
visitor.session.entryPage
  • Gets a dictionary object that represents the URL of the first page that the visitor landed on in the current session. The object contains the following properties, each representing a component of the URL:
Key Description
fullUrl The original URL.
scheme The scheme name such as 'http' or 'https'.
authority The user information part terminated with '@' (e.g. username:password@), the hostname, and the port number preceded by a colon ':'.
userInfo The user name and the password separated by a colon.
user The user name used for authentication.
pass The password used for authentication.
host The hostname (ip address or domain name).
port The port number.
relative The complete right part of the URL beginning with '/' and consisting of the path, query and fragment.
path The path component of the URL consisting of the directory and the file name.
directory The directory component of the path.
file The file name component of the path.
query The query part beginning with a question mark ('?').
fragment The fragment part beginning with a hash ('#').
  • Example Value:
    URL Components
  • Example Usage:
if (visitor.session.entryPage.host) {
	alert("You have been referred to this website from " +
	      visitor.session.entryPage.host + ".");
}
visitor.session.sessionStart
  • Gets the date and time the visitor landed on the website in the current session.
  • Data Type: Date
  • Example Usage:
// Calculate the difference in minutes between the current time and the
// time the visitor first arrived at the website
var minutesOnSite = Math.floor((new Date() - visitor.session.sessionStart) / 1000 / 60);

// Output the result
alert("You have been " + minutesOnSite + " minutes on this website.");
visitor.session.referral.url
  • Gets a dictionary object that represents the URL of the website that referred the visitor in the current session.
  • For a list of properties of the URL object, please see the documentation of the visitor.session.entryPage variable.
visitor.session.referral.search.engine
  • Gets the name of the search engine that referred the visitor in the current session.
  • Data Type: String
  • Default Value: '' (if the visitor didn't use a search engine to find the website or the search engine used is unknown)
  • Possible Values: 'Google', 'Bing', 'Yahoo', 'AOL', 'Ask', 'Lycos', 'Baidu', 'Yandex', ''
visitor.session.referral.search.query
  • Gets the full search query the visitor used to arrive at the website in the current session.
  • Data Type: String
  • Default Value: '' (if no search query is available)
  • Example Values: 'GeoLocation JavaScript', '"Search Query" EXAMPLE'
visitor.session.referral.search.terms
  • Gets an array of keywords used in the search query that brought the visitor to the website. All keywords are converted to lowercase.
  • Data Type: Array of Strings
  • Default Value: [] (if no search query is available)
  • Example Value: ['search query', 'example'] for the search query '"Search Query" EXAMPLE'
visitor.session.visitCount
  • Gets the number of times (including the current session) the visitor has visited the site.
  • Data Type: Integer
  • Example Value: 3 (meaning that this is the third visit to the website)