An open API service indexing awesome lists of open source software.

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

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']
```