MCPcopy
hub / github.com/PostHog/posthog / capture

Method capture

posthog/demo/matrix/models.py:205–235  ·  view source on GitHub ↗

Capture an arbitrary event. Similar to JS `posthog.capture()`.

(self, event: str, properties: Optional[Properties] = None)

Source from the content-addressed store, hash-verified

203 return self.person
204
205 def capture(self, event: str, properties: Optional[Properties] = None):
206 """Capture an arbitrary event. Similar to JS `posthog.capture()`."""
207 combined_properties: Properties = {
208 "$device_type": self.device_type,
209 "$os": self.os,
210 "$browser": self.browser,
211 "$session_id": self.active_session_id,
212 "$device_id": self.device_id,
213 }
214 if self.super_properties:
215 combined_properties.update(self.super_properties)
216 if self.current_url is not None:
217 parsed_current_url = urlparse(self.current_url)
218 combined_properties["$current_url"] = self.current_url
219 combined_properties["$host"] = parsed_current_url.netloc
220 combined_properties["$pathname"] = parsed_current_url.path
221 if "$set" not in combined_properties:
222 combined_properties["$set"] = {}
223 if properties:
224 if referrer := properties.get("$referrer"):
225 referring_domain = urlparse(referrer).netloc if referrer != "$direct" else referrer
226 referrer_properties = {"$referrer": referrer, "$referring_domain": referring_domain}
227 self.register(referrer_properties)
228 combined_properties["$set"].update(referrer_properties)
229 combined_properties["$referring_domain"] = referring_domain
230 combined_properties.update(properties)
231 # GeoIP
232 combined_properties[PROPERTY_GEOIP_COUNTRY_CODE] = self.person.country_code
233 combined_properties["$set"][PROPERTY_GEOIP_COUNTRY_CODE] = self.person.country_code
234 # Saving
235 super()._capture_raw(event, combined_properties, distinct_id=self.active_distinct_id)
236
237 def capture_pageview(
238 self, current_url: str, properties: Optional[Properties] = None, *, referrer: Optional[str] = None

Callers 4

__exit__Method · 0.95
capture_pageviewMethod · 0.95
identifyMethod · 0.95
groupMethod · 0.95

Calls 4

registerMethod · 0.95
_capture_rawMethod · 0.80
getMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected