A Go module that analyzes and classifies different kinds of referrer URLs (search, social, ...).
package main
import (
"fmt"
"github.com/Shopify/goreferrer"
)
var urls = []string{
"http://ca.search.yahoo.com/search?p=hello",
"https://twitter.com/jdoe/status/391149968360103936",
"http://yoursite.com/links",
}
func main() {
for _, url := range urls {
r := goreferrer.DefaultRules.Parse(url)
switch r.Type {
case goreferrer.Search:
fmt.Printf("Search %s: %s\n", r.Label, r.Query)
case goreferrer.Social:
fmt.Printf("Social %s\n", r.Label)
case goreferrer.Indirect:
fmt.Printf("Indirect: %s\n", r.URL)
}
}
}
Result:
Search Yahoo: hello
Social Twitter
Indirect: http://yoursite.com/links