mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
Add goal type to JSON response
This commit is contained in:
parent
6365c6956b
commit
66575f497b
@ -1,8 +1,22 @@
|
|||||||
|
defimpl Jason.Encoder, for: Plausible.Goal do
|
||||||
|
def encode(value, opts) do
|
||||||
|
goal_type =
|
||||||
|
cond do
|
||||||
|
value.event_name -> :event
|
||||||
|
value.page_path -> :page
|
||||||
|
end
|
||||||
|
|
||||||
|
value
|
||||||
|
|> Map.put(:goal_type, goal_type)
|
||||||
|
|> Map.take([:id, :domain, :goal_type, :event_name, :page_path])
|
||||||
|
|> Jason.Encode.map(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defmodule Plausible.Goal do
|
defmodule Plausible.Goal do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
@derive {Jason.Encoder, only: [:id, :domain, :event_name, :page_path]}
|
|
||||||
schema "goals" do
|
schema "goals" do
|
||||||
field :domain, :string
|
field :domain, :string
|
||||||
field :event_name, :string
|
field :event_name, :string
|
||||||
|
@ -204,6 +204,7 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
res = json_response(conn, 200)
|
res = json_response(conn, 200)
|
||||||
|
assert res["goal_type"] == "event"
|
||||||
assert res["event_name"] == "Signup"
|
assert res["event_name"] == "Signup"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -216,6 +217,7 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
res = json_response(conn, 200)
|
res = json_response(conn, 200)
|
||||||
|
assert res["goal_type"] == "page"
|
||||||
assert res["page_path"] == "/signup"
|
assert res["page_path"] == "/signup"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user