mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 10:02:10 +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
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@derive {Jason.Encoder, only: [:id, :domain, :event_name, :page_path]}
|
||||
schema "goals" do
|
||||
field :domain, :string
|
||||
field :event_name, :string
|
||||
|
@ -204,6 +204,7 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
|
||||
})
|
||||
|
||||
res = json_response(conn, 200)
|
||||
assert res["goal_type"] == "event"
|
||||
assert res["event_name"] == "Signup"
|
||||
end
|
||||
|
||||
@ -216,6 +217,7 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
|
||||
})
|
||||
|
||||
res = json_response(conn, 200)
|
||||
assert res["goal_type"] == "page"
|
||||
assert res["page_path"] == "/signup"
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user