diff --git a/PlexPy.py b/PlexPy.py index b786d7c3..06284d2d 100755 --- a/PlexPy.py +++ b/PlexPy.py @@ -62,7 +62,7 @@ def main(): try: locale.setlocale(locale.LC_ALL, "") - plexpy.SYS_ENCODING = locale.getpreferredencoding() + plexpy.SYS_LANGUAGE, plexpy.SYS_ENCODING = locale.getdefaultlocale() except (locale.Error, IOError): pass diff --git a/lib/UniversalAnalytics/Tracker.py b/lib/UniversalAnalytics/Tracker.py index b336e493..62d393ff 100644 --- a/lib/UniversalAnalytics/Tracker.py +++ b/lib/UniversalAnalytics/Tracker.py @@ -303,6 +303,7 @@ Tracker.alias(safe_unicode, 'dr', 'referrer', 'referer') Tracker.alias(int, 'qt', 'queueTime', 'queue-time') Tracker.alias(safe_unicode, 't', 'hitType', 'hittype') Tracker.alias(int, 'aip', 'anonymizeIp', 'anonIp', 'anonymize-ip') +Tracker.alias(safe_unicode, 'ds', 'dataSource', 'data-source') # Campaign attribution Tracker.alias(safe_unicode, 'cn', 'campaign', 'campaignName', 'campaign-name') diff --git a/plexpy/__init__.py b/plexpy/__init__.py index fc96a8ef..efd8f720 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -15,7 +15,6 @@ import os from Queue import Queue -import shutil import sqlite3 import sys import subprocess @@ -56,6 +55,7 @@ ARGS = None SIGNAL = None SYS_PLATFORM = None +SYS_LANGUAGE = None SYS_ENCODING = None QUIET = False @@ -98,6 +98,8 @@ DEV = False WS_CONNECTED = False PLEX_SERVER_UP = None +TRACKER = None + def initialize(config_file): with INIT_LOCK: @@ -460,14 +462,17 @@ def start(): activity_pinger.connect_server(log=True, startup=True) if CONFIG.SYSTEM_ANALYTICS: - # Send analytic events + global TRACKER + TRACKER = initialize_tracker() + + # Send system analytics events if not CONFIG.FIRST_RUN_COMPLETE: - send_analytics(category='system', action='install') + analytics_event(category='system', action='install') if _UPDATE: - send_analytics(category='system', action='update') + analytics_event(category='system', action='update') - send_analytics(category='system', action='start') + analytics_event(category='system', action='start') _STARTED = True @@ -1684,14 +1689,35 @@ def generate_uuid(): return uuid.uuid4().hex -def send_analytics(category, action): - tracker = Tracker.create('UA-111522699-2', client_id=CONFIG.PMS_UUID, hash_client_id=True) - tracker.send('event', { - 'category': category, - 'action': action, +def initialize_tracker(): + data = { + 'dataSource': 'server', 'appName': 'Tautulli', 'appVersion': common.VERSION_NUMBER, 'appID': '{} {}'.format(common.PLATFORM, common.PLATFORM_VERSION), 'appInstallerId': plexpy.INSTALL_TYPE, + 'userLanguage': plexpy.SYS_LANGUAGE, + 'documentEncoding': plexpy.SYS_ENCODING, 'noninteractive': True - }) + } + + tracker = Tracker.create('UA-111522699-2', client_id=CONFIG.PMS_UUID, hash_client_id=True) + tracker.set(data) + + return tracker + + +def analytics_event(category, action, label=None, value=None, **kwargs): + data = {'category': category, 'action': action} + + if label is not None: + data['label'] = label + + if value is not None: + data['value'] = value + + if kwargs: + data.update(kwargs) + + if TRACKER: + TRACKER.send('event', data)