Skip to content
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

Page Scroll Goals #5029

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Page Scroll Goals #5029

wants to merge 30 commits into from

Conversation

RobertJoonas
Copy link
Contributor

@RobertJoonas RobertJoonas commented Jan 29, 2025

Required migration steps

Migrating from the old unique index to the new one is a bit tricky, requiring multiple steps:

  1. Migration: Add scroll_threshold column to Goal and add the new unique index. Page Scroll Goals: migration step 1 #5033
  2. Minimal schema change: Make Ecto aware of the new unique_constraint. Page Scroll Goals: migration step 2 #5034
  3. Migration: Drop the old index. Page Scroll Goals: migration step 3 #5036

Once the old index is dropped, this PR is ready to go.

Changes

This PR implements page scroll goals.

A page scroll goal can be created by simply adding a value into an optional scroll_threshold field when creating a pageview goal:

image

A user can filter and break down page scroll goals like any other goals.

TODO: figure out what to do with the total conversions metric

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@RobertJoonas RobertJoonas requested a review from macobo January 29, 2025 12:23
Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial thoughts on the PR. Will dig into the query side of this in-depth in another pass.

@RobertJoonas RobertJoonas changed the title Page scroll goals Page Scroll Goals Jan 30, 2025
@macobo macobo force-pushed the page-scroll-goals branch 2 times, most recently from 9978623 to 3c63b79 Compare January 30, 2025 11:35
@macobo macobo force-pushed the page-scroll-goals branch from 3c63b79 to 7e2e780 Compare January 30, 2025 11:39
@macobo macobo force-pushed the page-scroll-goals branch from da3f88a to ebf0dfb Compare January 30, 2025 11:52
lib/plausible/stats/goals.ex Outdated Show resolved Hide resolved
lib/plausible/stats/goals.ex Show resolved Hide resolved
lib/plausible/stats/goals.ex Outdated Show resolved Hide resolved
@@ -130,4 +130,365 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryGoalDimensionTest do
]
end
end

describe "page scroll goals" do
Copy link
Contributor

@macobo macobo Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're missing tests in test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs for:

  1. Tests filtering with scroll goals filter
  2. Tests doing event:goal group by with scroll goals
  3. group_conversion_rate tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@macobo macobo Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're still missing a test showing the behavior with imported data + conversion rate + goal group by.

@RobertJoonas RobertJoonas requested a review from macobo February 3, 2025 13:23

insert(:goal, site: site, page_path: "/blog**")

site_import = insert(:site_import, site: site)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant code in all the tests - you could do above

    test "rejects imported data with warning when page scroll goal is filtered by", %{
      conn: conn,
      site: site,
      site_import: site_import
    } do

}
} = json_response(conn, 200)

assert results == [%{"dimensions" => [], "metrics" => [1, 0, 100.0]}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: This could be inlined in the previous assert? Or is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more explicit. Inlining would be pattern matching which means there could be more keys in the map. Not a huge issue to inline it but not a concern to keep it this way either.

@@ -130,4 +130,365 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryGoalDimensionTest do
]
end
end

describe "page scroll goals" do
Copy link
Contributor

@macobo macobo Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're still missing a test showing the behavior with imported data + conversion rate + goal group by.

@RobertJoonas
Copy link
Contributor Author

I think we're still missing a test showing the behavior with imported data + conversion rate + goal group by.

@macobo test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs:1468 is testing it. If you meant to say imported data + group conversion rate + goal group by - that's not possible with imported data, as mixing multiple dimensions will make the query ineligible for imported data.

Copy link

github-actions bot commented Feb 3, 2025

Preview environment👷🏼‍♀️🏗️
PR-5029

Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be happy if the testing nit were resolved but other than that looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants