feed-to-muc/removetracking.go

32 lines
721 B
Go
Raw Permalink 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
}
output = resp.Request.URL.String()
// Remove the URL part starting with known tracking parameters.
trackingParameters := [6]string{"?utm_", "?wt_", "#ref=", "?ref=", "?pk_", "?source="}
for _, trackingParameter := range trackingParameters {
output = strings.Split(output, trackingParameter)[0]
}
return output, err
}