Skip to content

Commit

Permalink
Internals documentation for datasette.track_event()
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 31, 2024
1 parent fe9dfbf commit d2b298f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,26 @@ Using either of these pattern will result in the in-memory database being served

This removes a database that has been previously added. ``name=`` is the unique name of that database.

.. _datasette_track_event:

await .track_event(event)
-------------------------

``event`` - ``Event``
An instance of a subclass of ``datasette.events.Event``.

Plugins can call this to track events, using classes they have previously registered. See :ref:`plugin_event_tracking` for details.

The event will then be passed to all plugins that have registered to receive events using the :ref:`plugin_hook_track_event` hook.

Example usage, assuming the plugin has previously registered the ``BanUserEvent`` class:

.. code-block:: python
await datasette.track_event(
BanUserEvent(user={"id": 1, "username": "cleverbot"})
)
.. _datasette_sign:

.sign(value, namespace="default")
Expand Down
2 changes: 1 addition & 1 deletion docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ track_event(datasette, event)
``event`` - ``Event``
Information about the event, represented as an instance of a subclass of the ``Event`` base class.

This hook will be called any time an event is tracked through code calling the ``datasette.track_event(...)`` internal method.
This hook will be called any time an event is tracked by code that calls the :ref:`datasette.track_event(...) <datasette_track_event>` internal method.

The ``event`` object will always have the following properties:

Expand Down

0 comments on commit d2b298f

Please sign in to comment.