GoodAnalytics.Connectors.Config (GoodAnalytics v0.1.1)

Copy Markdown View Source

Compile-time and runtime configuration for the connector subsystem.

Compile-Time Configuration

Register connectors and the global dispatch policy callback via Application.compile_env:

# config/config.exs
config :good_analytics, :connectors, [
  GoodAnalytics.Connectors.Adapters.Meta,
  GoodAnalytics.Connectors.Adapters.Google,
  GoodAnalytics.Connectors.Adapters.LinkedIn,
  GoodAnalytics.Connectors.Adapters.TikTok
]

config :good_analytics, :dispatch_policy, {MyApp.ConnectorPolicy, :evaluate}

Runtime Configuration

The global kill switch can be set in runtime.exs:

config :good_analytics, :connectors_enabled, true

Setting this to false short-circuits all dispatch planning globally.

Summary

Functions

Returns true if the connector subsystem is globally enabled.

Returns the configured dispatch policy callback, or nil if none is set.

Invokes the global dispatch policy callback for a planning context.

Looks up a registered connector module by its connector type (atom or string).

Returns the list of registered connector modules.

Returns the list of registered connector types (atoms).

Functions

connectors_enabled?()

Returns true if the connector subsystem is globally enabled.

Reads from runtime config, defaults to true. Can be set to false in runtime.exs to short-circuit all dispatch planning without redeployment.

dispatch_policy()

Returns the configured dispatch policy callback, or nil if none is set.

The callback should be a {module, function} tuple that accepts a planning context map and returns :allow or {:reject, reason}.

evaluate_policy(planning_context)

Invokes the global dispatch policy callback for a planning context.

Returns :allow if no policy is configured or the policy approves. Returns {:reject, reason} if the policy rejects the dispatch.

get_connector(connector_type)

Looks up a registered connector module by its connector type (atom or string).

Returns nil if not found. The lookup map is memoized in :persistent_term and rebuilt only when the registered-connectors list changes, so the per-delivery hot path stays O(1) without rebuilding the map on every call.

registered_connectors()

Returns the list of registered connector modules.

registered_types()

Returns the list of registered connector types (atoms).

Each module must implement connector_type/0 from the connector behavior.