diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3080ecd --- /dev/null +++ b/LICENSE @@ -0,0 +1,6 @@ +session.js 0.4.1 +(c) 2012 Iain, CodeJoust +session.js is freely distributable under the MIT license. +Portions of session.js are inspired or borrowed from Underscore.js, and quirksmode.org demo javascript. +This version uses google's jsapi library for location services. +For details, see: https://github.com/codejoust/session.js diff --git a/README.md b/README.md index 3ea4b93..5408329 100644 --- a/README.md +++ b/README.md @@ -7,53 +7,105 @@ 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 +[Live API Demo](http://go.iain.in/sessionjslivedemo01) | [Example Usage Page](http://go.iain.in/sessionjslivedemo02) -To add more fields, add or remove included modules and options near the bottom of the js file. +Configurable options are below. ### Usage: Include `session.js` in the head or footer. -If used in the footer (before the `
+Script Output:
++ loading... ++ + + + + + + + + + +
` tag), you can use the `window.session_loaded = function(session){}` callback).
+#### Download/Linking:
+Recommended:
+[Api v0.4 Uncompressed](http://codejoust.github.com/session.js/session-0.4.js)
+
+Quick Example:
+
+```html
+
+
+```
+
+#### Other Source Options:
+Lock version to v0.4 (current stable):
+[uncompressed](http://codejoust.github.com/session.js/session-0.4.js),
+[compressed](http://codejoust.github.com/session.js/session-0.4.min.js).
+
+Edge:
+[uncompressed](http://codejoust.github.com/session.js/session.js),
+[compressed](http://codejoust.github.com/session.js/session.min.js)
+
+
+If used in the footer (before the `` tag), you can use the `window.session = {start: function(sess){ /* loaded session data */ }}` callback, before including the session.js. This is recommended when using session.js with location data.
### API demo dump of `window.session`:
```js
{
- "api_version": 0.2,
+ "api_version": 0.4,
"locale": {
- "country": "US",
+ "country": "us",
"lang": "en"
},
- "cur_session": {
+ "current_session": {
"visits": 1,
+ "start": 1326170811877,
+ "last_visit": 1326170811877,
+ "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
- },
- "referrer": "",
- "url": "http://localhost:8000/",
- "path": "/",
- "start": 1325915913173,
- "last_visit": 1325915913173
+ }
},
- "orig_session": {
- "visits": 75,
+ "original_session": {
+ "visits": 29,
+ "start": 1326032481755,
+ "last_visit": 1326170811879,
+ "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
- },
- "referrer": "http://localhost:8000/",
- "url": "http://localhost:8000/test_visitor.html",
- "path": "/test_visitor.html",
- "start": 1325886709703,
- "last_visit": 1325915913175
+ }
},
"browser": {
"browser": "Chrome",
"version": 16,
- "OS": "Mac"
+ "os": "Mac"
},
"plugins": {
"flash": true,
@@ -61,17 +113,21 @@ If used in the footer (before the `` tag), you can use the `window.sessio
"java": true,
"quicktime": true
},
+ "time": {
+ "tz_offset": -5,
+ "observes_dst": true
+ },
"device": {
"screen": {
"width": 1280,
"height": 1024
},
"viewport": {
- "width": 1206,
- "height": 816
+ "width": 1230,
+ "height": 952
},
- "is_phone": false,
"is_tablet": false,
+ "is_phone": false,
"is_mobile": false
},
"location": {
@@ -87,29 +143,45 @@ If used in the footer (before the `` tag), you can use the `window.sessio
}
}
```
-
+
### Options:
-Set `window.session_opts` before including `session.js` to change 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](http://codejoust.github.com/session.js/ipinfodb_demo.html).
+
+Synchronous information (everything but location not cached in a cookie),
+is available immediately after including session.js.
+
```js
-window.session_opts = {
- use_html5_location: false,
- // use html5 location -- this _ONLY_ return lat/long, not an city/address
- ipinfodb_key: null,
- // attempts to use ipinfodb if provided a valid key -- get a key at http://ipinfodb.com/register.php
- gapi_location: true,
- // leaving true allows for fallback for both the html5 location and the ipinfodb
- session_days: 32,
- // how many days session information is kept in a cookie
- location_cookie_name: 'location',
- // the name of the location cookie
- // -- warning: different providers use the same cookie
- // -- if switching providers, remember to use another cookie or provide checks for old cookies
- session_cookie_name: 'first_session',
- // session cookie name
- location_cookie_hours: 2
- // lifetime of the location cookie
-};
+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: function(session){
+ // Session location loaded into window.session and first argument.
+ }
+}
```
+
diff --git a/debug.html b/debug.html
new file mode 100644
index 0000000..928e9d4
--- /dev/null
+++ b/debug.html
@@ -0,0 +1,240 @@
+
+
+
+
+ + + + + + +
+