Create a Uniq ID for user. Ideally this is done on install. If not, on a run - this then needs to be saved to the config
e.g.
def read_or_generate_uuid(config_file, section, option):
config = configparser.ConfigParser()
config.read(config_file)
if section in config and option in config[section]:
return config[section][option]
else:
new_uuid = str(uuid.uuid4())
config[section] = {option: new_uuid}
with open(config_file, 'w') as configfile:
config.write(configfile)
return new_uuid
Capture each time its run
Capture installs
from posthog import Posthog
def capture_event(event_name, properties={}):
try:
posthog = Posthog(project_api_key='phc_L5wgGTFZYVC1q8Hk7Qu0dp3YKuU1OUPSPGAx7kADWcs', host='https://app.posthog.com')
# Attempt to send the event to PostHog
posthog.capture(event_name, properties=properties)
print(f"Event '{event_name}' captured successfully!")
except posthog.RequestError as e:
# Handle the case when there's an issue with sending the event
print(f"Failed to capture event '{event_name}': {e}")
# You can add further logic here if needed, such as logging the error or continuing the script
# Example usage
event_name = 'App Run'
event_properties = {'user_id': userID, 'source': 'app', from_lang:fromLan,to_lang:toLang,voice_emgine,engine}
capture_event(event_name, event_properties)
https://posthog.com/docs/libraries/python