Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Add data retention to the choose plan page (#3605)
Vinicius Brasil45a763ab2b92
diff --git a/lib/plausible/billing/plan.ex b/lib/plausible/billing/plan.exindex 9a4de8db98..78a6b8551c 100644--- a/lib/plausible/billing/plan.ex+++ b/lib/plausible/billing/plan.ex@@ -23,6 +23,7 @@ defmodule Plausible.Billing.Plan dofield :site_limit, :integerfield :team_member_limit, Plausible.Billing.Ecto.Limitfield :volume, :string+ field :data_retention_in_years, :integerfield :monthly_costfield :monthly_product_id, :string@@ -30,16 +31,16 @@ defmodule Plausible.Billing.Plan dofield :yearly_product_id, :stringend- @fields ~w(generation kind features monthly_pageview_limit site_limit team_member_limit volume monthly_cost monthly_product_id yearly_cost yearly_product_id)a+ @required_fields ~w(generation kind features monthly_pageview_limit site_limit team_member_limit volume)a+ @optional_fields ~w(monthly_cost yearly_cost monthly_product_id yearly_product_id data_retention_in_years)a+ @fields @required_fields ++ @optional_fieldsdef changeset(plan, attrs) doplan|> cast(attrs, @fields)|> put_volume()|> validate_required_either([:monthly_product_id, :yearly_product_id])- |> validate_required(- @fields -- [:monthly_cost, :yearly_cost, :monthly_product_id, :yearly_product_id]- )+ |> validate_required(@required_fields)enddefp put_volume(changeset) do@@ -51,9 +52,10 @@ defmodule Plausible.Billing.Plan doenddef validate_required_either(changeset, fields) do- if Enum.any?(fields, &get_field(changeset, &1)),- do: changeset,- else:- add_error(changeset, hd(fields), "one of these fields must be present #{inspect(fields)}")+ if Enum.any?(fields, &get_field(changeset, &1)) do+ changeset+ else+ add_error(changeset, hd(fields), "one of these fields must be present #{inspect(fields)}")+ endendenddiff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.exindex 8f6c89c6de..333186c9de 100644--- a/lib/plausible_web/live/choose_plan.ex+++ b/lib/plausible_web/live/choose_plan.ex@@ -739,29 +739,34 @@ defmodule PlausibleWeb.Live.ChoosePlan do[team_member_limit_benefit(plan),site_limit_benefit(plan),+ data_retention_benefit(plan),"Intuitive, fast and privacy-friendly dashboard","Email/Slack reports","Google Analytics import"]|> Kernel.++(feature_benefits(plan))+ |> Enum.filter(& &1)enddefp business_benefits(plan, growth_benefits) do["Everything in Growth",team_member_limit_benefit(plan),- site_limit_benefit(plan)+ site_limit_benefit(plan),+ data_retention_benefit(plan)]|> Kernel.++(feature_benefits(plan))|> Kernel.--(growth_benefits)|> Kernel.++(["Priority support"])+ |> Enum.filter(& &1)enddefp enterprise_benefits(business_benefits) doteam_members =- if "Up to 10 team members" in business_benefits,- do: "10+ team members",- else: nil+ if "Up to 10 team members" in business_benefits, do: "10+ team members"++ data_retention =+ if "5 years of data retention" in business_benefits, do: "5+ years of data retention"["Everything in Business",@@ -769,11 +774,16 @@ defmodule PlausibleWeb.Live.ChoosePlan do"50+ sites","600+ Stats API requests per hour",&sites_api_benefit/1,+ data_retention,"Technical onboarding"]|> Enum.filter(& &1)end+ defp data_retention_benefit(%Plan{} = plan) do+ if plan.data_retention_in_years, do: "#{plan.data_retention_in_years} years of data retention"+ end+defp team_member_limit_benefit(%Plan{} = plan) docase plan.team_member_limit do:unlimited -> "Unlimited team members"diff --git a/priv/plans_v4.json b/priv/plans_v4.jsonindex 8fd801898c..c40343a230 100644--- a/priv/plans_v4.json+++ b/priv/plans_v4.json@@ -7,7 +7,8 @@"yearly_product_id":"857079","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -17,7 +18,8 @@"yearly_product_id":"857080","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -27,7 +29,8 @@"yearly_product_id":"857081","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -37,7 +40,8 @@"yearly_product_id":"857082","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -47,7 +51,8 @@"yearly_product_id":"857083","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -57,7 +62,8 @@"yearly_product_id":"857084","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -67,7 +73,8 @@"yearly_product_id":"857085","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -77,7 +84,8 @@"yearly_product_id":"857086","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"business",@@ -87,7 +95,8 @@"yearly_product_id":"857087","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -97,7 +106,8 @@"yearly_product_id":"857088","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -107,7 +117,8 @@"yearly_product_id":"857089","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -117,7 +128,8 @@"yearly_product_id":"857090","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -127,7 +139,8 @@"yearly_product_id":"857091","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -137,7 +150,8 @@"yearly_product_id":"857092","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -147,7 +161,8 @@"yearly_product_id":"857093","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -157,6 +172,7 @@"yearly_product_id":"857094","site_limit":50,"team_member_limit":10,- "features":["goals","props","revenue_goals","funnels","stats_api"]+ "features":["goals","props","revenue_goals","funnels","stats_api"],+ "data_retention_in_years": 5}]diff --git a/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs b/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exsnew file mode 100644index 0000000000..6c1188be36--- /dev/null+++ b/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs@@ -0,0 +1,11 @@+defmodule Plausible.Repo.Migrations.AddDataRetentionInYearsToPlans do+ use Ecto.Migration++ def change do+ if !Application.get_env(:plausible, :is_selfhost) do+ alter table(:plans) do+ add :data_retention_in_years, :integer, null: true+ end+ end+ end+enddiff --git a/priv/sandbox_plans.json b/priv/sandbox_plans.jsonindex 2d2f8871e1..b25134a3f0 100644--- a/priv/sandbox_plans.json+++ b/priv/sandbox_plans.json@@ -37,7 +37,8 @@"yearly_product_id":"63862","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -47,7 +48,8 @@"yearly_product_id":"63863","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -57,7 +59,8 @@"yearly_product_id":"63864","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -67,7 +70,8 @@"yearly_product_id":"63865","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"growth",@@ -77,7 +81,8 @@"yearly_product_id":"63866","site_limit":10,"team_member_limit":3,- "features":["goals"]+ "features":["goals"],+ "data_retention_in_years": 3},{"kind":"business",@@ -117,7 +122,8 @@"yearly_product_id":"63870","site_limit":50,"team_member_limit":10,- "features":["goals","props", "revenue_goals", "funnels","stats_api"]+ "features":["goals","props", "revenue_goals", "funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -127,7 +133,8 @@"yearly_product_id":"63871","site_limit":50,"team_member_limit":10,- "features":["goals","props", "revenue_goals", "funnels","stats_api"]+ "features":["goals","props", "revenue_goals", "funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -137,7 +144,8 @@"yearly_product_id":"63872","site_limit":50,"team_member_limit":10,- "features":["goals","props", "revenue_goals", "funnels","stats_api"]+ "features":["goals","props", "revenue_goals", "funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -147,7 +155,8 @@"yearly_product_id":"63873","site_limit":50,"team_member_limit":10,- "features":["goals","props", "revenue_goals", "funnels","stats_api"]+ "features":["goals","props", "revenue_goals", "funnels","stats_api"],+ "data_retention_in_years": 5},{"kind":"business",@@ -157,6 +166,7 @@"yearly_product_id":"63874","site_limit":50,"team_member_limit":10,- "features":["goals","props", "revenue_goals", "funnels","stats_api"]+ "features":["goals","props", "revenue_goals", "funnels","stats_api"],+ "data_retention_in_years": 5}]diff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exsindex 7912dc6576..5e2fdbedce 100644--- a/test/plausible_web/live/choose_plan_test.exs+++ b/test/plausible_web/live/choose_plan_test.exs@@ -262,6 +262,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doassert growth_box =~ "Email/Slack reports"assert growth_box =~ "Google Analytics import"assert growth_box =~ "Goals and custom events"+ assert growth_box =~ "3 years of data retention"assert business_box =~ "Everything in Growth"assert business_box =~ "Up to 10 team members"@@ -271,6 +272,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doassert business_box =~ "Funnels"assert business_box =~ "Ecommerce revenue attribution"assert business_box =~ "Priority support"+ assert business_box =~ "5 years of data retention"refute business_box =~ "Goals and custom events"@@ -280,6 +282,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doassert enterprise_box =~ "600+ Stats API requests per hour"assert enterprise_box =~ "Sites API access for"assert enterprise_box =~ "Technical onboarding"+ assert enterprise_box =~ "5+ years of data retention"assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~"https://plausible.io/white-label-web-analytics"