From ab33ef5848a13bb5b7a8be17a8e390e1c14bcd79 Mon Sep 17 00:00:00 2001 From: sfaulds Date: Fri, 14 Oct 2016 14:35:34 +1100 Subject: [PATCH] add screen app size to GA only ping GA if playing dont send an app stopped message --- resources/lib/ga_client.py | 8 ++++++++ resources/lib/librarysync.py | 5 ++--- resources/lib/player.py | 3 +++ resources/lib/service_entry.py | 15 ++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/resources/lib/ga_client.py b/resources/lib/ga_client.py index 037a5ad6..ba582045 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -5,6 +5,7 @@ import requests import logging import clientinfo import md5 +import xbmcgui from utils import window, settings, language as lang log = logging.getLogger("EMBY."+__name__) @@ -29,6 +30,10 @@ class GoogleAnalytics(): # use md5 for client and user for analytics self.device_id = md5.new(self.device_id).hexdigest() self.user_name = md5.new(self.user_name).hexdigest() + + # resolution + self.height = xbmcgui.Window(10000).getHeight() + self.width = xbmcgui.Window(10000).getWidth() def formatException(self): exc_type, exc_obj, exc_tb = sys.exc_info() @@ -76,6 +81,9 @@ class GoogleAnalytics(): data['t'] = 'event' # action type data['ec'] = eventCategory # Event Category data['ea'] = eventAction # Event Action + + # add width and height + data['sr'] = str(self.width) + "x" + str(self.height) if(eventLabel != None): data['el'] = eventLabel # Event Label diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 7279b996..27df195d 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -81,9 +81,6 @@ class LibrarySync(threading.Thread): # Run at start up - optional to use the server plugin if settings('SyncInstallRunDone') == "true": - - ga.sendEventData("SyncAction", "FastSync") - # Validate views self.refreshViews() completed = False @@ -97,11 +94,13 @@ class LibrarySync(threading.Thread): if plugin['Name'] == "Emby.Kodi Sync Queue": log.debug("Found server plugin.") self.isFastSync = True + ga.sendEventData("SyncAction", "FastSync") completed = self.fastSync() break if not completed: # Fast sync failed or server plugin is not found + ga.sendEventData("SyncAction", "Sync") completed = ManualSync().sync() else: # Install sync is not completed diff --git a/resources/lib/player.py b/resources/lib/player.py index f7e0c13a..4e4c1fd8 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -476,6 +476,9 @@ class Player(xbmc.Player): xbmcvfs.delete("%s%s" % (path, file)) self.played_info.clear() + + ga = GoogleAnalytics() + ga.sendEventData("PlayAction", "Stopped") def stopPlayback(self, data): diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index ad6ae247..07ff0224 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -140,13 +140,14 @@ class Service(object): # or Kodi is shut down. self._server_online_check() - # ping metrics server to keep sessions alive - # ping every 3 min + # ping metrics server to keep sessions alive while playing + # ping every 5 min timeSinceLastPing = time.time() - self.lastMetricPing - if(timeSinceLastPing > 180): + if(timeSinceLastPing > 300): self.lastMetricPing = time.time() - ga = GoogleAnalytics() - ga.sendEventData("Application", "Ping") + if self.kodi_player.isPlaying(): + ga = GoogleAnalytics() + ga.sendEventData("PlayAction", "PlayPing") if self.monitor.waitForAbort(1): # Abort was requested while waiting. We should exit @@ -297,8 +298,8 @@ class Service(object): def shutdown(self): - ga = GoogleAnalytics() - ga.sendEventData("Application", "Shutdown") + #ga = GoogleAnalytics() + #ga.sendEventData("Application", "Shutdown") if self.userclient_running: self.userclient_thread.stop_client()