-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Average Scroll Depth Metric: imported data #4915
base: master
Are you sure you want to change the base?
Conversation
a083472
to
03327af
Compare
dbde2ce
to
8543cee
Compare
|
8543cee
to
9470502
Compare
9470502
to
1d7beb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall. Some questions and comments below
) | ||
|> group_by([e], [selected_as(:date), selected_as(:page)]) | ||
|> order_by([e], selected_as(:date)) | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like both the if and else clauses have the same basic query from events_v2
. Maybe there's an opportunity to extract it outside the conditional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I've extracted a base_q
in 7b5eeeb. The select clause however is a bit tricky to extract because we want to select a list. One possible solution is to select_merge
which requires the select to be a map, but then we'd still need to convert it back to a list in the end. I figured it's not worth the hustle as the FF is not expected to be there forever.
@@ -345,6 +345,7 @@ defmodule Plausible.Stats.Imported do | |||
|
|||
defp can_order_by?(query) do | |||
Enum.all?(query.order_by, fn | |||
{:scroll_depth, _} -> false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is ordering by scroll depth prevented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because since scroll_depth
is a "special metric", it's not yet selected into the query yet at this point, and any attempt to order by it will result in an invalid query.
fragment( | ||
""" | ||
case | ||
when isNotNull(?) AND isNotNull(?) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not instead return 0 values when scroll depth is missing from either side of the join? Other words - can we avoid this big conditional somehow? There's nothing wrong with the conditonal itself but I find managing raw fragments like this is a pain because of how the params must be passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fragment is pretty hideous indeed, but I'm afraid there's no way around it if we want the query to explicitly return NULL when there's no data. The main problem here is that zero can be a valid scroll_depth
value.
defp select_metric(:scroll_depth, "imported_pages") do | ||
wrap_alias([i], %{ | ||
scroll_depth_sum: sum(i.scroll_depth), | ||
total_visitors: sum(i.pageleave_visitors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any need/benefit to renaming pageleave_visitors
to total_visitors
here? Could be a bit misleading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 Agreed. It's misleading and could be confused with total_visitors
used in the calculation of conversion rate. I've renamed it to pageleave_visitors
all around - including the native query. 3203218
Changes
This PR starts making use of two new columns in the
imported_pages
table. The relevant migrations are already merged and executed:pageleave_visitors
field)The objectives of this PR are to:
scroll_depth
metric in the full CSV export/import featurescroll_depth
from imported data (if it exists) in stats queriesReturning warnings about imported data not being included in scroll_depth calculation will be implemented in a follow up PR.
Tests
Changelog
Documentation
Dark mode