]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/helpers/SanitizeUrlHelper.kt
7e4ad981f017ede460e2628a9f728355a34d8f22
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / SanitizeUrlHelper.kt
1 /*
2  * Copyright ©2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacybrowser.helpers
21
22 private val trackingQueriesList = listOf(
23     "__hsfp=",             // HubSpot.
24     "__hssc=",             // HubSpot.
25     "__hstc=",             // HubSpot.
26     "__s=",                // Drip.com.
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.
49 )
50
51 class SanitizeUrlHelper {
52     fun sanitizeTrackingQueries(inputUrl: String): String {
53         // Make a copy of the input URL so that it can be modified.
54         var url = inputUrl
55
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"))
61             }
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"))
65             }
66         }
67
68         // Return the sanitized URL.
69         return url
70     }
71
72     fun sanitizeAmpRedirects(inputUrl: String): String {
73         // Make a copy of the input URL so that it can be modified.
74         var url = inputUrl
75
76         // Remove Twitter `amp=1`.
77         if (url.contains("?amp"))
78             url = url.substring(0, url.indexOf("?amp"))
79         else if (url.contains("&amp"))
80             url = url.substring(0, url.indexOf("&amp"))
81
82         // Return the sanitized URL.
83         return url
84     }
85 }