feed-to-muc/removetracking.go

43 lines
1.1 KiB
Go
Raw Normal View History

/* 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) {
// Perfom a get request to get rid of 301 forwarding through
// services like feedproxy.google.com.
resp, err := http.Get(input)
if err != nil {
return input, err
}
// Remove the URL part starting with "?utm_", which is
// used for tracking purposes.
output = strings.Split(resp.Request.URL.String(), "?utm_")[0]
// Remove the URL part starting with "?wt_", which is
// used for Webtrekk tracking.
output = strings.Split(output, "?wt_")[0]
// Remove the URL part starting with "#ref=", which is
// used for tracking the referer by some feeds.
output = strings.Split(output, "#ref=")[0]
// Remove the URL part starting with "?ref=", which is
// used for tracking the referer by some feeds.
output = strings.Split(output, "?ref=")[0]
// Remove the URL part starting with "?pk_", which is
// used for tracking purposes.
output = strings.Split(output, "?pk_")[0]
return output, err
}