mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 17:56:11 +00:00
ping GA server to keep analytic sessions alive
This commit is contained in:
parent
198ece54e1
commit
d9b9901a04
2 changed files with 23 additions and 9 deletions
|
@ -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'))
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue