goreferrer

package module
v0.0.0-...-ec9c9a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 6 Imported by: 0

README

goreferrer

A Go package that analyzes and classifies different kinds of referrer URLs (search, social, ...).

Build Status

Example

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadJsonDomainRules

func LoadJsonDomainRules(reader io.Reader) (map[string]DomainRule, error)

Types

type DomainRule

type DomainRule struct {
	Type       ReferrerType
	Label      string
	Domain     string
	Parameters []string
}

type GoogleSearchType

type GoogleSearchType int
const (
	NotGoogleSearch GoogleSearchType = iota
	OrganicSearch
	Adwords
)

func (GoogleSearchType) String

func (g GoogleSearchType) String() string

type Referrer

type Referrer struct {
	Type       ReferrerType
	Label      string
	URL        string
	Subdomain  string
	Domain     string
	Tld        string
	Path       string
	Query      string
	GoogleType GoogleSearchType
}

func (*Referrer) Host

func (r *Referrer) Host() string

func (*Referrer) RegisteredDomain

func (r *Referrer) RegisteredDomain() string

type ReferrerType

type ReferrerType int
const (
	Invalid ReferrerType = iota
	Indirect
	Direct
	Email
	Search
	Social
)

func (ReferrerType) String

func (r ReferrerType) String() string

type RuleSet

type RuleSet struct {
	DomainRules map[string]DomainRule
	UaRules     map[string]UaRule
}
var DefaultRules RuleSet

func NewRuleSet

func NewRuleSet() RuleSet

func (RuleSet) Merge

func (r RuleSet) Merge(other RuleSet)

func (RuleSet) Parse

func (r RuleSet) Parse(URL string) Referrer

func (RuleSet) ParseWith

func (r RuleSet) ParseWith(URL string, domains []string, agent string) Referrer

type UaRule

type UaRule struct {
	Url    string
	Domain string
	Tld    string
}

func (UaRule) RegisteredDomain

func (u UaRule) RegisteredDomain() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL