diff --git a/resources/lib/ga_client.py b/resources/lib/ga_client.py index 4a267727..10b664da 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -9,6 +9,9 @@ from utils import window, settings, language as lang log = logging.getLogger("EMBY."+__name__) +# for info on the metrics that can be sent to Google Analytics +# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#events + class GoogleAnalytics(): testing = False @@ -51,13 +54,7 @@ class GoogleAnalytics(): return errorType, errorFile def sendEventData(self, eventCategory, eventAction, eventLabel=None): - - if(settings('metricLogging') == "false"): - return - - # for info on the metrics that can be sent to Google Analytics - # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#events - + # all the data we can send to Google Analytics data = {} data['v'] = '1' @@ -82,8 +79,15 @@ class GoogleAnalytics(): if(eventLabel != None): data['el'] = eventLabel # Event Label + self.sendData(data) + + def sendData(self, data): + log.info("GA: " + str(data)) + if(settings('metricLogging') == "false"): + return + if(self.testing): url = "https://www.google-analytics.com/debug/collect" # test URL else: @@ -96,4 +100,6 @@ class GoogleAnalytics(): if(self.testing): log.info("GA: " + r.text.encode('utf-8')) + + \ No newline at end of file diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index d3f1fe76..ad6ae247 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -4,6 +4,7 @@ import logging import sys +import time import _strptime # Workaround for threads using datetime: _striptime is locked from datetime import datetime @@ -41,7 +42,7 @@ class Service(object): library_thread = None last_progress = datetime.today() - + lastMetricPing = time.time() def __init__(self): @@ -139,7 +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 + timeSinceLastPing = time.time() - self.lastMetricPing + if(timeSinceLastPing > 180): + self.lastMetricPing = time.time() + ga = GoogleAnalytics() + ga.sendEventData("Application", "Ping") + if self.monitor.waitForAbort(1): # Abort was requested while waiting. We should exit break