2 * Copyright ©2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
6 * Privacy Browser Android is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser Android is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser Android. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.helpers
22 private val trackingQueriesList = listOf(
23 "__hsfp=", // HubSpot.
24 "__hssc=", // HubSpot.
25 "__hstc=", // HubSpot.
27 "_hsenc=", // HubSpot.
28 "_openstat=", // Yandex.
29 "dclid=", // DoubleClick ID.
30 "fbadid=", // FaceBook Ad ID.
31 "fbclid=", // FaceBook Click ID.
32 "gclid=", // Google Click ID.
33 "hsCtaTracking=", // HubSpot.
34 "igshid=", // Instagram.
35 "mc_eid=", // MailChimp Email ID.
36 "?mkt_tok=", // Adobe Marketo.
37 "ml_subscriber=", // MailerLite.
38 "ml_subscriber_hash=", // MailerLite.
39 "msclkid=", // Microsoft Click ID.
40 "oly_anon_id=", // Omeda Anonymous ID.
41 "oly_enc_id=", // Omeda ID.
42 "rb_clickid=", // Unknown tracker.
43 "s_cid=", // Adobe Site Catalyst.
44 "utm_", // Google Analytics.
45 "vero_conv=", // Vero.
46 "vero_id=", // Vero ID.
47 "wickedid=", // Wicked Reports ID.
48 "yclid=" // Yandex Click ID.
51 class SanitizeUrlHelper {
52 fun sanitizeTrackingQueries(inputUrl: String): String {
53 // Make a copy of the input URL so that it can be modified.
56 // Remove each tracking query from the URL.
57 trackingQueriesList.forEach {
58 if (url.contains("?$it")) { // Check for an initial query
59 // Remove the first query and anything after it.
60 url = url.substring(0, url.indexOf("?$it"))
62 else if (url.contains("&$it")) { // Check for a subsequent query.
63 // Remove the query and anything after it.
64 url = url.substring(0, url.indexOf("&$it"))
68 // Return the sanitized URL.
72 fun sanitizeAmpRedirects(inputUrl: String): String {
73 // Make a copy of the input URL so that it can be modified.
76 // Remove Twitter `amp=1`.
77 if (url.contains("?amp"))
78 url = url.substring(0, url.indexOf("?amp"))
79 else if (url.contains("&"))
80 url = url.substring(0, url.indexOf("&"))
82 // Return the sanitized URL.