simple-module-analytics 0.0.15__tar.gz → 0.0.16__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/.gitignore +1 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/PKG-INFO +2 -2
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/docs/index.md +77 -7
- simple_module_analytics-0.0.16/hatch_build.py +60 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/package.json +2 -2
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/pyproject.toml +5 -4
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/constants.py +5 -1
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/settings.py +3 -7
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/index.ts +1 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/locales/de.json +18 -3
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/locales/en.json +16 -1
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/module.py +8 -5
- simple_module_analytics-0.0.16/sm_analytics/ui/components/PropertyEditor.test.tsx +98 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/PropertyEditor.tsx +61 -9
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/RankingPanel.tsx +7 -3
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/RecentActivity.tsx +2 -2
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportView.test.tsx +12 -0
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/api.test.ts +114 -0
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/api.ts +92 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/hostAdapter.test.ts +37 -2
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/hostCache.test.ts +251 -0
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/hostTracker.test.ts +122 -0
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/hostTracker.ts +113 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/useAnalytics.test.tsx +26 -3
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/useAnalytics.ts +26 -10
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/useAnalyticsAuth.test.tsx +68 -0
- simple_module_analytics-0.0.16/sm_analytics/ui/utils/validationMessage.ts +29 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/schemas.py +5 -3
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_registration.py +2 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/web/test_api.py +21 -0
- simple_module_analytics-0.0.16/tests/web/test_schemas.py +30 -0
- simple_module_analytics-0.0.15/sm_analytics/ui/utils/api.ts +0 -52
- simple_module_analytics-0.0.15/sm_analytics/ui/utils/csrf.ts +0 -46
- simple_module_analytics-0.0.15/sm_analytics/ui/utils/hostTracker.test.ts +0 -65
- simple_module_analytics-0.0.15/sm_analytics/ui/utils/hostTracker.ts +0 -52
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/README.md +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/collection/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/collection/privacy.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/collection/retention.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/collection/service.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/geo.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/runtime.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/tenancy.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/models/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/pages/Dashboard.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/reporting/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/reporting/reports.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/DateRangeControl.test.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/DateRangeControl.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/DeleteProperty.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/FilterChips.test.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/FilterChips.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/PropertySettings.test.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/PropertySettings.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportExport.test.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportExport.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportFilters.test.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportFilters.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/ReportView.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/components/TrafficChart.tsx +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/i18n.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/reportExport.test.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/reportExport.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/tracker.test.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/tracker.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/trackingPaths.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/ui/utils/types.ts +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/deps.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/endpoints/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/endpoints/admin.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/web/endpoints/public.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/collection/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/collection/test_concurrency.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/collection/test_privacy.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/collection/test_service.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/conftest.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_geo.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_indexes.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_migration.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_operator.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/core/test_settings.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/perf/benchmark.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/pg_support.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/reporting/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/reporting/test_postgres.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/reporting/test_reports.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tests/web/__init__.py +0 -0
- {simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/tsconfig.json +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_analytics
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.16
|
|
4
4
|
Summary: Anonymous tenant-scoped web and application analytics with local GeoIP
|
|
5
|
-
Project-URL: Repository, https://github.com/antosubash/
|
|
5
|
+
Project-URL: Repository, https://github.com/antosubash/smpy_modules
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Keywords: analytics,geoip,simple-module,web-analytics
|
|
8
8
|
Requires-Python: >=3.12
|
|
@@ -22,18 +22,80 @@ pattern includes them. Analytics stores no titles, form contents or user IDs.
|
|
|
22
22
|
Choose public route slugs and allowed event values accordingly: these fields can
|
|
23
23
|
still contain personal information supplied by an application.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
`startHostAnalytics` from `@simple-module-py/analytics
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
Install the host adapter once in the Inertia entry point. Import
|
|
26
|
+
`startHostAnalytics` from `@simple-module-py/analytics` and forward completed
|
|
27
|
+
navigation pages. Skip Inertia's `initial` event: the initializer handles the
|
|
28
|
+
first load. Pass the initial page too so the optional `shouldTrack` callback
|
|
29
|
+
can skip a host's 404 component on the first load as well as later visits:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { router } from '@inertiajs/react';
|
|
33
|
+
import { startHostAnalytics, type HostAnalyticsPage } from '@simple-module-py/analytics';
|
|
34
|
+
|
|
35
|
+
// Call from createInertiaApp's setup, where props.initialPage is available.
|
|
36
|
+
const stop = startHostAnalytics(
|
|
37
|
+
(navigate) => router.on('navigate', (event) => {
|
|
38
|
+
if (event.detail.type !== 'initial') navigate(event.detail.page);
|
|
39
|
+
}),
|
|
40
|
+
props.initialPage,
|
|
41
|
+
{ shouldTrack: (page) => page.component !== 'Errors/NotFound' },
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`shouldTrack` receives the absolute `url`, query-free `path`, and any `component`,
|
|
46
|
+
`status` or `tenantId` supplied by the host. Inertia supplies the component but
|
|
47
|
+
not an HTTP status; a host may add its own status. Returning false disables both
|
|
48
|
+
pageviews and custom events for that page. Without the callback, matching routes
|
|
49
|
+
are tracked as before. URL strings remain supported when metadata is unnecessary.
|
|
50
|
+
Call the returned cleanup on teardown.
|
|
51
|
+
|
|
52
|
+
Configuration (including an empty property list) is reused for three minutes.
|
|
53
|
+
The next eligible navigation after expiry refreshes it; concurrent navigations
|
|
54
|
+
share a request and only the latest page is recorded when it resolves. A failed,
|
|
55
|
+
invalid or timed-out fetch disables tracking and waits 30 seconds before another
|
|
56
|
+
navigation may retry. No background timer fetches config. A successful refresh
|
|
57
|
+
picks up enabled, changed or paused properties without a reload; changes may take
|
|
58
|
+
up to three minutes of navigation to appear.
|
|
59
|
+
|
|
60
|
+
The cache key is the origin and the host's resolved tenant ID. Single-tenant and
|
|
61
|
+
subdomain hosts may use URLs or Inertia pages directly. **Hosts that switch tenants
|
|
62
|
+
on the same origin must include `tenantId` on the initial page and every forwarded
|
|
63
|
+
navigation** (including same-URL switches). For the framework tenants provider,
|
|
64
|
+
map its resolved `tenant.active.id` shared prop; never use `auth.user.tenant_id`:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const trackingPage = (page: typeof props.initialPage): HostAnalyticsPage => ({
|
|
68
|
+
url: page.url,
|
|
69
|
+
component: page.component,
|
|
70
|
+
tenantId: page.props.tenant?.active?.id ?? null,
|
|
71
|
+
});
|
|
72
|
+
// Use trackingPage(props.initialPage) above, and navigate(trackingPage(event.detail.page)).
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Changing this scope discards the previous config and any late response. Other
|
|
76
|
+
origins are ignored. The endpoint retains `Cache-Control: private, no-store`:
|
|
77
|
+
config is tenant-bound and is never shared through a proxy cache. Its existing
|
|
78
|
+
rate-limit registration is unchanged.
|
|
79
|
+
|
|
80
|
+
The module also exports `initAnalytics(config, url)` and `track(name, properties)`
|
|
81
|
+
for explicit integration. Configure allowed event/property names first:
|
|
31
82
|
|
|
32
83
|
```ts
|
|
33
84
|
import { track } from '@simple-module-py/analytics';
|
|
34
85
|
await track('download', { format: 'pdf' });
|
|
35
86
|
```
|
|
36
87
|
|
|
88
|
+
A host that installs the module from PyPI resolves `@simple-module-py/analytics`
|
|
89
|
+
through the `package.json` shipped inside the wheel (correct there since 0.0.16,
|
|
90
|
+
#472). If the host's `tsconfig.json` maps module packages with `paths`, it needs
|
|
91
|
+
the bare name as well as the `/*` form, or `tsc` reports `TS2307` for the import
|
|
92
|
+
above:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
"@simple-module-py/analytics": ["./.venv/lib/python3.12/site-packages/sm_analytics"],
|
|
96
|
+
"@simple-module-py/analytics/*": ["./.venv/lib/python3.12/site-packages/sm_analytics/*"]
|
|
97
|
+
```
|
|
98
|
+
|
|
37
99
|
An event named `download` with property `format` must be declared on the property.
|
|
38
100
|
Other properties are discarded. Event names are 1–50 characters; up to 20 scalar
|
|
39
101
|
string/number/boolean values are accepted, with strings limited to 500 characters.
|
|
@@ -100,7 +162,15 @@ Reports support inclusive start/end dates (default last seven days, maximum 366)
|
|
|
100
162
|
path/event/geographic filters, top-50 breakdowns and the last five minutes of
|
|
101
163
|
activity. Select an event to see its allowed property breakdowns. Selecting an
|
|
102
164
|
unknown location filters empty values; leaving a selector at All does not filter.
|
|
103
|
-
Recent activity refreshes every 30 seconds while visible
|
|
165
|
+
Recent activity refreshes every 30 seconds while visible; its empty state refers
|
|
166
|
+
to the last five minutes, independently of the selected report date range.
|
|
167
|
+
No map or GPS is used.
|
|
168
|
+
|
|
169
|
+
Property validation errors appear beside the field they describe, with focus
|
|
170
|
+
moved to the first invalid field. Route validation distinguishes a missing leading
|
|
171
|
+
slash, the 500-character limit and invalid path segments. An expired dashboard
|
|
172
|
+
session redirects to sign-in with a return link to the report, and stops polling.
|
|
173
|
+
The initial Inertia navigation does not restart an already loading report.
|
|
104
174
|
|
|
105
175
|
Retention defaults to 90 days. Every minute each web process deletes at most 5000
|
|
106
176
|
expired events per tenant, then removes expired sessions with no remaining events.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Wheel build hook: the packaged ``package.json`` points at the packaged layout (#472).
|
|
2
|
+
|
|
3
|
+
``package.json`` lives at the module root so npm workspaces see it, and its
|
|
4
|
+
entry points say so: ``"./<package>/index.ts"``. The wheel copies it *into* the
|
|
5
|
+
package, next to ``index.ts``, where that path names a folder that does not
|
|
6
|
+
exist; a host that installed the wheel could not import the bare package name.
|
|
7
|
+
This writes the copy with the ``<package>/`` step removed.
|
|
8
|
+
|
|
9
|
+
An editable install serves the source tree, so it keeps the file as written.
|
|
10
|
+
The same file sits in every module that ships an entry point; keep the copies
|
|
11
|
+
identical (``scripts/tests/test_wheel_contents.py``).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import tempfile
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
22
|
+
|
|
23
|
+
ENTRY_KEYS = ("exports", "main", "module", "types")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def repoint(value: Any, package: str) -> Any:
|
|
27
|
+
"""``./<package>/x`` becomes ``./x`` in a string, at any depth of ``exports``."""
|
|
28
|
+
prefix = f"./{package}/"
|
|
29
|
+
if isinstance(value, str):
|
|
30
|
+
return "./" + value[len(prefix) :] if value.startswith(prefix) else value
|
|
31
|
+
if isinstance(value, dict):
|
|
32
|
+
return {key: repoint(inner, package) for key, inner in value.items()}
|
|
33
|
+
if isinstance(value, list):
|
|
34
|
+
return [repoint(inner, package) for inner in value]
|
|
35
|
+
return value
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PackageJsonHook(BuildHookInterface):
|
|
39
|
+
PLUGIN_NAME = "custom"
|
|
40
|
+
|
|
41
|
+
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
|
|
42
|
+
package = self.config["package"]
|
|
43
|
+
source = Path(self.root) / "package.json"
|
|
44
|
+
target = f"{package}/package.json"
|
|
45
|
+
if version == "editable":
|
|
46
|
+
build_data["force_include"][str(source)] = target
|
|
47
|
+
return
|
|
48
|
+
manifest = json.loads(source.read_text(encoding="utf-8"))
|
|
49
|
+
for key in ENTRY_KEYS:
|
|
50
|
+
if key in manifest:
|
|
51
|
+
manifest[key] = repoint(manifest[key], package)
|
|
52
|
+
self._scratch = tempfile.TemporaryDirectory()
|
|
53
|
+
packaged = Path(self._scratch.name) / "package.json"
|
|
54
|
+
packaged.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
55
|
+
build_data["force_include"][str(packaged)] = target
|
|
56
|
+
|
|
57
|
+
def finalize(self, version: str, build_data: dict[str, Any], artifact_path: str) -> None:
|
|
58
|
+
scratch = getattr(self, "_scratch", None)
|
|
59
|
+
if scratch is not None:
|
|
60
|
+
scratch.cleanup()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simple-module-py/analytics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Anonymous traffic and application analytics",
|
|
6
6
|
"exports": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"@inertiajs/react": "^3.9.1",
|
|
11
11
|
"@simple-module-py/i18n": "*",
|
|
12
|
-
"@simple-module-py/ui": "
|
|
12
|
+
"@simple-module-py/ui": ">=0.0.38",
|
|
13
13
|
"lucide-react": "^1.43.0",
|
|
14
14
|
"react": "^19.3.1",
|
|
15
15
|
"react-dom": "^19.3.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_analytics"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.16"
|
|
4
4
|
description = "Anonymous tenant-scoped web and application analytics with local GeoIP"
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
readme = "README.md"
|
|
@@ -16,7 +16,7 @@ dependencies = [
|
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
[project.urls]
|
|
19
|
-
Repository = "https://github.com/antosubash/
|
|
19
|
+
Repository = "https://github.com/antosubash/smpy_modules"
|
|
20
20
|
|
|
21
21
|
[project.optional-dependencies]
|
|
22
22
|
geoip = ["geoip2>=5.2,<6"]
|
|
@@ -33,8 +33,9 @@ build-backend = "hatchling.build"
|
|
|
33
33
|
packages = ["sm_analytics"]
|
|
34
34
|
exclude = ["**/*.test.ts", "**/*.test.tsx", "**/page-tests/**", "**/test-dom.tsx"]
|
|
35
35
|
|
|
36
|
-
[tool.hatch.build.targets.wheel.
|
|
37
|
-
|
|
36
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
37
|
+
path = "hatch_build.py"
|
|
38
|
+
package = "sm_analytics"
|
|
38
39
|
|
|
39
40
|
[tool.pytest.ini_options]
|
|
40
41
|
asyncio_mode = "auto"
|
{simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/constants.py
RENAMED
|
@@ -7,9 +7,13 @@ API_PREFIX = "/api/analytics"
|
|
|
7
7
|
VIEW_PREFIX = "/analytics"
|
|
8
8
|
PERM_VIEW = "analytics.view"
|
|
9
9
|
PERM_MANAGE = "analytics.manage"
|
|
10
|
-
_PAGE_DASHBOARD = "Analytics/Dashboard"
|
|
11
10
|
COLLECT_PATH = f"{API_PREFIX}/collect"
|
|
12
11
|
CONFIG_PATH = f"{API_PREFIX}/config"
|
|
13
12
|
MAX_BODY_BYTES = 8192
|
|
13
|
+
COLLECT_RATE = "120/minute"
|
|
14
|
+
# Config requests share an IP budget across tabs and visitors behind a NAT (or an
|
|
15
|
+
# e2e shard on 127.0.0.1). The host adapter caches them, but uncached integrations
|
|
16
|
+
# can still exhaust 120/minute and cause 429s on unrelated pages.
|
|
17
|
+
CONFIG_RATE = "1200/minute"
|
|
14
18
|
UTM_PARAMETERS = frozenset({"utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"})
|
|
15
19
|
EXCLUDED_SEGMENTS = frozenset({"auth", "login", "logout", "register", "settings", "analytics"})
|
{simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/core/settings.py
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"""Deployment settings hydrate from the framework database, never the environment."""
|
|
2
2
|
|
|
3
3
|
from pydantic import Field
|
|
4
|
-
from pydantic_settings import
|
|
4
|
+
from pydantic_settings import SettingsConfigDict
|
|
5
|
+
from simple_module_core.settings_base import DbBackedSettings
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
class AnalyticsSettings(
|
|
8
|
+
class AnalyticsSettings(DbBackedSettings):
|
|
8
9
|
model_config = SettingsConfigDict(extra="ignore", use_attribute_docstrings=True)
|
|
9
10
|
retention_days: int = Field(default=90, ge=1, le=3650)
|
|
10
11
|
"""Days of events retained; deletion runs in bounded batches."""
|
|
@@ -15,8 +16,3 @@ class AnalyticsSettings(BaseSettings):
|
|
|
15
16
|
scheduler_enabled: bool = Field(default=True, json_schema_extra={"requires_restart": True})
|
|
16
17
|
"""Run periodic retention cleanup in this process."""
|
|
17
18
|
|
|
18
|
-
@classmethod
|
|
19
|
-
def settings_customise_sources(
|
|
20
|
-
cls, settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings
|
|
21
|
-
):
|
|
22
|
-
return (init_settings,)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { initAnalytics, track } from './ui/utils/tracker';
|
|
2
2
|
export type { AnalyticsConfig, TrackingProperty, Scalar } from './ui/utils/tracker';
|
|
3
3
|
export { startHostAnalytics } from './ui/utils/hostTracker';
|
|
4
|
+
export type { HostAnalyticsPage, HostAnalyticsOptions } from './ui/utils/hostTracker';
|
{simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/locales/de.json
RENAMED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"geo_disabled": "Standortberichte sind deaktiviert.",
|
|
65
65
|
"geo_age": "Alter der Datenbank: {days} Tage",
|
|
66
66
|
"setup": "Erfassung einrichten",
|
|
67
|
-
"setup_help": "
|
|
67
|
+
"setup_help": "Passende Routen werden erfasst, sobald dieses Projekt aktiviert ist. Benutzerdefinierte Ereignisse müssen hier aufgeführt sein, bevor sie erfasst werden.",
|
|
68
68
|
"event_format_error": "Ein Ereignis pro Zeile verwenden: ereignis: eigenschaft, eigenschaft.",
|
|
69
69
|
"dimensions": {
|
|
70
70
|
"path": "Seiten",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"custom_range": "Eigene Daten",
|
|
101
101
|
"apply": "Anwenden",
|
|
102
102
|
"filters_button": "Filter",
|
|
103
|
-
"manage": "
|
|
103
|
+
"manage": "Projekt verwalten",
|
|
104
104
|
"close": "Schließen",
|
|
105
105
|
"show_more": "Mehr anzeigen",
|
|
106
106
|
"show_less": "Weniger anzeigen",
|
|
@@ -110,9 +110,24 @@
|
|
|
110
110
|
"activity": "Aktivität",
|
|
111
111
|
"date_help": "Datumsangaben in UTC. Das Enddatum muss am oder nach dem Startdatum und innerhalb von 366 Tagen liegen.",
|
|
112
112
|
"clear_filter": "Filter {name} entfernen",
|
|
113
|
-
"settings": "
|
|
113
|
+
"settings": "Projekteinstellungen",
|
|
114
114
|
"export_csv": "CSV exportieren",
|
|
115
115
|
"export_help": "Aktuellen Bericht herunterladen: Summen, täglicher Traffic und bis zu 50 Zeilen je Aufschlüsselung. Zeitraum und Filter sind enthalten.",
|
|
116
116
|
"export_failed": "CSV-Export fehlgeschlagen. Bitte erneut versuchen."
|
|
117
|
+
},
|
|
118
|
+
"pageview": "Seitenaufruf",
|
|
119
|
+
"recent_empty": "Keine Aktivität in den letzten fünf Minuten.",
|
|
120
|
+
"session_expired": "Ihre Sitzung ist abgelaufen. Sie werden zur Anmeldung weitergeleitet…",
|
|
121
|
+
"validation": {
|
|
122
|
+
"route_prefix": "Routenmuster müssen mit / beginnen.",
|
|
123
|
+
"route_length": "Routenmuster dürfen höchstens 500 Zeichen lang sein.",
|
|
124
|
+
"route_segments": "Verwenden Sie feste Pfadsegmente oder :name als Platzhalter.",
|
|
125
|
+
"origin": "Geben Sie einen vollständigen http(s)-Ursprung ohne Pfad ein.",
|
|
126
|
+
"event_names": "Ungültiger Ereignis- oder Eigenschaftsname (höchstens 50 Zeichen, 20 Eigenschaften).",
|
|
127
|
+
"utm": "Nicht unterstützter UTM-Parameter.",
|
|
128
|
+
"text_short": "Zu kurz (Mindestlänge: {count}).",
|
|
129
|
+
"text_long": "Geben Sie höchstens {count} Zeichen ein.",
|
|
130
|
+
"items_long": "Verwenden Sie höchstens {count} Einträge.",
|
|
131
|
+
"items_short": "Zu wenige Einträge (Minimum: {count})."
|
|
117
132
|
}
|
|
118
133
|
}
|
{simple_module_analytics-0.0.15 → simple_module_analytics-0.0.16}/sm_analytics/locales/en.json
RENAMED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"geo_disabled": "Location reporting is disabled.",
|
|
65
65
|
"geo_age": "Database age: {days} days",
|
|
66
66
|
"setup": "Tracking setup",
|
|
67
|
-
"setup_help": "
|
|
67
|
+
"setup_help": "Matching routes are tracked once this property is enabled. Custom events must be listed here before they are recorded.",
|
|
68
68
|
"event_format_error": "Use one event per line: event: property, property.",
|
|
69
69
|
"dimensions": {
|
|
70
70
|
"path": "Pages",
|
|
@@ -114,5 +114,20 @@
|
|
|
114
114
|
"export_csv": "Export CSV",
|
|
115
115
|
"export_help": "Download the current report: totals, daily traffic and up to 50 rows per breakdown. Dates and filters are included.",
|
|
116
116
|
"export_failed": "CSV export failed. Try again."
|
|
117
|
+
},
|
|
118
|
+
"pageview": "Pageview",
|
|
119
|
+
"recent_empty": "No activity in the last five minutes.",
|
|
120
|
+
"session_expired": "Your session has expired. Redirecting to sign in…",
|
|
121
|
+
"validation": {
|
|
122
|
+
"route_prefix": "Route patterns must start with /",
|
|
123
|
+
"route_length": "Route patterns must be at most 500 characters",
|
|
124
|
+
"route_segments": "Use literal path segments or :name placeholders",
|
|
125
|
+
"origin": "Expected an exact http(s) origin without a path",
|
|
126
|
+
"event_names": "Invalid event or property name (max 50 characters, 20 properties)",
|
|
127
|
+
"utm": "Unsupported UTM parameter",
|
|
128
|
+
"text_short": "Too short (minimum length: {count}).",
|
|
129
|
+
"text_long": "Enter at most {count} characters.",
|
|
130
|
+
"items_long": "Use at most {count} entries.",
|
|
131
|
+
"items_short": "Too few entries (minimum: {count})."
|
|
117
132
|
}
|
|
118
133
|
}
|
|
@@ -12,7 +12,6 @@ from simple_module_core.module_settings import register_module_settings
|
|
|
12
12
|
from simple_module_core.permissions import PermissionRegistry
|
|
13
13
|
from simple_module_core.public_routes import PublicRouteRegistry
|
|
14
14
|
from simple_module_core.rate_limit import RateLimitRegistry, RateLimitRule
|
|
15
|
-
from simple_module_hosting.csrf import get_csrf_token
|
|
16
15
|
from simple_module_hosting.inertia_deps import InertiaDep
|
|
17
16
|
from simple_module_hosting.permissions import RequiresPermission, resolved_permissions_for
|
|
18
17
|
from starlette.requests import Request
|
|
@@ -22,6 +21,10 @@ from sm_analytics.core.runtime import Runtime
|
|
|
22
21
|
from sm_analytics.core.settings import AnalyticsSettings
|
|
23
22
|
from sm_analytics.core.tenancy import bind_admin
|
|
24
23
|
|
|
24
|
+
# Kept beside render so the framework doctor sees a bare constant name rather
|
|
25
|
+
# than c.<name> attribute access, which its page scan cannot resolve (SM003, #482).
|
|
26
|
+
_PAGE_DASHBOARD = "Analytics/Dashboard"
|
|
27
|
+
|
|
25
28
|
|
|
26
29
|
class AnalyticsModule(ModuleBase):
|
|
27
30
|
meta = ModuleMeta(
|
|
@@ -30,6 +33,7 @@ class AnalyticsModule(ModuleBase):
|
|
|
30
33
|
view_prefix=c.VIEW_PREFIX,
|
|
31
34
|
depends_on=[c._MODULE_SETTINGS],
|
|
32
35
|
version=metadata.version("simple_module_analytics"),
|
|
36
|
+
i18n_audience="admin",
|
|
33
37
|
requires_framework=">=1.0,<2.0",
|
|
34
38
|
)
|
|
35
39
|
|
|
@@ -51,10 +55,9 @@ class AnalyticsModule(ModuleBase):
|
|
|
51
55
|
async def dashboard(request: Request, inertia: InertiaDep):
|
|
52
56
|
permissions = resolved_permissions_for(request)
|
|
53
57
|
return await inertia.render(
|
|
54
|
-
|
|
58
|
+
_PAGE_DASHBOARD,
|
|
55
59
|
{
|
|
56
60
|
"can_manage": "*" in permissions or c.PERM_MANAGE in permissions,
|
|
57
|
-
"csrf_token": get_csrf_token(request) or "",
|
|
58
61
|
},
|
|
59
62
|
)
|
|
60
63
|
|
|
@@ -82,10 +85,10 @@ class AnalyticsModule(ModuleBase):
|
|
|
82
85
|
|
|
83
86
|
def register_rate_limits(self, registry: RateLimitRegistry) -> None:
|
|
84
87
|
registry.add_exact(
|
|
85
|
-
c.COLLECT_PATH, RateLimitRule(
|
|
88
|
+
c.COLLECT_PATH, RateLimitRule(c.COLLECT_RATE, key="ip", methods=frozenset({"POST"}))
|
|
86
89
|
)
|
|
87
90
|
registry.add_exact(
|
|
88
|
-
c.CONFIG_PATH, RateLimitRule(
|
|
91
|
+
c.CONFIG_PATH, RateLimitRule(c.CONFIG_RATE, key="ip", methods=frozenset({"GET"}))
|
|
89
92
|
)
|
|
90
93
|
|
|
91
94
|
def locale_dirs(self) -> dict[str, Path]:
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { act } from 'react';
|
|
4
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
5
|
+
import { afterEach, expect, it, vi } from 'vitest';
|
|
6
|
+
import { saveProperty } from '../utils/api';
|
|
7
|
+
import { PropertyEditor } from './PropertyEditor';
|
|
8
|
+
|
|
9
|
+
(globalThis as unknown as { React: unknown }).React = React;
|
|
10
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
11
|
+
let root: Root;
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await act(async () => root?.unmount());
|
|
14
|
+
document.body.replaceChildren();
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
});
|
|
18
|
+
it('places each server validation error next to its field and focuses the first invalid field', async () => {
|
|
19
|
+
vi.stubGlobal(
|
|
20
|
+
'fetch',
|
|
21
|
+
vi.fn(async () =>
|
|
22
|
+
Response.json(
|
|
23
|
+
{
|
|
24
|
+
detail: [
|
|
25
|
+
{
|
|
26
|
+
loc: ['body', 'origins', 0],
|
|
27
|
+
msg: 'Value error, Expected an exact http(s) origin without a path',
|
|
28
|
+
type: 'value_error',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
loc: ['body', 'route_patterns'],
|
|
32
|
+
msg: 'Value error, Route patterns must start with /',
|
|
33
|
+
type: 'value_error',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{ status: 422 },
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
const container = document.createElement('div');
|
|
42
|
+
document.body.append(container);
|
|
43
|
+
root = createRoot(container);
|
|
44
|
+
await act(async () =>
|
|
45
|
+
root.render(
|
|
46
|
+
<PropertyEditor
|
|
47
|
+
onSave={async (input) => {
|
|
48
|
+
await saveProperty(input);
|
|
49
|
+
}}
|
|
50
|
+
onCancel={() => {}}
|
|
51
|
+
/>,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
await act(async () =>
|
|
55
|
+
container
|
|
56
|
+
.querySelector('form')
|
|
57
|
+
?.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })),
|
|
58
|
+
);
|
|
59
|
+
const origins = container.querySelector('textarea[id$="-origins"]');
|
|
60
|
+
const routes = container.querySelector('textarea[id$="-routes"]');
|
|
61
|
+
for (const [field, message] of [
|
|
62
|
+
[origins, 'origin'],
|
|
63
|
+
[routes, 'start with /'],
|
|
64
|
+
] as const) {
|
|
65
|
+
expect(field?.getAttribute('aria-invalid')).toBe('true');
|
|
66
|
+
const descriptions = field
|
|
67
|
+
?.getAttribute('aria-describedby')
|
|
68
|
+
?.split(' ')
|
|
69
|
+
.map((id) => document.getElementById(id)?.textContent)
|
|
70
|
+
.join(' ');
|
|
71
|
+
expect(descriptions).toContain(message);
|
|
72
|
+
}
|
|
73
|
+
expect(document.activeElement).toBe(origins);
|
|
74
|
+
expect(container.textContent).not.toContain('Value error,');
|
|
75
|
+
});
|
|
76
|
+
it('brings a non-field save failure into view', async () => {
|
|
77
|
+
const scroll = vi.spyOn(HTMLElement.prototype, 'scrollIntoView');
|
|
78
|
+
const container = document.createElement('div');
|
|
79
|
+
document.body.append(container);
|
|
80
|
+
root = createRoot(container);
|
|
81
|
+
await act(async () =>
|
|
82
|
+
root.render(
|
|
83
|
+
<PropertyEditor
|
|
84
|
+
onSave={async () => {
|
|
85
|
+
throw new Error('Save unavailable');
|
|
86
|
+
}}
|
|
87
|
+
onCancel={() => {}}
|
|
88
|
+
/>,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
await act(async () =>
|
|
92
|
+
container
|
|
93
|
+
.querySelector('form')
|
|
94
|
+
?.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })),
|
|
95
|
+
);
|
|
96
|
+
expect(container.querySelector('[role="alert"]')?.textContent).toBe('Save unavailable');
|
|
97
|
+
expect(scroll).toHaveBeenCalled();
|
|
98
|
+
});
|