mbuzz 0.1.1__py3-none-any.whl → 0.2.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.
mbuzz/__init__.py
CHANGED
mbuzz/client/track.py
CHANGED
|
@@ -28,10 +28,12 @@ class TrackOptions:
|
|
|
28
28
|
session_id: Optional[str] = None
|
|
29
29
|
user_id: Optional[str] = None
|
|
30
30
|
properties: Optional[Dict[str, Any]] = None
|
|
31
|
+
ip: Optional[str] = None
|
|
32
|
+
user_agent: Optional[str] = None
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
def _resolve_ids(options: TrackOptions) -> TrackOptions:
|
|
34
|
-
"""Resolve visitor/session/user IDs from context if not provided."""
|
|
36
|
+
"""Resolve visitor/session/user IDs and ip/user_agent from context if not provided."""
|
|
35
37
|
ctx = get_context()
|
|
36
38
|
if not ctx:
|
|
37
39
|
return options
|
|
@@ -42,6 +44,8 @@ def _resolve_ids(options: TrackOptions) -> TrackOptions:
|
|
|
42
44
|
session_id=options.session_id or ctx.session_id,
|
|
43
45
|
user_id=options.user_id or ctx.user_id,
|
|
44
46
|
properties=options.properties,
|
|
47
|
+
ip=options.ip or ctx.ip,
|
|
48
|
+
user_agent=options.user_agent or ctx.user_agent,
|
|
45
49
|
)
|
|
46
50
|
|
|
47
51
|
|
|
@@ -62,18 +66,21 @@ def _validate(options: TrackOptions) -> bool:
|
|
|
62
66
|
|
|
63
67
|
def _build_payload(options: TrackOptions, properties: Dict[str, Any]) -> Dict[str, Any]:
|
|
64
68
|
"""Build API payload from options."""
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"properties": properties,
|
|
73
|
-
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
74
|
-
}
|
|
75
|
-
]
|
|
69
|
+
event = {
|
|
70
|
+
"event_type": options.event_type,
|
|
71
|
+
"visitor_id": options.visitor_id,
|
|
72
|
+
"session_id": options.session_id,
|
|
73
|
+
"user_id": options.user_id,
|
|
74
|
+
"properties": properties,
|
|
75
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
76
76
|
}
|
|
77
|
+
# Add ip and user_agent only if provided (for server-side session resolution)
|
|
78
|
+
if options.ip:
|
|
79
|
+
event["ip"] = options.ip
|
|
80
|
+
if options.user_agent:
|
|
81
|
+
event["user_agent"] = options.user_agent
|
|
82
|
+
|
|
83
|
+
return {"events": [event]}
|
|
77
84
|
|
|
78
85
|
|
|
79
86
|
def _parse_response(response: Optional[Dict[str, Any]], options: TrackOptions) -> TrackResult:
|
|
@@ -97,6 +104,8 @@ def track(
|
|
|
97
104
|
session_id: Optional[str] = None,
|
|
98
105
|
user_id: Optional[str] = None,
|
|
99
106
|
properties: Optional[Dict[str, Any]] = None,
|
|
107
|
+
ip: Optional[str] = None,
|
|
108
|
+
user_agent: Optional[str] = None,
|
|
100
109
|
) -> TrackResult:
|
|
101
110
|
"""Track an event.
|
|
102
111
|
|
|
@@ -106,6 +115,8 @@ def track(
|
|
|
106
115
|
session_id: Session ID (uses context if not provided)
|
|
107
116
|
user_id: User ID (uses context if not provided)
|
|
108
117
|
properties: Additional event properties
|
|
118
|
+
ip: Client IP address for server-side session resolution
|
|
119
|
+
user_agent: Client user agent for server-side session resolution
|
|
109
120
|
|
|
110
121
|
Returns:
|
|
111
122
|
TrackResult with success status and event details
|
|
@@ -116,6 +127,8 @@ def track(
|
|
|
116
127
|
session_id=session_id,
|
|
117
128
|
user_id=user_id,
|
|
118
129
|
properties=properties,
|
|
130
|
+
ip=ip,
|
|
131
|
+
user_agent=user_agent,
|
|
119
132
|
)
|
|
120
133
|
|
|
121
134
|
options = _resolve_ids(options)
|
mbuzz/context.py
CHANGED
|
@@ -14,6 +14,8 @@ class RequestContext:
|
|
|
14
14
|
user_id: Optional[str] = None
|
|
15
15
|
url: Optional[str] = None
|
|
16
16
|
referrer: Optional[str] = None
|
|
17
|
+
ip: Optional[str] = None
|
|
18
|
+
user_agent: Optional[str] = None
|
|
17
19
|
|
|
18
20
|
def enrich_properties(self, properties: Dict[str, Any]) -> Dict[str, Any]:
|
|
19
21
|
"""Add url and referrer to properties if not already present."""
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
mbuzz/__init__.py,sha256=
|
|
1
|
+
mbuzz/__init__.py,sha256=ip9lSCsNe7T5k1qOfGs4pttoTNGx5Ws-Zf9fHoWXFPg,2247
|
|
2
2
|
mbuzz/api.py,sha256=BITkW6TQEGmPA0OmYFFC611X6JWiY6C1dY-_wsKDT2U,2107
|
|
3
3
|
mbuzz/config.py,sha256=u6v1WnMTgiqyDXHszlXw5hyNENgYRy7-z-IWKuYp0-o,2399
|
|
4
|
-
mbuzz/context.py,sha256=
|
|
4
|
+
mbuzz/context.py,sha256=mM9Hi8GnqTkAVCqB_VKGCXl7a5AFME4WTM-2DCIji_w,1290
|
|
5
5
|
mbuzz/cookies.py,sha256=MCpMljQXaqJ2bhEtTv1aKR2fuqLfGBFofjPRayAQGpw,197
|
|
6
6
|
mbuzz/client/__init__.py,sha256=oNOTpPKdt-b_VH_f848OQTbEEDFhlpbEjZ-WjKvh3JI,36
|
|
7
7
|
mbuzz/client/conversion.py,sha256=Ua3ngFWmH6ekm3ZanNf5up_jV8t5nf788ipM1usvZoM,2346
|
|
8
8
|
mbuzz/client/identify.py,sha256=duyd-OWdBo4w7-7Nv5X-GeG2IpMI-1G_kYwnDXup0FE,859
|
|
9
9
|
mbuzz/client/session.py,sha256=mk8v892bvpeW-VNKFQYDsW442w881yfXBiM4sr9a0SU,835
|
|
10
|
-
mbuzz/client/track.py,sha256
|
|
10
|
+
mbuzz/client/track.py,sha256=HWRYWDWJ_WW_k5IHtkAn4s_MmVwSVFxsxR76KG2h_Ps,4288
|
|
11
11
|
mbuzz/middleware/__init__.py,sha256=gIjwTArToaQNB2NC0iPE_RcmzuHjH7-7jjd7_Dyq4Pw,37
|
|
12
12
|
mbuzz/middleware/flask.py,sha256=s3U77A2986L-KvWUH9MmqSwJwQWzQTYlZPZXH-wzE9o,4182
|
|
13
13
|
mbuzz/utils/__init__.py,sha256=-ejtRN6CTkV3D8uujDtAPDoMT0DAG-ULpWOF-Ae55dY,103
|
|
14
14
|
mbuzz/utils/identifier.py,sha256=iAYmd4he2RTtTNlmszb6KQmD9McZbSMgZZdkMuoGOCE,174
|
|
15
15
|
mbuzz/utils/session_id.py,sha256=3XJkzPg5iUIbRYzz5LThfS8WTAmlmtn60WZTA_TlVhk,1185
|
|
16
|
-
mbuzz-0.
|
|
17
|
-
mbuzz-0.
|
|
18
|
-
mbuzz-0.
|
|
16
|
+
mbuzz-0.2.0.dist-info/METADATA,sha256=3Z8snpq6fv0PmZUvSuAjsH1KaiZIpE9pRLVHTaw8cPE,1849
|
|
17
|
+
mbuzz-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
18
|
+
mbuzz-0.2.0.dist-info/RECORD,,
|
|
File without changes
|