https://github.com/livechat/store-params
Library for storing URL params
https://github.com/livechat/store-params
Last synced: 5 months ago
JSON representation
Library for storing URL params
- Host: GitHub
- URL: https://github.com/livechat/store-params
- Owner: livechat
- License: mit
- Created: 2017-09-28T09:29:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-23T08:56:36.000Z (over 8 years ago)
- Last Synced: 2025-09-20T02:21:17.993Z (9 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 3
- Watchers: 14
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# store-params
store-params is lightweight, vanilla javascript library for storing URL params in cookies, localStorage or sessionStorage
## Getting Started
`npm install store-params --save` or download and insert `store-params.min.js`
```html
var storage = new StoreParams();
```
```html
// Also can pass in optional settings block
var storage = new StoreParams({
storage: 'cookies',
cookieDuration: 14,
cookieDomain: 'www.example.com',
storeUTMs: true,
storeReferrer: true,
include: [
{
param: 'a',
storage: 'varA'
},
{
param: 'b',
storage: 'varB'
}
],
exclude: [
'utm_source'
]
});
```
## Use Cases
### Capturing UTM params
By default library will store all UTM params (utm_medium, utm_campaign, utm_term, utm_content). This can be disabled by setting `storeUTMs` option to `false`.
### Capturing Referrer URL
Also by default library will store referrer URL as `referrer`. It can be disabled by setting `storeReferrer` option to `false`
### Capturing custom URL params
You can store any URL param with this library. Just add list of URL to include option.
```html
// Storing a, b and c params
var storage = new StoreParams({
include: [
{
param: 'a'
},
{
param: 'b'
},
{
param: 'c'
}
]
});
```
## Configuration options
**storage**
Type of storage
```
default: 'cookies'
options: 'cookies', 'localStorage', 'sessionStorage'
```
**cookieDuration**
Cookie duration in days for cookie storage
```
default: 14
options: integer
```
**cookieDomain**
Cookie domain for cookie storage
```
default: location.hostname without www.
options: string
```
**storeUTMs**
Store UTM params
```
default: true
options: boolean (true / false)
```
**storeReferrer**
Store referrer URL
```
default: true
options: boolean (true / false)
```
**include**
List of custom URL params to be stored.
```
default: ''
options: array of objects with param and storage (optional) keys.
Example:
[
{
param: 'a',
storage: 'varA'
}
]
```
**exclude**
Excluded URL params
```
default: ''
options: array of URL params.
Example:
['utm_source', 'utm_medium']
```