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:

  • :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

  • :extra_feature - an atom representing the feature name in the plan JSON file (see also Plausible.Billing.Plan). If nil or not set, check_availability/1 silently returns :ok

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.

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.

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 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.