Commit Graph

1943 Commits

Author SHA1 Message Date
hq1
fbafa9534f
Set default: false on allow_next_upgrade_override in Team and User scheams (#4808)
Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2024-11-12 09:51:25 +00:00
Karl-Aksel Puulmann
d84fab805c
Solve noisy warnings about a negative range was inferred for Date.range/2 (#4803)
* Solve noisy warnings about `a negative range was inferred for Date.range/2`

query.now is in utc but the date range was in the querys timezone

This is visible in the pattern on the graph:

* Add tests
2024-11-12 07:50:51 +00:00
Karl-Aksel Puulmann
4aa7dec301
Channels: Migration to add materialized column, backfill code (#4798)
* Channels: Migration to add column, backfill code

This change adds `acqusition_channel` columns to events_v2 and
sessions_v2 tables. These columns are materialized - we don't ingest
into them directly. Instead they're calculated based on other columns.

The data migration changes now allow to also backfill the column.

Tested the ability to change definitions by changing the function
definitions and re-running the migration with backfill. Confirmed that
the underlying data changed as expected.

* quiet option

* Exclude data migrations from validation

* Migration consistency
2024-11-12 06:41:34 +00:00
Karl-Aksel Puulmann
3759db9b8c
Channels: Fix ON CLUSTER behavior (#4801)
* Channels: Fix cluster behavior

CREATE TABLE AS SELECT syntax did not work on cluster.

Instead, let's do a normal insert. For safety and to avoid timing
issues, ensure that INSERT waits for data to be inserted on all active
replicas.

* Proper replicated tables
2024-11-11 19:59:16 +00:00
Karl-Aksel Puulmann
d620432227
Channels: Speed up clickhouse calculations (#4789)
* Fix interpolation in data_migration.ex

* Speed up calculating acquisition_channel in clickhouse

The previous `has` queries proved to be problematic and causing a lot of
CPU overhead.

Benchmarked via this query:

```sql
SELECT
  channel,
  count(),
  countIf(acquisition_channel(referrer_source, utm_medium, utm_campaign, utm_source, click_id_param) = channel) AS matches
FROM events_v2
WHERE timestamp > now() - toIntervalHour(48)
GROUP BY channel
ORDER BY count() desc
```

Before this fix:
```
query_duration_ms:                                                57960
DiskReadElapsedMs:                                                374.712
RealTimeMs:                                                       2891200.667
UserTimeMs:                                                       2704024.783
SystemTimeMs:                                                     1693.265
OSCPUWaitMs:                                                      90.253
OSCPUVirtualTimeMs:                                               2705709.58
```

After this fix:
```
query_duration_ms:                                                4367
DiskReadElapsedMs:                                                454.356
RealTimeMs:                                                       213892.207
UserTimeMs:                                                       199363.485
SystemTimeMs:                                                     1479.364
OSCPUWaitMs:                                                      13.739
OSCPUVirtualTimeMs:                                               200837.37
```

Note that the new tables are not tracked in our schema as usual as
they're pretty much temporary tables to create the dictionary without
needing to upload files to clickhouse servers.

* CREATE OR REPLACE table with SELECT
2024-11-11 10:39:51 +00:00
Uku Taht
98bc3e7554
Channels in dashboard CSV export (#4787)
* Add channels.csv to dashboard CSV export

* Feature flag channels in CSV

* Disable credo
2024-11-11 09:31:57 +00:00
hq1
78a95eb8fc
Extract schema transitions under delegated namespace (#4788)
* Extract schema transitions under delegated namespace

* fixup
2024-11-07 11:27:27 +00:00
Adrian Gruntkowski
799e163eef
Do not attempt preloading user on guest invitation (#4790) 2024-11-07 11:24:42 +00:00
Adrian Gruntkowski
e1cdbfb9ac
Fix team struct sync and pruning team memberships/invitations on site transfer (#4786)
* Ensure `accept_traffic_until` is set with `trial_expiry_date` for teams

* Fix pruning guest memberships and invitations during site transfer
2024-11-07 10:53:42 +00:00
MorgeMoensch
fb45e64539
Add missing question mark on login page (#4783)
* Fix typo on login form to unify login and register

* Update CHANGELOG.md
2024-11-06 16:10:34 +00:00
Adrian Gruntkowski
342c3e5513
Finish moving /sites LV reads to team schemas behind FF (#4777)
* Implement user owning existing and pending sites check for teams

* Add predicate checking whether user has any existin or pending sites via teams

* Check need to upgrade for sites list via teams when FF is up

* Backfill teams for users on trial without a team

* Create team for users who register with trial started

* Replicate trial start logic on user create in team factories

* Make `ensure_can_take_ownership` in sites LV work via teams too

* Dispatch feature access check from `/sites` to Teams-schema reads

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2024-11-06 13:12:34 +00:00
Karl-Aksel Puulmann
eed21a0138
APIv2: Remove cruft (v2 flag, experimental_reduced_joins) (#4780)
* Remove query.v2 flag

This was originally used for making sure queries use the right table as
migrating to APIv2. This is no longer needed

* Remove experimental_reduced_joins flag
2024-11-06 12:08:20 +00:00
Karl-Aksel Puulmann
dbf7a099a3
Acquisition channels: Functions to calculate channels in clickhouse (#4701)
* Expose a few data migration functions, add quiet option to do_run

* Create functions and test acquisition channel logic in clickhouse

Tests were lifted from test/plausible_web/controllers/api/external_controller_test.exs

* Clean up test code a bit

* Property test for acquisition channels

* Handle empty strings properly in reference implementation

* Fix spelling, minor issues

* Revert "Property test for acquisition channels"

This reverts commit 3fa0e0e4eb.

* Only test clickhouse functions

* Solve minor code issue

* update channels logic

* Revert "Only test clickhouse functions"

This reverts commit e12784031a.

* Add more tests

* Add small result assertion

* Make query options explicit in data migrations

* Move multi-query running logic to within datamigration lib

* Unbreak numeric ids migration

* Named params directly to Clickhouse

* Update reference test implementation

---------

Co-authored-by: Uku Taht <uku.taht@gmail.com>
2024-11-06 11:27:02 +00:00
Uku Taht
c130c2a751
Fixes for ?source and ?ref params (#4781)
* Store `?source` and `?ref` params in `utm_source` field

* Remove dead code
2024-11-06 11:12:41 +00:00
Adrian Gruntkowski
c0a8aa025c
Clean up guest invitations selectively after accepting (#4778) 2024-11-06 08:56:48 +00:00
Adrian Gruntkowski
1e1a4ab35b
Get rid of memberships prosthetic for Teams.Sites.list_with_invitations (#4764)
* Get rid of memberships prosthetic for `Teams.Sites.list_with_invitations`

* Fix query in newly introduced teams backfill script
2024-11-05 09:44:27 +00:00
Karl-Aksel Puulmann
af5eb720db
Release breakdown_comparisons_ui flag (#4774) 2024-11-05 09:13:22 +00:00
Adrian Gruntkowski
dac9e3a0f0
Add removing guest memberships with mismatched team to backfill script (#4776) 2024-11-05 09:05:52 +00:00
Karl-Aksel Puulmann
1048967ac5
Channels: Write click_id_param column (#4704)
* Add migration for click_id_source

* click_id_param

* Write click_id_source column

* Add columns to schema

* click_id_param
2024-11-05 08:04:04 +00:00
ruslandoga
0ec8ac6d7c
remove @plausible.io contacts from CE (#4766) 2024-11-05 07:37:21 +00:00
ruslandoga
40f28ed151
rm Timex.diff/3 (#4695) 2024-11-04 09:18:04 +00:00
Artur Pata
13ad279820
Add second line for Filters (if saved_segments enabled) (#4729) 2024-11-04 08:22:48 +00:00
Karl-Aksel Puulmann
b16bd91600
Hard-code sample rate based on fractional_hardcoded_sample_rate flag (#4762)
* Hard-code sample rate based on fractional_hardcoded_sample_rate flag

We found cases where using a numeric sample rate would cause issues when
joining two tables due to different _sample_factor. Ref: https://3.basecamp.com/5308029/buckets/26383192/card_tables/cards/7973456592#__recording_7978780711

The proper fix is to use fractional sample rates everywhere, but this is
a whole project due to not wanting to sample small sites. For now, hard-code
sample rate for specific sites having the issue while we work on a
larger fix.

* is_number
2024-10-31 10:25:22 +00:00
Adrian Gruntkowski
7ff1a16ae3
Fix sites list for needs to upgrade condition check (#4758) 2024-10-31 09:20:29 +00:00
Adrian Gruntkowski
fc92ed5018
Switch Sites.list[_with_invitations] to use teams schemas (#4747)
* Simplify "needs_to_upgrade" check in Sites LV

* Use new schema for listing sites (WIP)

* wip: trying to filter out redundant site entries

* Move site listing logic around and continue fixing tests

* Fix Plausible.SiteTest

Expectations in some tests were adjusted. For instance,
we do not show invitations for sites where user is already
a member or owner.

* 1st stab at high-level factories covering old/new models

* Switch live /sites tests to transitional factories

* Improve prosthetics and make the remaining /sites tests pass

* Put new sites list logic behind a feature flag

* Fix listing pinned sites

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2024-10-31 08:53:02 +00:00
Uku Taht
c3a06caa97
Channel and source data updates (#4599)
* Channel and source data updates

* Update source mappings for migration

* Fix codespell

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>

* Update lib/plausible/ingestion/acquisition.ex

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>

* Standardize access to utm params

* Add wikipedia as "known" source

* Move custom sources to json file

* Add some advertising utm_sources

* Move source mapping logic to refinspector file

* Rename PlausibleWeb.RefInspector -> Plausible.Ingestion.Source

* Move mapping overrides to custom_sources.json

* More robust detection of paid sources

* Add missing utm_sources to migration

* Codespell

* Add moduledoc for Plausible.Ingestion.Source

* Fix dialyzer

* Remove migration

* Add more custom favicons

* Re-generate referrer favicons file

* Add doctest for sources

---------

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
2024-10-30 13:41:51 +00:00
Adrian Gruntkowski
dd79ad3c22
Fix further team sync discrepancies (#4755)
* Sync removing and rejecting invitations and site transfers

* Sync invitation/transfer ID with each new invite

* Accept only subset of guest invitations on sync

* Pass test

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2024-10-30 11:20:33 +00:00
Karl-Aksel Puulmann
b5d48a7347
Breakdown comparisons: Tooltip UX, arrows (#4719)
* Revert "Revert "Remove no change icon, better alignment""

This reverts commit a69d0a14a7fe038fe110907571240ad99a2ba6a4.

* different arrows

* Render graph tooltips in react

* Use ChangeArrow in graph tooltips

* Only display a single date if viewing a single date

* Tests for breakdown responses with labels

* Simplify code a bit

* strokeClass

* refactor ChangeArrow

* Play with stroke widths

* jest tests

* Silence logging in jest tests

* not variable stroke width

* prettier

* Conversion rate widths

* Update a test

* Trim trailing dates for label when comparing running month

* Reformat file

* Update expect.toHaveTextContent for multiline

* Update date range labelling to be more consistent with the frontend

* reformat
2024-10-30 10:19:47 +00:00
Adrian Gruntkowski
dc7e019d58
Adjust GA4 import timeout and page size to reduce risk of 502s and timeouts (#4753) 2024-10-29 11:24:01 +00:00
RobertJoonas
1a6fd1dc15
Remove unused controller action (#4748)
* remove unused controller action

* remove unused alias
2024-10-28 14:33:53 +00:00
Adrian Gruntkowski
a3ab3c9061
Ensure upserted invitations and memberships are up to date on conflict (#4749) 2024-10-28 13:54:57 +00:00
Adrian Gruntkowski
27ac3b6b5b
Address team syncing discrepancies (#4739)
* Clean site transfers after 48 hours

* Sync accepting site transfers and invitations within transaction

* Add dry run mode to teams backfill and make it a default

* Extend invitation clean worker tests
2024-10-28 10:11:47 +00:00
hq1
8bd32b68c9
Bring back premium feature notices in tiles (#4742)
* Lost tapes: bring back premium feature notices in tiles

* Ensure that e-mail CTA is only presented to business/enterprise customers

* Format

* Fix typespecs

* Add t() type to EnterprisePlan

* Reduce Plan.t() definition

Found no reason for it to be there.
2024-10-28 09:07:18 +00:00
Adrian Gruntkowski
0404522b5a
Sync team consistently on site creation (#4736) 2024-10-24 18:44:28 +00:00
Adrian Gruntkowski
2ec9e32557
Extend team consistency checks and improve syncing team and memberships (#4735)
* Extend team consistency checks

* Sync team against user right after creating the site

* Prune orphaned team guest memberships and invitations on site removal
2024-10-24 13:38:58 +00:00
hq1
c1a6501ec1
Delete teams along with users on DELETE /me (#4734)
* Delete teams along with users on DELETE /me

* Delete orphaned teams during backfill

* Format
2024-10-24 10:24:12 +00:00
Adrian Gruntkowski
5dbe1870e0
Implement teams consistency check and improve teams backfill (#4733)
* Implement team consistency check script

* Improve backfill teams sync check

* Fix team grace period sync
2024-10-24 10:03:22 +00:00
Karl-Aksel Puulmann
a59f12733d
Fix filter transformations (#4727)
Previously the code would use the incorrect operator and lead to nesting
2024-10-23 15:33:34 +00:00
hq1
1234cbf2c1
Enable teams sync (#4726) 2024-10-23 12:25:46 +00:00
RobertJoonas
0f93328b6f
Fix custom property value filter suggestions (#4720)
* new endpoint for custom prop value filter suggestions

* add test coverage for searching prop suggestions

* plug the new endpoint into FE

* update changelog

* format JS

* Update CHANGELOG.md

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>

---------

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
2024-10-23 12:24:23 +00:00
Adrian Gruntkowski
6695f2d7a0
Fix backfilling teams for users without sites but with subscriptions (#4725) 2024-10-23 11:59:33 +00:00
Adrian Gruntkowski
7d6f10f0cb
Ensure team is present before use in sync logic (#4709)
* Ensure team is present before use in sync logic

* Ensure teams backfill works against partially assigned sites

* Associate site with team on creation

* Associate site with team on sync

* Reuse alias

* Add tests for invitation creation sync

* Move team assertions to a helper module

* Format

* Test team creation on site creation via Sites context module

* Add tests for teams sync on subscription changes

* Tag tests

* Test grace period start syncing up with teams

* Test grace period manual lock sycning w/ teams

* Test grace period end sycing up w/ teams

* Test clearing grace period sync with teams

* Update moduledoc

* Fix missing preloads and wrong result pattern matching in sync logic

* Test sync on accepting invites and site transfers

* Test sync on membership role update and member removal

* transfer async fix WIP

* Stop privisioning team in site factory

* Remove unused relationship from Site schema

* Ensure consistent parsing of `passthrough` from Paddle webhook

* Update team passthrough notification tests & logic

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2024-10-23 11:29:15 +00:00
Karl-Aksel Puulmann
7794ff1417
Fix bounce_rate metric causing 500s with comparisons (#4723) 2024-10-23 10:18:23 +00:00
Adrian Gruntkowski
be83b7829d
Improve GA4 import error handling (#4714)
* Log warnings on HTTP GA4 import errors and add Sentry context on socket errors

* Treat socket and 5xx errors as recoverable (up for retry in ~1hr) in GA4 imports
2024-10-22 10:57:29 +00:00
Karl-Aksel Puulmann
472f4f181c
Comparisons pagination fixes (#4697)
* Add filter clauses for each main result filter

This handles the case where main query has a limit and results change. Doesnt handle metrics like percentage.

* Fix percentage calculations by ignoring breakdown-related filters in totals queries

* Refactor comparisons test suite

* Move comparisons logic to comparisons module

* New route for internal query tests

Only to be used in testing

* Support comparison queries with imports/breakdowns

* time dimension predicate extraction

* Clean up a test

* Update docstring

* Update route test

* fix a typo
2024-10-22 10:23:40 +00:00
Karl-Aksel Puulmann
aec0318c3b
Dashboard: show comparison for breakdowns (#4692)
* Comparisons: Move code to LegacyQueryBuilder

* WIP: Return comparison results to frontend

* refactor: remove useless param

* Different result format

* Pass object to metric.renderValue

* remove dead code

* Fixup response format

* Comparison in a tooltip

Not perfect at all, but a good start. Problems arise with money etc.

* Simple change arrow

* Extract metric entry to ts

* popper attempt WIP

* Slightly nicer content

* Solve warning

* Unified changeArrow in app

* Remove needless spanning

* Always set `graph_metric` in top stats.

FE already has business logic around whether a given metric is graphable

* Remove dead code

* Move Money module under dashboard utils, keep in build

* change <Metric /> definition to take in a `formatter` and store default formatters in another (typed) const

* Use standard system for formatting numbers

* Arrows only in table

* remove dead import

* Inline renderValue

* Render metric name in tooltip

* numberFormatter -> numberShortFormatter

* numberShortFormatter update

* Separate long/short formatters

* Use long vs short formatters

* Put column name into tooltip

* Slightly improved label handling for percentages, conversion rate

* Improved boundary handling in tooltip.js

* Iterate tooltips, no tooltip for - revenue

* Update top stats tests after graph_metric change

* Change revenue metrics stats API return structure

Conversion now happens earlier in query pipeline, we return float for comparison purposes

* useQueryContext in a component

* graph_metric for current visitors to fix realtime view

* No tooltips if fully - row

* renderValue as a proper function

* Simplify MetricEntry

* Use common const

* tooltip to typescript

* More explicit return structure

* metric-entry -> metric-value

* Restore some files

* ChangeArrow

* Restore MoreLink

* Fix typing in MoreLink

* <MetricValue />

* Tests for MetricValue and ChangeArrow

* details modal fixups

* re-add space between arrow and percentage

* Solve stylelint issues

* Update test

* Format

* Add flag `breakdown_comparisons_ui`

* reformat

* Remove no change icon, better alignment

* Revert "Remove no change icon, better alignment"

This reverts commit a8d62b6383.

* number-formatter.ts

* numberLongFormatter refactor

* useMemo dependency

* Handle nulls/undefined in top stats

---------

Co-authored-by: Uku Taht <uku.taht@gmail.com>
2024-10-22 09:02:13 +00:00
ruslandoga
0e4e614d4c
Remove eex artifact (#4712)
fixes #4710
2024-10-22 07:20:39 +00:00
Adrian Gruntkowski
3023d322d4
Limit resource usage in teams backfill data migration (#4708) 2024-10-21 08:52:07 +00:00
hq1
4bb8b44cad
Fix docs URL slug (#4707) 2024-10-21 08:27:34 +00:00
Adrian Gruntkowski
076d7509e6
Fix with_teams (#4706) 2024-10-21 08:11:49 +00:00