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"
  • script_extension is the specific script to download from plausible.
  • 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 use conn.remote_ip
    • Defaults to ["fly-client-ip", "x-real-ip"]
  • 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, and remote_ip
  • Returns {:ok, payload_modifiers} where payload_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"}}

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