View Source PlausibleProxy.Plug (plausible_proxy v0.1.1)
A plug to intercept:
- GET calls for the plausible script
- POST calls to
/api/event
Options:
local_path
is the local server path to serve up plausible js file from- Defaults to
"/js/plausible_script.js"
- Defaults to
script_extension
is the specific script to download from plausible.- See: https://plausible.io/docs/script-extensions#all-our-script-extensions
- Defaults to
"script.js"
remote_ip_headers
is a list of headers to search for inbound remote ip- First value found will populate the
X-Forwarded-For
header on requests to Plausible - If none are found in request,
PlausibleProxy
will useconn.remote_ip
- Defaults to
["fly-client-ip", "x-real-ip"]
- First value found will populate the
event_callback_fn
is an optional callback function to call when an event fires- Defaults to return empty map
Event Callback Function:
- 3 arity function that receives
conn
,payload
, andremote_ip
- Returns
{:ok, payload_modifiers}
wherepayload_modifiers
is a Map of key/value pairs to modify the event payload sent to Plausible
Supported payload_modifiers:
props
is a map of values to pass in the "props" value of the event payload body sent to Plausible- e.g.
%{props: %{"company" => "DockYard"}}
- e.g.
Example
defmodule MyApp.Endpoint do
...
plug PlausibleProxy.Plug,
event_callback_fn: fn _, _, _ -> {:ok, %{props: %{"site" => "mysite.com"}}},
remote_ip_headers: ["x-myhosting-remote-ip"],
script_extension: "script.pageview-props.js"
...
end