#links #parse-url #url

untrack

Library to parse and remove tracking tokens from URLs contained in arbitrary text input

6 releases

0.1.5 Jul 28, 2024
0.1.4 Jul 26, 2024

#1318 in Parser implementations

Download history 161/week @ 2024-07-19 282/week @ 2024-07-26 14/week @ 2024-08-02 3/week @ 2024-08-09 1/week @ 2024-08-16 1/week @ 2024-08-30 14/week @ 2024-09-13 43/week @ 2024-09-20 12/week @ 2024-09-27 3/week @ 2024-10-04

212 downloads per month

MIT license

30KB
676 lines

untrack crate

This crate is intended to remove tracking tokens from URLs contained in any text input. The crate can either substitute the URLs in place or return a Vec of cleaned urls to a given text input.

Usecase

Removing tracking tokens can improve the privacy of the user sharing the link containing the tokens and the consumer opening the shared link.

Supported tracking tokens

The crate currently supports Twitter, X, YouTube, Instagram, Substack and Spotify tracking tokens. The exact tokens can be found in src/parsing_params.rs.

Example usage

fn clean_urls_from_any_text(input: &String) -> Option<Vec>

let input = 
String::from("Twitter link: https://twitter.com/user/status/123?utm_source=test&s=1234");

let expected = vec!["https://twitter.com/user/status/123".to_string()];

assert_eq!(clean_urls_from_any_text(&input), Some(expected));

fn replace_urls_in_place(input: &mut String) -> Option<&mut String>

let mut input = String::from("Multiple URLs: https://twitter.com/user/status/123?s=12 and https://www.youtube.com/watch?v=abc&feature=share");

let result = replace_urls_in_place(&mut input);

assert!(result.is_some());

assert_eq!(input, "Multiple URLs: https://twitter.com/user/status/123 and https://www.youtube.com/watch?v=abc");

Dependencies

~2.3–3.5MB
~59K SLoC