mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 17:11:36 +03:00
Set exit_page only on pageviews (#3870)
* Set exit_page only on pageviews * Update tests * Update entry_page on first pageview * Update CHANGELOG.md
This commit is contained in:
parent
07b714a143
commit
02d2256483
@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Remove `DISABLE_AUTH` deprecation warning plausible/analytics#3904
|
||||
|
||||
### Changed
|
||||
- A visits `entry_page` and `exit_page` is only set and updated for pageviews, not custom events
|
||||
- Limit the number of Goal Conversions shown on the dashboard and render a "Details" link when there are more entries to show
|
||||
- Show Outbound Links / File Downloads / 404 Pages / Cloaked Links instead of Goal Conversions when filtering by the corresponding goal
|
||||
- Require custom properties to be explicitly added from Site Settings > Custom Properties in order for them to show up on the dashboard
|
||||
|
@ -42,7 +42,12 @@ defmodule Plausible.Session.CacheStore do
|
||||
session
|
||||
| user_id: event.user_id,
|
||||
timestamp: event.timestamp,
|
||||
exit_page: event.pathname,
|
||||
entry_page:
|
||||
if(session.entry_page == "" and event.name == "pageview",
|
||||
do: event.pathname,
|
||||
else: session.entry_page
|
||||
),
|
||||
exit_page: if(event.name == "pageview", do: event.pathname, else: session.exit_page),
|
||||
is_bounce: false,
|
||||
duration: Timex.diff(event.timestamp, session.start, :second) |> abs,
|
||||
pageviews:
|
||||
@ -58,8 +63,8 @@ defmodule Plausible.Session.CacheStore do
|
||||
hostname: event.hostname,
|
||||
site_id: event.site_id,
|
||||
user_id: event.user_id,
|
||||
entry_page: event.pathname,
|
||||
exit_page: event.pathname,
|
||||
entry_page: if(event.name == "pageview", do: event.pathname, else: ""),
|
||||
exit_page: if(event.name == "pageview", do: event.pathname, else: ""),
|
||||
is_bounce: true,
|
||||
duration: 0,
|
||||
pageviews: if(event.name == "pageview", do: 1, else: 0),
|
||||
|
@ -89,6 +89,69 @@ defmodule Plausible.Session.CacheStoreTest do
|
||||
assert session.events == 2
|
||||
end
|
||||
|
||||
test "initial pageview-specific attributes" do
|
||||
site_id = new_site_id()
|
||||
|
||||
event =
|
||||
build(:event,
|
||||
name: "custom_event",
|
||||
site_id: site_id,
|
||||
pathname: "/path/1",
|
||||
user_id: 1
|
||||
)
|
||||
|
||||
flush([event])
|
||||
|
||||
session = get_session(site_id)
|
||||
|
||||
assert session.exit_page == ""
|
||||
assert session.events == 1
|
||||
assert session.pageviews == 0
|
||||
end
|
||||
|
||||
test "updating pageview-specific attributes" do
|
||||
site_id = new_site_id()
|
||||
|
||||
event1 =
|
||||
build(:event,
|
||||
name: "custom_event",
|
||||
site_id: site_id,
|
||||
pathname: "/path/1",
|
||||
user_id: 1
|
||||
)
|
||||
|
||||
event2 =
|
||||
build(:pageview,
|
||||
pathname: "/path/2",
|
||||
site_id: site_id,
|
||||
user_id: 1
|
||||
)
|
||||
|
||||
event3 =
|
||||
build(:pageview,
|
||||
pathname: "/path/3",
|
||||
site_id: site_id,
|
||||
user_id: 1
|
||||
)
|
||||
|
||||
event4 =
|
||||
build(:event,
|
||||
name: "custom_event",
|
||||
site_id: site_id,
|
||||
pathname: "/path/4",
|
||||
user_id: 1
|
||||
)
|
||||
|
||||
flush([event1, event2, event3, event4])
|
||||
|
||||
session = get_session(site_id)
|
||||
|
||||
assert session.entry_page == "/path/2"
|
||||
assert session.exit_page == "/path/3"
|
||||
assert session.events == 4
|
||||
assert session.pageviews == 2
|
||||
end
|
||||
|
||||
test "calculates duration correctly for out-of-order events", %{buffer: buffer} do
|
||||
timestamp = Timex.now()
|
||||
event1 = build(:event, name: "pageview", timestamp: timestamp |> Timex.shift(seconds: 10))
|
||||
@ -103,18 +166,6 @@ defmodule Plausible.Session.CacheStoreTest do
|
||||
end
|
||||
|
||||
describe "collapse order" do
|
||||
defp new_site_id() do
|
||||
[[site_id]] =
|
||||
Plausible.ClickhouseRepo.query!("select max(site_id) + rand() from sessions_v2 FINAL").rows
|
||||
|
||||
site_id
|
||||
end
|
||||
|
||||
defp flush(events) do
|
||||
for e <- events, do: CacheStore.on_event(e, %{}, nil)
|
||||
Plausible.Session.WriteBuffer.flush()
|
||||
end
|
||||
|
||||
test "across parts" do
|
||||
e = build(:event, name: "pageview", site_id: new_site_id())
|
||||
|
||||
@ -137,8 +188,7 @@ defmodule Plausible.Session.CacheStoreTest do
|
||||
%{e | pathname: "/exit"}
|
||||
])
|
||||
|
||||
session_q = from s in Plausible.ClickhouseSessionV2, where: s.site_id == ^e.site_id
|
||||
session = Plausible.ClickhouseRepo.one!(session_q)
|
||||
session = get_session(e.site_id)
|
||||
|
||||
refute session.is_bounce
|
||||
assert session.entry_page == "/"
|
||||
@ -167,4 +217,21 @@ defmodule Plausible.Session.CacheStoreTest do
|
||||
assert session.events == 4
|
||||
end
|
||||
end
|
||||
|
||||
defp new_site_id() do
|
||||
[[site_id]] =
|
||||
Plausible.ClickhouseRepo.query!("select max(site_id) + rand() from sessions_v2 FINAL").rows
|
||||
|
||||
site_id
|
||||
end
|
||||
|
||||
defp flush(events) do
|
||||
for e <- events, do: CacheStore.on_event(e, %{}, nil)
|
||||
Plausible.Session.WriteBuffer.flush()
|
||||
end
|
||||
|
||||
defp get_session(site_id) do
|
||||
session_q = from s in Plausible.ClickhouseSessionV2, where: s.site_id == ^site_id
|
||||
Plausible.ClickhouseRepo.one!(session_q)
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,2 @@
|
||||
name,conversions,conversion_rate
|
||||
/,1,25.0
|
||||
,1,100.0
|
||||
|
|
@ -1,2 +1,2 @@
|
||||
name,conversions,conversion_rate
|
||||
/,1,33.3
|
||||
,1,100.0
|
||||
|
|
@ -1,2 +1,3 @@
|
||||
name,unique_entrances,total_entrances,visit_duration
|
||||
/,4,4,15
|
||||
/,3,3,20
|
||||
,1,1,0
|
||||
|
|
@ -1,3 +1,4 @@
|
||||
name,unique_exits,total_exits,exit_rate
|
||||
/,3,3,100.0
|
||||
/,2,2,66.0
|
||||
,1,1,
|
||||
/some-other-page,1,1,100.0
|
||||
|
|
@ -1,3 +1,3 @@
|
||||
name,visitors,pageviews,bounce_rate,time_on_page
|
||||
/,4,3,75,
|
||||
/,4,3,67,
|
||||
/some-other-page,1,1,,60.0
|
||||
|
|
@ -1,2 +1,3 @@
|
||||
name,unique_entrances,total_entrances,visit_duration
|
||||
/,5,5,12
|
||||
/,4,4,15
|
||||
,1,1,0
|
||||
|
|
@ -1,3 +1,4 @@
|
||||
name,unique_exits,total_exits,exit_rate
|
||||
/,4,4,100.0
|
||||
/,3,3,75.0
|
||||
,1,1,
|
||||
/some-other-page,1,1,100.0
|
||||
|
|
@ -1,3 +1,3 @@
|
||||
name,visitors,pageviews,bounce_rate,time_on_page
|
||||
/,5,4,80,
|
||||
/,5,4,75,
|
||||
/some-other-page,1,1,,60.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user