Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Update session screen_size if unknown (#1610)

ssendev8077671f8ae1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4be2ecc5cb..0c7985aaca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Subscribed users can see their Paddle invoices from the last 12 months under the user settings
- Allow custom styles to be passed to embedded iframe plausible/analytics#1522
- New UTM Tags `utm_content` and `utm_term` plausible/analytics#515
+- If a session was started without a screen_size it is updated if an event with screen_size occurs
### Fixed
- UI fix where multi-line text in pills would not be underlined properly on small screens.
diff --git a/lib/plausible/session/store.ex b/lib/plausible/session/store.ex
index aa9daff06c..64afc08f8b 100644
--- a/lib/plausible/session/store.ex
+++ b/lib/plausible/session/store.ex
@@ -91,6 +91,8 @@ defmodule Plausible.Session.Store do
duration: Timex.diff(event.timestamp, session.start, :second) |> abs,
pageviews:
if(event.name == "pageview", do: session.pageviews + 1, else: session.pageviews),
+ screen_size:
+ if(session.screen_size == "", do: event.screen_size, else: session.screen_size),
events: session.events + 1
}
end
diff --git a/test/plausible/session/store_test.exs b/test/plausible/session/store_test.exs
index aa39cb2c59..b310bdc802 100644
--- a/test/plausible/session/store_test.exs
+++ b/test/plausible/session/store_test.exs
@@ -70,7 +70,8 @@ defmodule Plausible.Session.StoreTest do
domain: event1.domain,
user_id: event1.user_id,
name: "pageview",
- timestamp: timestamp
+ timestamp: timestamp,
+ screen_size: "Desktop"
)
Store.on_event(event1, nil, store)
@@ -80,6 +81,7 @@ defmodule Plausible.Session.StoreTest do
assert session.duration == 10
assert session.pageviews == 2
assert session.events == 2
+ assert session.screen_size == "Desktop"
end
test "calculates duration correctly for out-of-order events", %{store: store} do