-
Notifications
You must be signed in to change notification settings - Fork 14
/
referrer.go
76 lines (65 loc) · 1.14 KB
/
referrer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package goreferrer
type ReferrerType int
const (
Invalid ReferrerType = iota
Indirect
Direct
Email
Search
Social
)
func (r ReferrerType) String() string {
switch r {
default:
return "invalid"
case Indirect:
return "indirect"
case Direct:
return "direct"
case Email:
return "email"
case Search:
return "search"
case Social:
return "social"
}
}
type Referrer struct {
Type ReferrerType
Label string
URL string
Subdomain string
Domain string
Tld string
Path string
Query string
GoogleType GoogleSearchType
}
func (r *Referrer) RegisteredDomain() string {
if r.Domain != "" && r.Tld != "" {
return r.Domain + "." + r.Tld
}
return ""
}
func (r *Referrer) Host() string {
if r.Subdomain != "" {
return r.Subdomain + "." + r.RegisteredDomain()
}
return r.RegisteredDomain()
}
type GoogleSearchType int
const (
NotGoogleSearch GoogleSearchType = iota
OrganicSearch
Adwords
)
func (g GoogleSearchType) String() string {
switch g {
default:
return "not google search"
case OrganicSearch:
return "organic google search"
case Adwords:
return "google adwords referrer"
}
}