https://github.com/bufferapp/buffer-js-utms
Functions to extract UTM parameters with expiration
https://github.com/bufferapp/buffer-js-utms
Last synced: 11 months ago
JSON representation
Functions to extract UTM parameters with expiration
- Host: GitHub
- URL: https://github.com/bufferapp/buffer-js-utms
- Owner: bufferapp
- Created: 2019-11-11T11:25:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-11T12:40:57.000Z (about 6 years ago)
- Last Synced: 2025-02-01T11:35:44.178Z (12 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Buffer's UTM extracting helper fuctions
This module offers some basic logic to extract UTM parameters from the
query string. It returns them in a simple data structure that includes a
TTL so that we can define when to discard the found UTM parameters
This module is currently shared between `buffer-login` and `buffer-marketing`
to handle UTM tracking in a consistent way
## Install
```
npm install @bufferapp/utms --save
```
## Usage
The main API to this module is `refreshUtms(query, previousUtms)`, it takes
the curret query parameters (object) and the previous value returned by this
function (which includes both the extracted UTMs and the TTL info)
This package does not take care of storing previous UTMs, a simple way to use
it is by storing them in the users session:
```
const { refreshUtms } = require('@bufferapp/utms')
middleware.trackUtm = (req, res, next) => {
req.session.utms = refreshUtms(req.query, req.session.utms)
next()
}
```
With the above middleware, the currently valid UTMs for the request would be available
in `req.session.utms.values`