Package: nucleus-python
nucleus-pythonWe tried to make it as simple as possible to report the data you need to analyze your app usage and improve it.This module is compatible with Python 3+.To start using this module, sign up and get an app ID onNucleus.sh.Installation$pipinstallnucleus-pythonBasic usageAdd the following code to import Nucleus and init the analytics.Don't use theimport ... fromsyntax as you won't be able to set the module options likeapp_id.importnucleusnucleus.app_id='your app id'nucleus.set_props({'version':'0.5.0',# Set app version (Nucleus cannot detect it)'userId':'richard_hendrix'})nucleus.app_started()Only useapp_started()once per session, if you are using Nucleus in several files call app_started() the earliest possible.Sign up and get a tracking ID for your apphere.OptionsYou can init Nucleus with options:nucleus.report_interval=20# interval (in seconds) between server comnucleus.disable_tracking=False# completely disable trackingnucleus.debug=False# Show internal logs to help debugnucleus.auto_user_id=False# Assign the user an IDIdentify usersYou can track specific users actions on the 'User Explorer' section of your dashboard by assigning an user ID.It can be any value as long as it is astring.nucleus.set_user_id('someUniqueUserId')Alternatively, set theauto_user_idoption of the module toTrueto automatically assign the user an ID based on his username and hostname.Modify automatic dataYou can overwrite some properties or fill data that wasn't detected.You have to do it before callingapp_started()for this to workIt is a good idea to set your app version directly as Nucleuscannot detect itfor the moment.nucleus.set_props({'version':'0.5.0','locale':'en_US'})Track custom dataYou can also add custom data along with the automatic data.Those will be visible in your user dashboardif you previously set an user ID.The module will remember past properties so you can usenucleus.set_propsmultiple times without overwriting past props.Properties can eithernumbers,stringsorbooleans.
Nested properties or arrays aren't supported at the moment.nucleus.set_props({"age":34,"name":'Richard Hendricks',"job":'CEO'})To overwrite past properties, set the second parameter toTrue.nucleus.set_props({"age":23},True)ErrorsTo catch errors with Nucleus, simply add the tracking code to an exception and pass the exception as the unique parameter.Nucleus will extract the relevant informations and show them in your dashboard.try:my_app()exceptExceptionase:nucleus.track_error(e)Add this at the outermost level of your code to handle any otherwise uncaught exceptions before terminating.The advantage of except Exception over the bare except is that there are a few exceptions that it wont catch, most obviously KeyboardInterrupt and SystemExit.EventsAfter initializing Nucleus, you can send your own custom events.nucleus.track("PLAYED_TRACK")They are a couple event names that are reserved by Nucleus:init,error:andnucleus:.You shouldn't report events containing these strings.Tracking with dataYou can add extra information to tracked events, as an object.Properties can eithernumbers,stringsorbooleans.Nested properties or arrays aren't supported at the moment.Example:nucleus.track("PLAYED_TRACK",data={"trackName":'My Awesome Song',"duration":120})Toggle trackingThis will completely disable any communication with Nucleus' servers.To opt-out your users from tracking:nucleus.disable_tracking()and to opt back in:nucleus.enable_tracking()This doesn't persist after restarts so you have to handle saving the setting.Contacthello@nucleus.shfor any inquiry