Fixes a minor bug with the visit event

- Analytics is no longer static.
analytics
Abhay Rana 8 years ago
parent 4edb2a2053
commit 0c314e690b
  1. 12
      hackertray/__init__.py
  2. 21
      hackertray/analytics.py

@ -47,7 +47,7 @@ class HackerNewsApp:
self.db = set()
# Setup analytics
Analytics.setup(args.dnt, HackerNewsApp.MIXPANEL_TOKEN)
self.tracker = Analytics(args.dnt, HackerNewsApp.MIXPANEL_TOKEN)
# create an indicator applet
self.ind = appindicator.Indicator("Hacker Tray", "hacker-tray", appindicator.CATEGORY_APPLICATION_STATUS)
@ -108,7 +108,7 @@ class HackerNewsApp:
launch_data['browser'] = subprocess.check_output(["xdg-settings","get","default-web-browser"]).strip()
except subprocess.CalledProcessError as e:
launch_data['browser'] = "unknown"
Analytics.track('launch', launch_data)
self.tracker.track('launch', launch_data)
def toggleComments(self, widget):
"""Whether comments page is opened or not"""
@ -119,13 +119,13 @@ class HackerNewsApp:
webbrowser.open(HackerNewsApp.UPDATE_URL)
# Remove the update button once clicked
self.menu.remove(widget)
Analytics.visit(HackerNewsApp.UPDATE_URL)
self.tracker.visit(HackerNewsApp.UPDATE_URL)
def showAbout(self, widget):
"""Handle the about btn"""
webbrowser.open(HackerNewsApp.ABOUT_URL)
Analytics.visit(HackerNewsApp.ABOUT_URL)
self.tracker.visit(HackerNewsApp.ABOUT_URL)
#ToDo: Handle keyboard interrupt properly
def quit(self, widget, data=None):
@ -138,7 +138,7 @@ class HackerNewsApp:
file.write(json.dumps(l))
gtk.main_quit()
Analytics.track('quit')
self.tracker.track('quit')
def run(self):
signal.signal(signal.SIGINT, self.quit)
@ -159,7 +159,7 @@ class HackerNewsApp:
if self.commentState:
webbrowser.open(self.HN_URL_PREFIX + widget.hn_id)
Analytics.visit(widget.url)
self.tracker.visit(widget.url)
def addItem(self, item):
"""Adds an item to the menu"""

@ -4,23 +4,20 @@ 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):
def __init__(self, dnt, token):
self.dnt = dnt
self.tracker = Mixpanel(token)
if(self.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):
def track(self, event, data = {}):
if(self.dnt == False):
# All events are tracked anonymously
Analytics.tracker.track("anonymous", event, data)
self.tracker.track("anonymous", event, data)
# Track a visit to a URL
# The url maybe an HN submission or
# some meta-url pertaining to hackertray
@staticmethod
def visit(url):
Analytics.track('visit', url)
def visit(self, url):
self.track('visit', {"link":url})
Loading…
Cancel
Save