View Source Plausible.Billing.Feature behaviour (Plausible v0.0.1)

This module provides an interface for managing features, e.g. Revenue Goals, Funnels and Custom Properties.

Feature modules have functions for toggling the feature on/off and checking whether the feature is available for a site/user.

When defining new features, the following options are expected by the __using__ macro:

  • :name - an atom representing the feature name in the plan JSON file (see also Plausible.Billing.Plan).

  • :display_name - human-readable display name of the feature

  • :toggle_field - the field in the %Plausible.Site{} schema that toggles the feature. If nil or not set, toggle/2 silently returns :ok

  • :free - if set to true, makes the check_availability/1 function always return :ok (no matter the user's subscription status)

Functions defined by __using__ can be overridden if needed.

Summary

Callbacks

Checks whether the site owner or the user plan includes the given feature.

Returns the human-readable display name of the feature.

Checks whether a feature is enabled or not. Returns false when the feature is disabled or the user does not have access to it.

Returns whether the feature is free to use or not.

Returns the atom representing the feature name in the plan JSON file.

Returns whether the site explicitly opted out of the feature. This function is different from enabled/1, because enabled/1 returns false when the site owner does not have access to the feature.

Toggles the feature on and off for a site. Returns {:error, :upgrade_required} when toggling a feature the site owner does not have access to.

Returns the %Plausible.Site{} field that toggles the feature on and off.

Functions

Lists all available feature modules.

Lists all the feature short names, e.g. RevenueGoals

Types

@type t() ::
  Plausible.Billing.Feature.RevenueGoals
  | Plausible.Billing.Feature.Funnels
  | Plausible.Billing.Feature.Props
  | Plausible.Billing.Feature.StatsAPI
  | Plausible.Billing.Feature.Goals

Callbacks

@callback check_availability(Plausible.Auth.User.t()) ::
  :ok | {:error, :upgrade_required} | {:error, :not_implemented}

Checks whether the site owner or the user plan includes the given feature.

@callback display_name() :: String.t()

Returns the human-readable display name of the feature.

@callback enabled?(Plausible.Site.t()) :: boolean()

Checks whether a feature is enabled or not. Returns false when the feature is disabled or the user does not have access to it.

@callback free?() :: boolean()

Returns whether the feature is free to use or not.

@callback name() :: atom()

Returns the atom representing the feature name in the plan JSON file.

@callback opted_out?(Plausible.Site.t()) :: boolean()

Returns whether the site explicitly opted out of the feature. This function is different from enabled/1, because enabled/1 returns false when the site owner does not have access to the feature.

@callback toggle(Plausible.Site.t(), Keyword.t()) :: :ok | {:error, :upgrade_required}

Toggles the feature on and off for a site. Returns {:error, :upgrade_required} when toggling a feature the site owner does not have access to.

@callback toggle_field() :: atom()

Returns the %Plausible.Site{} field that toggles the feature on and off.

Functions

Lists all available feature modules.

Link to this macro

list_short_names()

View Source (macro)

Lists all the feature short names, e.g. RevenueGoals