Browse Source

Remove Facebook fbclid tracking query param

merge-requests/55/head
Deimos 6 years ago
parent
commit
2b1e3a36c0
  1. 8
      tildes/tests/test_url_transform.py
  2. 13
      tildes/tildes/lib/url_transform.py

8
tildes/tests/test_url_transform.py

@ -48,6 +48,14 @@ def test_other_mobile_subdomain_not_removed():
assert cleaned_url == url
def test_facebook_tracking_removed():
"""Ensure that Facebook's "click tracking" query param is removed."""
url = "https://example.com/?fbclid=qwertyuiopasdfghjkl"
cleaned_url = apply_url_transformations(url)
assert cleaned_url == "https://example.com/"
def test_reddit_tracking_removed():
"""Ensure that Reddit's "share tracking" query params are removed."""
url = "https://www.reddit.com/r/tildes/comments/8k14is/_/?sort=new&st=abcdefgh&sh=1234asd"

13
tildes/tildes/lib/url_transform.py

@ -156,6 +156,19 @@ class TwitterMobileConverter(UrlTransformer):
return parsed_url._replace(netloc="twitter.com")
class FacebookTrackingRemover(UrlTransformer):
"""Remove Facebook's "click tracking" query parameter (fbclid)."""
@classmethod
def apply_transformation(cls, parsed_url: ParseResult) -> ParseResult:
"""Apply the actual transformation process to the url."""
query_params = parse_qs(parsed_url.query, keep_blank_values=True)
query_params.pop("fbclid", None)
return parsed_url._replace(query=urlencode(query_params, doseq=True))
class RedditTrackingRemover(UrlTransformer):
"""Remove Reddit's "share tracking" query parameters (st and sh)."""

Loading…
Cancel
Save