Adds basic analytics framework (mixpanel)

- Tracking launch event, with arguments passed
This commit is contained in:
Abhay Rana 2014-09-30 23:30:36 +05:30
parent d9e6e51722
commit 93c9647b3b
3 changed files with 33 additions and 0 deletions

View File

@ -26,11 +26,13 @@ import signal
from hackernews import HackerNews from hackernews import HackerNews
from chrome import Chrome from chrome import Chrome
from version import Version from version import Version
from analytics import Analytics
class HackerNewsApp: class HackerNewsApp:
HN_URL_PREFIX = "https://news.ycombinator.com/item?id=" HN_URL_PREFIX = "https://news.ycombinator.com/item?id="
UPDATE_URL = "https://github.com/captn3m0/hackertray#upgrade" UPDATE_URL = "https://github.com/captn3m0/hackertray#upgrade"
ABOUT_URL = "https://github.com/captn3m0/hackertray" ABOUT_URL = "https://github.com/captn3m0/hackertray"
MIXPANEL_TOKEN = "51a04e37dad59393c7371407e84a8050"
def __init__(self, args): def __init__(self, args):
#Load the database #Load the database
home = expanduser("~") home = expanduser("~")
@ -42,6 +44,9 @@ class HackerNewsApp:
except ValueError: except ValueError:
self.db = set() self.db = set()
# Setup analytics
Analytics.setup(args.dnt, HackerNewsApp.MIXPANEL_TOKEN)
# create an indicator applet # create an indicator applet
self.ind = appindicator.Indicator("Hacker Tray", "hacker-tray", appindicator.CATEGORY_APPLICATION_STATUS) self.ind = appindicator.Indicator("Hacker Tray", "hacker-tray", appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE) self.ind.set_status(appindicator.STATUS_ACTIVE)
@ -91,6 +96,11 @@ class HackerNewsApp:
self.ind.set_menu(self.menu) self.ind.set_menu(self.menu)
self.refresh(chrome_data_directory=args.chrome) 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): def toggleComments(self, widget):
"""Whether comments page is opened or not""" """Whether comments page is opened or not"""
self.commentState = not self.commentState self.commentState = not self.commentState
@ -195,7 +205,9 @@ def main():
parser.add_argument('-v','--version', action='version', version=Version.current()) 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('-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('--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(comments=False)
parser.set_defaults(dnt=False)
args = parser.parse_args() args = parser.parse_args()
indicator = HackerNewsApp(args) indicator = HackerNewsApp(args)
indicator.run() indicator.run()

20
hackertray/analytics.py Normal file
View File

@ -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)

View File

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