ping GA server to keep analytic sessions alive

This commit is contained in:
sfaulds 2016-10-13 11:47:43 +11:00
parent 198ece54e1
commit d9b9901a04
2 changed files with 23 additions and 9 deletions

View file

@ -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
@ -52,12 +55,6 @@ class GoogleAnalytics():
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:
@ -97,3 +101,5 @@ class GoogleAnalytics():
if(self.testing):
log.info("GA: " + r.text.encode('utf-8'))

View file

@ -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,6 +140,13 @@ 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