hound v1.1.1 Hound.Metadata View Source

Metadata allows to pass and extract custom data through. This can be useful if you need to identify sessions.

The keys and values must be serializable using :erlang.term_to_binary/1.

Examples

You can start a session using metadata by doing the following:

Hound.start_session(metadata: %{pid: self()})

If you need to retrieve the metadata, you simply need to use Hound.Metadata.extract/1 on the user agent string, so supposing you are using plug,

user_agent =  conn |> get_req_header("user-agent") |> List.first
metadata   = Hound.Metadata.extract(user_agent)
assert %{pid: pid} = metadata
# you can use your pid here

Link to this section Summary

Functions

Appends the metdata to the user_agent string

Extracts and parses the metadata contained in a user agent string. If the user agent does not contain any metadata, an empty map is returned

Formats a string to a valid UserAgent string to be passed to be appended to the browser user agent

Link to this section Functions

Link to this function

append(user_agent, metadata) View Source
append(String.t(), nil | map() | String.t()) :: String.t()

Appends the metdata to the user_agent string.

Extracts and parses the metadata contained in a user agent string. If the user agent does not contain any metadata, an empty map is returned.

Link to this function

format(metadata) View Source
format(map() | Keyword.t()) :: String.t()

Formats a string to a valid UserAgent string to be passed to be appended to the browser user agent.