hackertray/hackertray/analytics.py

28 lines
813 B
Python
Raw Normal View History

from mixpanel import Mixpanel
2017-12-24 13:25:20 +00:00
class Analytics:
# Setup analytics.
# dnt - do not track. Disables tracking if True
# token - The mixpanel token
2017-12-24 13:25:20 +00:00
def __init__(self, dnt, token):
self.dnt = dnt
self.tracker = Mixpanel(token)
if(self.dnt == True):
2017-12-24 11:13:07 +00:00
print("[+] Analytics disabled")
# Track an event
# event - string containing the event name
# data - data related to the event, defaults to {}
2017-12-24 13:25:20 +00:00
def track(self, event, data={}):
if(self.dnt == False):
# All events are tracked anonymously
self.tracker.track("anonymous", event, data)
2014-10-01 02:14:32 +00:00
# Track a visit to a URL
2017-12-24 13:25:20 +00:00
# The url maybe an HN submission or
2014-10-01 02:14:32 +00:00
# some meta-url pertaining to hackertray
2017-12-24 13:25:20 +00:00
def visit(self, url):
2017-12-24 13:25:20 +00:00
self.track('visit', {"link": url})