# `PhoenixKitOG.ActivityLog`
[🔗](https://github.com/BeamLabEU/phoenix_kit_og/blob/0.4.0/lib/phoenix_kit_og/activity_log.ex#L1)

Thin wrapper around `PhoenixKit.Activity.log/3` for the OG plugin.

Every entry is stamped with `module: "phoenix_kit_og"` so the admin
activity feed can filter to just this plugin's events. Callers pass
the pipe-friendly `{:ok, struct}` shape so the return value chains
cleanly through context functions. Core never raises — a missing
activities table on a fresh host, or any other failure, is logged
there and returned — so logging never breaks the mutation.

Metadata is PII-safe by convention: names, statuses, counts, UUIDs
are OK; email / phone / free-text / anything a user could paste in
is not.

# `insert_in_transaction`

```elixir
@spec insert_in_transaction(String.t(), keyword(), map()) :: struct() | nil
```

Inserts an activity row from INSIDE the caller's transaction, so the row
exists exactly when the transaction commits. Returns the entry for
`publish/1`, or `nil` when the row could not be written.

`PhoenixKit.Activity.log/3` broadcasts as it inserts, which inside a
transaction announces a change that may still roll back — hence the
split. The insert runs in a savepoint: a failed audit row must not abort
the transaction it describes.

# `log`

```elixir
@spec log({:ok, struct()} | {:error, term()}, String.t(), keyword(), (struct() -&gt;
                                                                  map())) ::
  {:ok, struct()} | {:error, term()}
```

Pipe step for context functions returning `{:ok, struct}`. Logs the
action and returns the value unchanged. `{:error, _}` short-circuits
to a no-op so callers can put this at the tail of the pipe.

## Example

    %Template{}
    |> Template.changeset(attrs)
    |> Repo.insert()
    |> ActivityLog.log("template.created", opts, &template_activity_fields/1)

# `maybe_log`

```elixir
@spec maybe_log(String.t(), keyword(), map()) :: :ok
```

Log without the pipe wrapper — for transactions, toggles, and other
paths where the caller doesn't have a `{:ok, struct}` in hand.

# `publish`

```elixir
@spec publish([struct() | nil]) :: :ok
```

Publishes entries written by `insert_in_transaction/3`, after the commit.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
