tracking-params

Easily get and remove unwanted tracking parameters from URLs.

Usage no npm install needed!

<script type="module">
  import trackingParams from 'https://cdn.skypack.dev/tracking-params';
</script>

README

Tracking Params Build Status Bundle Size

Easily get and remove unwanted tracking parameters from URLs.

This project was inspired by neat-url, but includes more functionality by returning detailed info along with the cleaned URL.

Installation

npm install tracking-params

Usage

const { cleanUrl, getTrackingData } = require('tracking-params');

const url = 'https://example.com?ok=ok';
const dirtyUrl = url + '&utm_term=term';

console.log(cleanUrl(url));
// 'https://example.com?ok=ok'

console.log(cleanUrl(dirtyUrl));
// 'https://example.com?ok=ok'

console.log(getTrackingData(url));
// {
//   url: 'https://example.com?ok=ok',
//   isDirty: false,
//   trackingParams: [],
//   cleanUrl: 'https://example.com?ok=ok'
// }

console.log(getTrackingData(dirtyUrl));
// {
//   url: 'https://example.com?ok=ok&utm_term=term',
//   isDirty: true,
//   trackingParams: [
//     { key: 'utm_term', value: 'term' }
//   ],
//   cleanUrl: 'https://example.com?ok=ok'
// }