Ref Inspector

Referer parser library.

Setup

Dependency

To use Ref Inspector with your projects, edit your mix.exs file and add it as a dependency:

defp deps do
  [ { :ref_inspector, github: "elixytics/ref_inspector" } ]
end

You should also update your applications to include all necessary projects:

def application do
  [ applications: [ :ref_inspector, :yamerl ] ]
end

Referer Database

Using mix ref_inspector.yaml.download you can store a local copy of the regexes database in the configured path. This database is taken from the referer-parser project.

The local path of the downloaded file will be shown to you upon command invocation.

Configuration

Add the path to the referer database you want to use to your project configuration:

use Mix.Config

config :ref_inspector,
  yaml: Path.join(Mix.Utils.mix_home, "ref_inspector/referers.yml")

The shown path is the default download path used by the mix task.

Usage

iex(1)> RefInspector.parse("http://www.google.com/search?q=ref_inspector")
%RefInspector.Result{
  referer: "http://www.google.com/search?q=ref_inspector",
  medium:  "search",
  source:  "google",
  term:    "ref_inspector"
}

Medium will be one of :unknown, :email, :search or :social (always an atom).

Source will be :unknown (as atom) if nothing was matched, otherwise a string with the detected provider.

Term will be :none (as atom) if no query parameters were given to parse or the provider does not send any terms to detect (mostly social or email referers). Otherwise it will be an unencoded string will the term passed (can be empty).

Referer will return the passed referer unmodified.

Resources

License

Apache License, Version 2.0

Referers.yml taken from the referer-parser project. See there for detailed license information about the data contained.