trodo-python 2.6.0__py3-none-any.whl → 2.7.0__py3-none-any.whl

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.
trodo/__init__.py CHANGED
@@ -40,7 +40,7 @@ Downstream microservice (join the caller's run instead of making a new one):
40
40
 
41
41
  from __future__ import annotations
42
42
 
43
- __version__ = "2.4.0"
43
+ __version__ = "2.7.0"
44
44
 
45
45
  from typing import Any, Callable, Dict, List, Optional, Union
46
46
 
@@ -3,7 +3,6 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import time
6
- import uuid
7
6
  from datetime import datetime, timezone
8
7
  from typing import Any, Dict, Optional
9
8
 
@@ -14,13 +13,24 @@ def now_iso() -> str:
14
13
  return datetime.now(timezone.utc).isoformat()
15
14
 
16
15
 
16
+ def server_session_id(distinct_id: str) -> str:
17
+ """Deterministic, "backend consistent" session id for a backend user.
18
+
19
+ Backend SDKs are stateless: the same distinct_id must resolve to the SAME
20
+ session across processes and restarts. Using ``server:{distinct_id}`` instead
21
+ of a per-process ``uuid4()`` produces exactly one session row per backend
22
+ user (no per-process bloat) and is idempotent server-side.
23
+ """
24
+ return f"server:{distinct_id}"
25
+
26
+
17
27
  def create_server_session(
18
28
  site_id: str,
19
29
  distinct_id: str,
20
30
  session_id: Optional[str] = None,
21
31
  ) -> ServerSession:
22
32
  return ServerSession(
23
- session_id=session_id or str(uuid.uuid4()),
33
+ session_id=session_id or server_session_id(distinct_id),
24
34
  site_id=site_id,
25
35
  distinct_id=distinct_id,
26
36
  start_time=now_iso(),
@@ -30,6 +40,15 @@ def create_server_session(
30
40
 
31
41
 
32
42
  def build_session_payload(session: ServerSession) -> Dict[str, Any]:
43
+ """Minimal server-session payload.
44
+
45
+ Backend SDKs cannot know browser-only signals (geo, device, browser, UTM,
46
+ referrer, wallet), so those fields are OMITTED rather than sent as ~30
47
+ explicit nulls — ingestion defaults missing fields to null. This saves
48
+ ingestion bandwidth and is more accurate. Only the markers ingestion keys
49
+ on are retained: ``is_server_session`` (drives identity-level browser-field
50
+ guards) and ``device_type='server'`` (server-origin fallback detector).
51
+ """
33
52
  return {
34
53
  "session_id": session.session_id,
35
54
  "site_id": session.site_id,
@@ -37,39 +56,9 @@ def build_session_payload(session: ServerSession) -> Dict[str, Any]:
37
56
  "distinct_id": session.distinct_id,
38
57
  "team_id": None,
39
58
  "start_time": session.start_time,
40
- "end_time": None,
41
59
  "last_activity": int(session.last_activity * 1000),
42
- "duration": 0,
43
- "pages_viewed": 0,
44
60
  "is_bounce": False,
45
- "previous_session_id": None,
46
- "time_since_last_session": None,
47
- "entry_page": None,
48
- "exit_page": None,
49
61
  "referrer": "server",
50
- "ip_address": None,
51
- "city": None,
52
- "region": None,
53
- "country": None,
54
- "browser_name": None,
55
- "browser_version": None,
56
62
  "device_type": "server",
57
- "os": None,
58
- "resolution": None,
59
- "user_agent": None,
60
- "language": None,
61
- "wallet_address": None,
62
- "wallet_type": None,
63
- "chain_name": None,
64
- "is_web3_user": False,
65
- "wallet_connected": False,
66
- "utm_source": None,
67
- "utm_medium": None,
68
- "utm_campaign": None,
69
- "utm_term": None,
70
- "utm_content": None,
71
- "utm_id": None,
72
- "visited_pages": [],
73
- "active_time_ms": 0,
74
63
  "is_server_session": True,
75
64
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trodo-python
3
- Version: 2.6.0
3
+ Version: 2.7.0
4
4
  Summary: Trodo Analytics SDK for Python — server-side event tracking
5
5
  License: ISC
6
6
  Keywords: analytics,tracking,trodo,server-side
@@ -1,4 +1,4 @@
1
- trodo/__init__.py,sha256=bO9bAzJhM6-QGDSIIxyiy0UxjYUcQsrhxhb6r6Rvu-8,16678
1
+ trodo/__init__.py,sha256=NapUF153zVbbqH45gud9g9M_UyQgxuqw_yAYERTGJlw,16678
2
2
  trodo/client.py,sha256=8DsKoLh_eaNxj93qkHynfeee-QsdomB_kXfUQjGnWDk,18607
3
3
  trodo/types.py,sha256=eySgUvCXROG2TxtxgiU0MNr5iH0DEcduK8bmYtTKG44,3138
4
4
  trodo/user_context.py,sha256=9la6azzwEanVmdP4ps_xMoufbeWVeIGU-M8ychmgajg,7859
@@ -23,9 +23,9 @@ trodo/queue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  trodo/queue/batch_flusher.py,sha256=4Lg6T3Urwi9U0Q4FpFGPmjDYKg4ZliCTR-ND8BJvWaY,1298
24
24
  trodo/queue/event_queue.py,sha256=EVFZrhlq_kwC3jJ2GK0wMhHISf9UzLCZNDnT_aZ2I2A,872
25
25
  trodo/session/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- trodo/session/server_session.py,sha256=4bQZc_Zxktmu8RVoyh0qI7tvr8AKsHI5xkGf3jEpWVE,2005
26
+ trodo/session/server_session.py,sha256=McsudEiq33XDq3nqxgzBcUvIjQxCMscwEuAPnYXrTjs,2136
27
27
  trodo/session/session_manager.py,sha256=JrgH1VeicmtlxPR4dXEuJbxhi23OelkgwW3-9Slv80o,2525
28
- trodo_python-2.6.0.dist-info/METADATA,sha256=JMJrzgxO8YnCH5FGXslwUr72IPrdFo-FO9wgxfPS76E,17882
29
- trodo_python-2.6.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
30
- trodo_python-2.6.0.dist-info/top_level.txt,sha256=VCQu1CJWFmNsqTs1YxMcw4Mq35Tc3z3uI9RwHEXAayQ,6
31
- trodo_python-2.6.0.dist-info/RECORD,,
28
+ trodo_python-2.7.0.dist-info/METADATA,sha256=K19DXcIe8jCHbOCEWXkyy0mxGhjCz_fH_VIdm0vuM9E,17882
29
+ trodo_python-2.7.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
30
+ trodo_python-2.7.0.dist-info/top_level.txt,sha256=VCQu1CJWFmNsqTs1YxMcw4Mq35Tc3z3uI9RwHEXAayQ,6
31
+ trodo_python-2.7.0.dist-info/RECORD,,