refererparser

package module
v0.0.0-...-03c1e5a Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 7 Imported by: 0

README

referer-parser Go library

This is the Go implementation of referer-parser, the library for extracting search marketing data from referer (sic) URLs.

The implementation uses the shared 'database' of known referers found in referers.yml.

The Go version of referer-parser is maintained by Thomas Sileo.

Installation

$ go get github.com/snowplow/referer-parser/go

Usage

package main

import (
  "log"

  "github.com/snowplow/referer-parser/go"
)

func main() {
  referer_url := "http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari"
  r := refererparser.Parse(referer_url)

  log.Printf("Known:%v", r.Known)
  log.Printf("Referer:%v", r.Referer)
  log.Printf("Medium:%v", r.Medium)
  log.Printf("Search parameter:%v", r.SearchParameter)
  log.Printf("Search term:%v", r.SearchTerm)
  log.Printf("Host:%v", r.URI)
}

referers.yml embed

The referers.json is embedded in the package using go-bindata.

$ go-bindata -ignore=\\.yml -pkg refererparser data/...

The referer-parser Go library is distributed under the MIT License.

Copyright (c) 2014 Thomas Sileo.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package refererparser implements referer extraction using a shared 'database' of known referers found in referers.yml [1].

Links

[1] https://github.com/snowplow/referer-parser/blob/master/referers.yml

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

Types

type RefererResult

type RefererResult struct {
	Known           bool
	Referer         string
	Medium          string
	SearchParameter string
	SearchTerm      string
	URI             *url.URL
}

RefererResult holds the extracted data

func Parse

func Parse(uri string) (refResult *RefererResult)

Parse an url and extract referer, it returns a RefererResult.

func (*RefererResult) SetCurrent

func (ref *RefererResult) SetCurrent(curl string)

SetCurrent is used to set the "internal" medium if needed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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