strip-tracking-params 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/index.js +53 -0
- package/package.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ricco020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# strip-tracking-params
|
|
2
|
+
|
|
3
|
+
Remove common **tracking query parameters** (UTM tags, ad click IDs like `gclid`
|
|
4
|
+
and `fbclid`, email-tracking ids) from a URL, returning a clean one. Runs locally,
|
|
5
|
+
zero dependencies, nothing stored or sent anywhere.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const stripTrackingParams = require('strip-tracking-params');
|
|
9
|
+
|
|
10
|
+
stripTrackingParams('https://example.com/page?utm_source=news&id=42&fbclid=abc');
|
|
11
|
+
// 'https://example.com/page?id=42' (functional params like id are kept)
|
|
12
|
+
|
|
13
|
+
stripTrackingParams('https://shop.com/p?ref=x&gclid=z', { extra: ['ref'] });
|
|
14
|
+
// 'https://shop.com/p'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## What it removes
|
|
18
|
+
|
|
19
|
+
A documented default list: `utm_*`, `gclid`/`gbraid`/`wbraid`/`dclid`,
|
|
20
|
+
`fbclid`, `igshid`, `msclkid`, `ttclid`, `yclid`, `mc_cid`/`mc_eid`, `_hsenc`,
|
|
21
|
+
`mkt_tok` and other common analytics and email trackers. See
|
|
22
|
+
`stripTrackingParams.DEFAULT_PARAMS`.
|
|
23
|
+
|
|
24
|
+
Pass `{ params: [...] }` to replace the list, or `{ extra: [...] }` to add to it.
|
|
25
|
+
|
|
26
|
+
**Honest note:** it only strips query parameters. A non-absolute URL is returned
|
|
27
|
+
unchanged (it cannot be parsed safely without a base), and it does not touch path
|
|
28
|
+
segments or fragments. It reduces tracking, it does not make a link anonymous.
|
|
29
|
+
|
|
30
|
+
## Notes
|
|
31
|
+
|
|
32
|
+
Maintained by the team behind [Priviy](https://www.priviy.com), a data-privacy
|
|
33
|
+
resource. For plain-English guides on trackers, metadata and cloud privacy, see
|
|
34
|
+
[priviy.com](https://www.priviy.com).
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* strip-tracking-params
|
|
5
|
+
* Remove common tracking query parameters (UTM tags, click IDs, email-tracking
|
|
6
|
+
* ids) from a URL, returning a clean URL. Runs locally, no network, no storage.
|
|
7
|
+
* The default list covers widely documented trackers; pass your own if needed.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Widely documented tracking parameters (analytics, ad-click IDs, email trackers).
|
|
11
|
+
var DEFAULT_PARAMS = [
|
|
12
|
+
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_id',
|
|
13
|
+
'utm_name', 'utm_cid', 'utm_reader', 'utm_social', 'utm_brand',
|
|
14
|
+
'gclid', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'gad_source',
|
|
15
|
+
'fbclid', 'igshid', 'twclid', 'yclid', 'msclkid', 'ttclid', 'li_fat_id',
|
|
16
|
+
'mc_cid', 'mc_eid', '_hsenc', '_hsmi', 'vero_id', 'vero_conv',
|
|
17
|
+
'oly_enc_id', 'oly_anon_id', 'wickedid', 'rb_clickid', 's_cid', 'mkt_tok',
|
|
18
|
+
'hsa_acc', 'hsa_cam', 'hsa_grp', 'hsa_ad', 'hsa_src', 'hsa_tgt', 'hsa_kw', 'hsa_mt', 'hsa_ver', 'hsa_net'
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} url
|
|
23
|
+
* @param {object} [options]
|
|
24
|
+
* @param {string[]} [options.params] override the list of parameters to strip
|
|
25
|
+
* @param {string[]} [options.extra] additional parameters to strip on top of the defaults
|
|
26
|
+
* @returns {string} the URL with tracking parameters removed (unchanged if it cannot be parsed)
|
|
27
|
+
*/
|
|
28
|
+
function stripTrackingParams(url, options) {
|
|
29
|
+
if (typeof url !== 'string') { throw new TypeError('url must be a string'); }
|
|
30
|
+
options = options || {};
|
|
31
|
+
var toStrip = options.params ? options.params.slice() : DEFAULT_PARAMS.slice();
|
|
32
|
+
if (options.extra) { toStrip = toStrip.concat(options.extra); }
|
|
33
|
+
var lower = {};
|
|
34
|
+
for (var i = 0; i < toStrip.length; i++) { lower[String(toStrip[i]).toLowerCase()] = true; }
|
|
35
|
+
|
|
36
|
+
var u;
|
|
37
|
+
try { u = new URL(url); }
|
|
38
|
+
catch (e) { return url; } // not an absolute URL: return unchanged rather than guess
|
|
39
|
+
|
|
40
|
+
var keys = [];
|
|
41
|
+
u.searchParams.forEach(function (_v, k) { keys.push(k); });
|
|
42
|
+
for (var j = 0; j < keys.length; j++) {
|
|
43
|
+
if (lower[keys[j].toLowerCase()]) { u.searchParams.delete(keys[j]); }
|
|
44
|
+
}
|
|
45
|
+
// Drop a trailing "?" if no params remain.
|
|
46
|
+
var out = u.toString();
|
|
47
|
+
if (u.search === '' && out.charAt(out.length - 1) === '?') { out = out.slice(0, -1); }
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
stripTrackingParams.DEFAULT_PARAMS = DEFAULT_PARAMS.slice();
|
|
52
|
+
module.exports = stripTrackingParams;
|
|
53
|
+
module.exports.stripTrackingParams = stripTrackingParams;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "strip-tracking-params",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Remove common tracking query parameters (UTM tags, gclid, fbclid, email trackers) from a URL. Local, zero dependencies, privacy-friendly.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"scripts": { "test": "node test.js" },
|
|
8
|
+
"keywords": ["tracking", "utm", "privacy", "url", "gclid", "fbclid", "clean-url", "detrack"],
|
|
9
|
+
"homepage": "https://www.priviy.com",
|
|
10
|
+
"author": "ricco020",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": { "node": ">=12" },
|
|
13
|
+
"files": ["index.js", "README.md", "LICENSE"]
|
|
14
|
+
}
|