remove analytics events

This commit is contained in:
Jude Nelson
2017-09-26 16:31:22 -04:00
parent 6dd49cb90d
commit eaeb2d19d8

View File

@@ -37,8 +37,6 @@ log = get_logger()
# ancillary storage providers
STORAGE_IMPL = None
ANALYTICS_KEY = None
def session(conf=None, config_path=CONFIG_PATH, server_host=None, server_port=None,
wallet_password=None, storage_drivers=None, metadata_dir=None,
@@ -149,148 +147,3 @@ def register_storage(storage_impl, conf, **driver_kw):
return rc
def get_analytics_key(uuid, proxy=None):
"""
Get the analytics key from the blockstack server
"""
key = os.environ.get('BLOCKSTACK_TEST_ANALYTICS_KEY', None)
if key is not None:
return key
try:
proxy = get_default_proxy() if proxy is None else proxy
key = proxy.get_analytics_key(uuid)
except Exception as e:
log.debug('Failed to get analytics key')
return
key = {} if key is None else key
if 'error' in key:
log.debug('Failed to fetch analytics key: {}'.format(key['error']))
return
key = key.get('analytics_key', None)
if key is not None:
return key
log.debug('No analytics key returned')
return
def analytics_event(event_type, event_payload, config_path=CONFIG_PATH,
proxy=None, analytics_key=None, action_tag='Perform action'):
"""
Log an analytics event
Return True if logged
Return False if not
The client uses 'Perform action' as its action tag, so we can distinguish
client events from server events. The server uses separate action tags.
"""
global ANALYTICS_KEY
try:
import mixpanel
except:
log.debug('mixpanel is not installed; no analytics will be reported')
return False
conf = get_config(path=config_path)
if conf is None:
log.debug('Failed to load config')
return False
if not conf['anonymous_statistics']:
return False
u = conf['uuid']
# use the given analytics key, if possible. or fallback.
analytics_key = ANALYTICS_KEY if analytics_key is None else analytics_key
# no fallback. so fetch from server.
if analytics_key is None:
ANALYTICS_KEY = get_analytics_key(u, proxy=proxy) if ANALYTICS_KEY is None else ANALYTICS_KEY
analytics_key = ANALYTICS_KEY
# all attempts failed. nothing more to do.
if analytics_key is None:
return False
# log the event
log.debug('Track event "{}": {}'.format(event_type, event_payload))
mp = mixpanel.Mixpanel(analytics_key)
mp.track(u, event_type, event_payload)
mp.track(u, action_tag, {})
return True
def analytics_user_register(u, email, config_path=CONFIG_PATH, proxy=None):
"""
Register a user with the analytics service
"""
global ANALYTICS_KEY
try:
import mixpanel
except:
log.debug('mixpanel is not installed; no analytics will be reported')
return False
conf = get_config(path=config_path)
if conf is None:
log.debug('Failed to load config')
return False
if not conf['anonymous_statistics']:
return False
ANALYTICS_KEY = get_analytics_key(u) if ANALYTICS_KEY is None else ANALYTICS_KEY
if ANALYTICS_KEY is None:
return False
# register the user
log.debug('Register user "{}"'.format(u))
mp = mixpanel.Mixpanel(ANALYTICS_KEY)
mp.people_set_once(u, {})
return True
def analytics_user_update(payload, proxy=None, config_path=CONFIG_PATH):
"""
Update a user's info on the analytics service
"""
global ANALYTICS_KEY
try:
import mixpanel
except:
log.debug('mixpanel is not installed; no analytics will be reported')
return False
conf = get_config(config_path)
if conf is None:
log.debug('Failed to load config')
return False
if not conf['anonymous_statistics']:
return False
u = conf['uuid']
ANALYTICS_KEY = get_analytics_key(u) if ANALYTICS_KEY is None else ANALYTICS_KEY
if ANALYTICS_KEY is None:
return False
# update the user
log.debug('Update user "{}"'.format(u))
mp = mixpanel.Mixpanel(ANALYTICS_KEY)
mp.people_append(u, payload)
return True