|
| 1 | +# referer-parser Go library |
| 2 | + |
| 3 | +This is the Go implementation of [referer-parser][referer-parser], the library for extracting search marketing data from referer _(sic)_ URLs. |
| 4 | + |
| 5 | +The implementation uses the shared 'database' of known referers found in [`referers.yml`][referers-yml]. |
| 6 | + |
| 7 | +The Go version of referer-parser is maintained by [Andrii Kostenko][gugu]. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```console |
| 12 | +$ go get github.com/short-io/referer-parser-go |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +```go |
| 18 | +package main |
| 19 | + |
| 20 | +import ( |
| 21 | + "log" |
| 22 | + |
| 23 | + "github.com/short-io/referer-parser-go" |
| 24 | +) |
| 25 | + |
| 26 | +func main() { |
| 27 | + refererparser.LoadRefererData("/path/to/referers.json") |
| 28 | + referer_url := "http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari" |
| 29 | + r := refererparser.Parse(referer_url) |
| 30 | + |
| 31 | + log.Printf("Known:%v", r.Known) |
| 32 | + log.Printf("Referer:%v", r.Referer) |
| 33 | + log.Printf("Medium:%v", r.Medium) |
| 34 | + log.Printf("Search parameter:%v", r.SearchParameter) |
| 35 | + log.Printf("Search term:%v", r.SearchTerm) |
| 36 | + log.Printf("Host:%v", r.URI) |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | +## Copyright and license |
| 42 | + |
| 43 | +The referer-parser Go library is distributed under the MIT License. |
| 44 | + |
| 45 | +Copyright (c) 2014 Thomas Sileo, Andrii Kostenko. |
| 46 | + |
| 47 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 48 | +of this software and associated documentation files (the "Software"), to deal |
| 49 | +in the Software without restriction, including without limitation the rights |
| 50 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 51 | +copies of the Software, and to permit persons to whom the Software is |
| 52 | +furnished to do so, subject to the following conditions: |
| 53 | + |
| 54 | +The above copyright notice and this permission notice shall be included in |
| 55 | +all copies or substantial portions of the Software. |
| 56 | + |
| 57 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 58 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 59 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 60 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 61 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 62 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 63 | +THE SOFTWARE. |
| 64 | + |
| 65 | +[referer-parser]: https://github.com/snowplow/referer-parser |
| 66 | +[referers-yml]: https://github.com/snowplow/referer-parser/blob/master/referers.json |
| 67 | + |
| 68 | +[tsileo]: https://github.com/tsileo |
| 69 | +[go-bindata]: https://github.com/jteeuwen/go-bindata |
0 commit comments