2018-08-03 11:02:31 +02:00
|
|
|
/* Copyright 2018 Martin Dosch
|
|
|
|
Licensed under the "MIT License" */
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Remove tracking parameter from URLs
|
|
|
|
func removeTracking(input string) (output string, err error) {
|
|
|
|
|
2022-08-21 12:07:30 +02:00
|
|
|
// Perform a get request to get rid of 301 forwarding through
|
2018-08-03 11:02:31 +02:00
|
|
|
// services like feedproxy.google.com.
|
|
|
|
resp, err := http.Get(input)
|
|
|
|
if err != nil {
|
|
|
|
return input, err
|
|
|
|
}
|
|
|
|
|
2019-05-31 12:48:03 +02:00
|
|
|
output = resp.Request.URL.String()
|
2018-08-03 11:02:31 +02:00
|
|
|
|
2019-05-31 12:48:03 +02:00
|
|
|
// Remove the URL part starting with known tracking parameters.
|
|
|
|
trackingParameters := [6]string{"?utm_", "?wt_", "#ref=", "?ref=", "?pk_", "?source="}
|
2018-08-03 11:02:31 +02:00
|
|
|
|
2019-05-31 12:48:03 +02:00
|
|
|
for _, trackingParameter := range trackingParameters {
|
|
|
|
output = strings.Split(output, trackingParameter)[0]
|
|
|
|
}
|
2018-09-09 19:13:16 +02:00
|
|
|
|
2018-08-03 11:02:31 +02:00
|
|
|
return output, err
|
|
|
|
}
|