Skip to content

Conversation

@RobertJoonas
Copy link
Contributor

Changes

Make the following email reports work for consolidated views:

  • weekly stats report
  • monthly stats report
  • traffic spike notification
  • traffic drop notification

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 force-pushed the consolidated-view-email-reports branch from c70dfe4 to b0cb685 Compare November 10, 2025 11:32
@RobertJoonas RobertJoonas force-pushed the consolidated-view-email-reports branch from b0cb685 to 742fa67 Compare November 10, 2025 12:08
@RobertJoonas RobertJoonas requested a review from aerosol November 10, 2025 12:27
Copy link
Member

@aerosol aerosol left a comment

Choose a reason for hiding this comment

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

Nice! minor comments inline

if consolidated?(site), do: "consolidated view", else: site.domain
def display_name(%Site{} = site, opts \\ []) do
if consolidated?(site) do
"#{if opts[:capitalize_consolidated], do: "C", else: "c"}onsolidated view"
Copy link
Member

Choose a reason for hiding this comment

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

perhaps use String.capitalize/1 exactly where it's needed 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit annoying indeed, but on the other hand we also don't want to capitalize site.domain if it's not a consolidated site 😵‍💫

Copy link
Member

Choose a reason for hiding this comment

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

Right, but maybe it is telling that the display_name concept is not applicable to cover all the cases.

So maybe we're completely fine with having an email template like:

 <%= if Plausible.Sites.consolidated?(@site) do %>
   Consolidated view
 <% else %>
   <%= @site.domain %>
 <% end %>

instead of

 <%= Plausible.Sites.display_name(@site, capitalize_consolidated: true) %>

The latter feels forced for no clear benefit; leaving it up to you though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor benefit perhaps is that it's easier to grep the display_name function and discover all places where the name "Consolidated view" is used instead of site.domain. Maybe feels a bit forced, but doesn't hurt readability IMO.

Copy link
Member

Choose a reason for hiding this comment

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

Yes but there's plenty of "consolidated view" strings in there verbatim. And sometimes we call it "All sites" even. So it really doesn't serve any purpose.

Copy link
Member

Choose a reason for hiding this comment

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

Plus there's like a gazillion of places where site.domain is used

Copy link
Member

Choose a reason for hiding this comment

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

That said, your call still. Please excuse my OCD

|> Repo.preload([report_type, :team])
from(s in Plausible.Site,
where: s.id == ^site_id,
preload: [^report_type, :team]
Copy link
Member

Choose a reason for hiding this comment

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

This is still three queries 😛 You'd have to inner_join both associations.

iex(7)> from(s in Plausible.Site, where: s.id == 1, preload: [:monthly_report, :team]) |> Repo.one(); 1
08:35:56.443 [debug] QUERY OK source="sites" db=1.2ms idle=1072.4ms
SELECT s0."id", s0."domain", s0."timezone", s0."public", s0."stats_start_date", s0."native_stats_start_at", s0."allowed_event_props", s0."conversions_enabled", s0."props_enabled", s0."funnels_enabled", s0."legacy_time_on_page_cutoff", s0."consolidated", s0."ingest_rate_limit_scale_seconds", s0."ingest_rate_limit_threshold", s0."domain_changed_from", s0."domain_changed_at", s0."imported_data", s0."team_id", s0."inserted_at", s0."updated_at" FROM "sites" AS s0 WHERE (s0."id" = 1) []
08:35:56.444 [debug] QUERY OK source="teams" db=0.4ms idle=1074.5ms
SELECT t0."id", t0."identifier", t0."name", t0."trial_expiry_date", t0."accept_traffic_until", t0."allow_next_upgrade_override", t0."locked", t0."setup_complete", t0."setup_at", t0."hourly_api_request_limit", t0."notes", t0."policy", t0."grace_period", t0."inserted_at", t0."updated_at", t0."id" FROM "teams" AS t0 WHERE (t0."id" = $1) [1]
08:35:56.444 [debug] QUERY OK source="monthly_reports" db=0.4ms idle=1074.5ms
SELECT m0."id", m0."recipients", m0."site_id", m0."inserted_at", m0."updated_at", m0."site_id" FROM "monthly_reports" AS m0 WHERE (m0."site_id" = $1) [1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🫣 a49ecc0

@RobertJoonas RobertJoonas requested a review from aerosol November 11, 2025 13:07
@RobertJoonas RobertJoonas added this pull request to the merge queue Nov 11, 2025
Merged via the queue into master with commit f24aa4f Nov 11, 2025
16 checks passed
@RobertJoonas RobertJoonas deleted the consolidated-view-email-reports branch November 11, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants