SkillAgentSearch skills...

FirstImpression.js

Micro-library for detecting new users

Install / Use

/learn @robflaherty/FirstImpression.js
About this skill

Quality Score

0/100

Supported Platforms

Universal

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. 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

// 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

// 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

License

Licensed under the MIT and GPL licenses.

View on GitHub
GitHub Stars104
CategoryDevelopment
Updated2mo ago
Forks11

Languages

JavaScript

Security Score

80/100

Audited on Jan 16, 2026

No findings