https://github.com/robflaherty/firstimpression.js
Micro-library for detecting new users
https://github.com/robflaherty/firstimpression.js
Last synced: over 1 year ago
JSON representation
Micro-library for detecting new users
- Host: GitHub
- URL: https://github.com/robflaherty/firstimpression.js
- Owner: robflaherty
- Created: 2012-03-26T02:34:52.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2013-05-17T14:50:19.000Z (about 13 years ago)
- Last Synced: 2025-03-26T08:07:01.534Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 109 KB
- Stars: 104
- Watchers: 8
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# firstImpression.js
firstImpression is a JavaScript micro-library that answers the question, "Has this visitor been here before?" It's mostly a wrapper for a **plain JS** port of [jquery.cookie](https://github.com/carhartl/jquery-cookie). No other libraries required.
`firstImpression()` returns `true` for a new user, `false` for a returning user. Calling `firstImpression()` also sets a cookie if one does not already exist. The default cookie name is `_firstImpression` and the default expiration is 2 years (730 days).
## Usage
```javascript
// Basic usage
if ( firstImpression() ) {
console.log('New user');
}
// Specify cookie name
if ( firstImpression('foo') ) {
console.log('New user');
}
// Specify cookie name and expiration in days
if ( firstImpression('foo', 365) ) {
console.log('New user');
}
```
## Removing cookies
```javascript
// Remove default cookie
firstImpression(null);
// Remove custom named cookie
firstImpression('foo', null);
```
## Browser Support
This should work in any browser that supports cookies. Tested in Chrome, Firefox, Opera, IE6-10, iOS, Android, and Opera Mobile.
## Contact
[@robflaherty](https://twitter.com/#!/robflaherty)
## License
Licensed under the MIT and GPL licenses.