mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
track_event() mechanism for analytics and plugins
* Closes #2240 * Documentation for event plugin hooks, refs #2240 * Include example track_event plugin in docs, refs #2240 * Tests for track_event() and register_events() hooks, refs #2240 * Initial documentation for core events, refs #2240 * Internals documentation for datasette.track_event()
This commit is contained in:
parent
890615b3f2
commit
bcc4f6bf1f
22 changed files with 614 additions and 10 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import asyncio
|
||||
import httpx
|
||||
import os
|
||||
import pathlib
|
||||
|
|
@ -8,7 +7,8 @@ import re
|
|||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import trustme
|
||||
from dataclasses import dataclass, field
|
||||
from datasette import Event, hookimpl
|
||||
|
||||
|
||||
try:
|
||||
|
|
@ -164,6 +164,35 @@ def check_permission_actions_are_documented():
|
|||
)
|
||||
|
||||
|
||||
class TrackEventPlugin:
|
||||
__name__ = "TrackEventPlugin"
|
||||
|
||||
@dataclass
|
||||
class OneEvent(Event):
|
||||
name = "one"
|
||||
|
||||
extra: str
|
||||
|
||||
@hookimpl
|
||||
def register_events(self, datasette):
|
||||
async def inner():
|
||||
return [self.OneEvent]
|
||||
|
||||
return inner
|
||||
|
||||
@hookimpl
|
||||
def track_event(self, datasette, event):
|
||||
datasette._tracked_events = getattr(datasette, "_tracked_events", [])
|
||||
datasette._tracked_events.append(event)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def install_event_tracking_plugin():
|
||||
from datasette.plugins import pm
|
||||
|
||||
pm.register(TrackEventPlugin(), name="TrackEventPlugin")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def ds_localhost_http_server():
|
||||
ds_proc = subprocess.Popen(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue