Code Monkey home page Code Monkey logo

session.js's Introduction

Session.js

Gives information about the current session.

To use: include the file session.js, then access the visitor object. It uses the google javascript loader to get location data. For async loading, use the window.session_loaded callback.

Live Demo

Configurable options are below.

Usage:

Include session.js in the head or footer.

Download/Linking:

Edge: uncompressed, compressed

Lock version to v0.4: uncompressed, compressed.

If used in the footer (before the </body> tag), you can use the window.session_loaded = function(session){} callback).

API demo dump of window.session:

{
  "api_version": 0.4,
  "locale": {
    "country": "us",
    "lang": "en"
  },
  "current_session": {
    "visits": 1,
    "start": 1326068806791,
    "last_visit": 1326068806791,
    "url": "http://codejoust.github.com/session.js/",
    "path": "/session.js/",
    "referrer": "",
    "referrer_info": {
      "host": "codejoust.github.com",
      "path": "/session.js/",
      "protocol": "http:",
      "port": 80,
      "search": "",
      "query": {}
    },
    "search": {
      "engine": null,
      "query": null
    }
  },
  "original_session": {
    "visits": 14,
    "start": 1326032481755,
    "last_visit": 1326068806793,
    "url": "http://codejoust.github.com/session.js/",
    "path": "/session.js/",
    "referrer": "",
    "referrer_info": {
      "host": "codejoust.github.com",
      "path": "/session.js/",
      "protocol": "http:",
      "port": 80,
      "search": "",
      "query": {}
    },
    "search": {
      "engine": null,
      "query": null
    }
  },
  "browser": {
    "browser": "Chrome",
    "version": 16,
    "os": "Mac"
  },
  "plugins": {
    "flash": true,
    "silverlight": true,
    "java": true,
    "quicktime": true
  },
  "time": {
    "timezone": "EST",
    "tz_offset": -5,
    "observes_dst": true
  },
  "device": {
    "screen": {
      "width": 1280,
      "height": 1024
    },
    "viewport": {
      "width": 1063,
      "height": 860
    },
    "is_tablet": false,
    "is_phone": false,
    "is_mobile": false
  },
  "location": {
    "latitude": 35.046,
    "longitude": -85.31,
    "address": {
      "city": "Chattanooga",
      "region": "TN",
      "country": "USA",
      "country_code": "US"
    },
    "source": "google"
  }
}
### Options: Set `window.session` before including `session.js` to change options and define a location callback. Default options are shown below.

ipinfodb.com location demo.

Synchronous information (everything but location not cached in a cookie), is available immediately after including session.js.

window.session = {
  options: {
  // Default Settings Example
    // Use the HTML5 Geolocation API
    // this ONLY returns lat & long, no city/address
    use_html5_location: false,
    // Attempts to use IPInfoDB if provided a valid key
    // Get a key at http://ipinfodb.com/register.php
    ipinfodb_key: false,
    // Leaving true allows for fallback for both
    // the HTML5 location and the IPInfoDB
    gapi_location: true,
    // Name of the location cookie (set blank to disable cookie)
    //   - WARNING: different providers use the same cookie
    //   - if switching providers, remember to use another cookie or provide checks for old cookies
    location_cookie: "location",
    // Location cookie expiration in hours
    location_cookie_timeout: 5,
    // Session expiration in days
    session_timeout: 32,
    // Session cookie name (set blank to disable cookie)
    session_cookie: "first_session"
    };
  },
  start: {
    // Session location loaded.
  }
}

session.js's People

Contributors

jhermsmeier avatar

Stargazers

Michael Le Du avatar

Watchers

James Cloos avatar Michael Le Du avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.