Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (34 sloc) 1.22 KB
# -*- coding: utf-8 -*-
from UniversalAnalytics import Tracker
import functools
TRACKING_CODE = "UA-XXXXXXXX-Y"
tracker = Tracker.create(TRACKING_CODE)
EXD_FORMART = "{0} on {1}"
def before_tracking(hittype, *args, **kwargs):
def receive_func(func):
@functools.wraps(func)
def wrapper(*wargs, **wkwargs):
tracker.send(hittype, *args, **kwargs)
print(hittype, args, kwargs)
return func(*wargs, **wkwargs)
return wrapper
return receive_func
def after_tracking(hittype, *args, **kwargs):
def receive_func(func):
@functools.wraps(func)
def wrapper(*wargs, **wkwargs):
try:
result = func(*wargs, **wkwargs)
print("normal", hittype)
tracker.send(hittype, *args, **kwargs)
return result
except Exception as e:
exd = EXD_FORMART.format(e.message, func.__name__)
print("exception", hittype, exd)
tracker.send("exception", {'exd': exd}, *args, **kwargs)
raise e
return
return wrapper
return receive_func
def send(hittype, *args, **kwargs):
tracker.send(hittype, *args, **kwargs)