def track_event(category=None, action=None, label=None, value=None, identifier=None, first_use=None, add=None, noninteraction=True): anonymousConfig = Config() anonymousConfig.anonimize_ip_address = True tracker = Tracker('UA-86466078-1', 'none', conf=anonymousConfig) visitor = Visitor() # convert the last 8 bytes of the machine identifier to an integer to get a "unique" user visitor.unique_id = struct.unpack("!I", binascii.unhexlify(identifier[32:]))[0]/2 if add: # add visitor's ip address (will be anonymized) visitor.ip_address = add if first_use: visitor.first_visit_time = first_use session = Session() event = Event(category=category, action=action, label=label, value=value, noninteraction=noninteraction) path = u"/" + u"/".join([category, action, label]) page = Page(path.lower()) tracker.track_event(event, session, visitor) tracker.track_pageview(page, session, visitor)
def get_ga(): from pyga.requests import Tracker, Session, Config ga = plugin.get_storage("analytics") config = Config() config.anonimize_ip_address = True tracker = Tracker(TRACKING_ID, 'steeve.io', conf=config) session = ga.setdefault("session", Session()) visitor = ensure_screen_res(ga.setdefault("visitor", make_visitor())) return tracker, session, visitor
def track_event(category=None, action=None, label=None): if not settings.analytics.getboolean('enabled'): return anonymousConfig = Config() anonymousConfig.anonimize_ip_address = True tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig) try: if os.path.isfile(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat'))): with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'r') as handle: visitor_text = handle.read() visitor = pickle.loads(codecs.decode(visitor_text.encode(), "base64")) if visitor.user_agent is None: visitor.user_agent = os.environ.get("SZ_USER_AGENT") if visitor.unique_id > int(0x7fffffff): visitor.unique_id = random.randint(0, 0x7fffffff) else: visitor = Visitor() visitor.unique_id = random.randint(0, 0x7fffffff) except: visitor = Visitor() visitor.unique_id = random.randint(0, 0x7fffffff) session = Session() event = Event(category=category, action=action, label=label, value=1) tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion', value=os.environ["BAZARR_VERSION"].lstrip('v'), scope=1)) tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1)) if settings.general.getboolean('use_sonarr'): tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1)) else: tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value='unused', scope=1)) if settings.general.getboolean('use_radarr'): tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1)) else: tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value='unused', scope=1)) tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1)) try: tracker.track_event(event, session, visitor) except: logging.debug("BAZARR unable to track event.") pass else: with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'w+') as handle: handle.write(codecs.encode(pickle.dumps(visitor), "base64").decode())
def get_ga(): from pyga.requests import Tracker, Session, Config with plugin.get_storage("analytics") as ga: config = Config() tracker = Tracker(TRACKING_ID, 'steeve.io', conf=config) session = ga.setdefault("session", Session()) if not ga.get("visitor"): ga["visitor"] = make_visitor() return tracker, session, ga["visitor"]
def track_event(category=None, action=None, label=None): if not settings.analytics.getboolean('enabled'): return anonymousConfig = Config() anonymousConfig.anonimize_ip_address = True tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig) try: visitor = pickle.loads(base64.b64decode(settings.analytics.visitor)) except: visitor = Visitor() unique_id = long(random.getrandbits(32)) visitor.unique_id = unique_id session = Session() event = Event(category=category, action=action, label=label, value=1) path = u"/" + u"/".join([category, action, label]) page = Page(path.lower()) tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion', value=os.environ["BAZARR_VERSION"], scope=1)) tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1)) if settings.general.getboolean('use_sonarr'): tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1)) if settings.general.getboolean('use_radarr'): tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1)) tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1)) try: tracker.track_event(event, session, visitor) tracker.track_pageview(page, session, visitor) except: pass else: settings.analytics.visitor = base64.b64encode(pickle.dumps(visitor)) with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: settings.write(handle)
import xbmc import xbmcaddon import time import random import threading from urllib import unquote, quote, quote_plus try: from hashlib import md5 except: from md5 import md5 GAUID='UA-31027962-2' from pyga.requests import Tracker, Page, Session, Visitor, Event, Config CONFIG = Config() CONFIG.anonimize_ip_address = True tracker = Tracker(GAUID, 'xbmc.ru', conf=CONFIG) import pickle def get_platform(): platforms = { "Linux": "X11; Linux", "Windows": "Windows NT %d.%d", "OSX": "Macintosh; Intel Mac OS X", "IOS": "iPad; CPU OS 6_1 like Mac OS X", } for platform, ua_platform_name in platforms.items(): if xbmc.getCondVisibility("System.Platform.%s" % platform): if platform == "Windows":