Adds basic analytics framework (mixpanel)

- Tracking launch event, with arguments passed
analytics
Abhay Rana 8 years ago
parent d9e6e51722
commit 93c9647b3b
  1. 12
      hackertray/__init__.py
  2. 20
      hackertray/analytics.py
  3. 1
      setup.py

@ -26,11 +26,13 @@ import signal
from hackernews import HackerNews
from chrome import Chrome
from version import Version
from analytics import Analytics
class HackerNewsApp:
HN_URL_PREFIX = "https://news.ycombinator.com/item?id="
UPDATE_URL = "https://github.com/captn3m0/hackertray#upgrade"
ABOUT_URL = "https://github.com/captn3m0/hackertray"
MIXPANEL_TOKEN = "51a04e37dad59393c7371407e84a8050"
def __init__(self, args):
#Load the database
home = expanduser("~")
@ -42,6 +44,9 @@ class HackerNewsApp:
except ValueError:
self.db = set()
# Setup analytics
Analytics.setup(args.dnt, HackerNewsApp.MIXPANEL_TOKEN)
# create an indicator applet
self.ind = appindicator.Indicator("Hacker Tray", "hacker-tray", appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
@ -91,6 +96,11 @@ class HackerNewsApp:
self.ind.set_menu(self.menu)
self.refresh(chrome_data_directory=args.chrome)
# Now that we're all done with the boot, send a beacone home
launch_data = vars(args)
launch_data['version'] = Version.current()
Analytics.track('launch', launch_data)
def toggleComments(self, widget):
"""Whether comments page is opened or not"""
self.commentState = not self.commentState
@ -195,7 +205,9 @@ def main():
parser.add_argument('-v','--version', action='version', version=Version.current())
parser.add_argument('-c','--comments', dest='comments',action='store_true', help="Load the HN comments link for the article as well")
parser.add_argument('--chrome', dest='chrome', help="Specify a Google Chrome Profile directory to use for matching chrome history")
parser.add_argument('--dnt', dest='dnt',action='store_true', help="Disable all analytics (Do Not Track)")
parser.set_defaults(comments=False)
parser.set_defaults(dnt=False)
args = parser.parse_args()
indicator = HackerNewsApp(args)
indicator.run()

@ -0,0 +1,20 @@
from mixpanel import Mixpanel
class Analytics:
# Setup analytics.
# dnt - do not track. Disables tracking if True
# token - The mixpanel token
@staticmethod
def setup(dnt, token):
Analytics.dnt = dnt
Analytics.tracker = Mixpanel(token)
if(dnt == True):
print "[+] Analytics disabled"
# Track an event
# event - string containing the event name
# data - data related to the event, defaults to {}
@staticmethod
def track(event, data = {}):
if(Analytics.dnt == False):
# All events are tracked anonymously
Analytics.tracker.track("anonymous", event, data)

@ -23,6 +23,7 @@ setup(name='hackertray',
},
install_requires=[
'requests>=2.2.1',
'mixpanel-py>=3.0.0'
],
entry_points={
'console_scripts': ['hackertray = hackertray:main'],

Loading…
Cancel
Save