mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 12:16:12 +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__)
|
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():
|
class GoogleAnalytics():
|
||||||
|
|
||||||
testing = False
|
testing = False
|
||||||
|
@ -52,12 +55,6 @@ class GoogleAnalytics():
|
||||||
|
|
||||||
def sendEventData(self, eventCategory, eventAction, eventLabel=None):
|
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
|
# all the data we can send to Google Analytics
|
||||||
data = {}
|
data = {}
|
||||||
data['v'] = '1'
|
data['v'] = '1'
|
||||||
|
@ -82,8 +79,15 @@ class GoogleAnalytics():
|
||||||
if(eventLabel != None):
|
if(eventLabel != None):
|
||||||
data['el'] = eventLabel # Event Label
|
data['el'] = eventLabel # Event Label
|
||||||
|
|
||||||
|
self.sendData(data)
|
||||||
|
|
||||||
|
def sendData(self, data):
|
||||||
|
|
||||||
log.info("GA: " + str(data))
|
log.info("GA: " + str(data))
|
||||||
|
|
||||||
|
if(settings('metricLogging') == "false"):
|
||||||
|
return
|
||||||
|
|
||||||
if(self.testing):
|
if(self.testing):
|
||||||
url = "https://www.google-analytics.com/debug/collect" # test URL
|
url = "https://www.google-analytics.com/debug/collect" # test URL
|
||||||
else:
|
else:
|
||||||
|
@ -97,3 +101,5 @@ class GoogleAnalytics():
|
||||||
if(self.testing):
|
if(self.testing):
|
||||||
log.info("GA: " + r.text.encode('utf-8'))
|
log.info("GA: " + r.text.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import _strptime # Workaround for threads using datetime: _striptime is locked
|
import _strptime # Workaround for threads using datetime: _striptime is locked
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ class Service(object):
|
||||||
library_thread = None
|
library_thread = None
|
||||||
|
|
||||||
last_progress = datetime.today()
|
last_progress = datetime.today()
|
||||||
|
lastMetricPing = time.time()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
@ -139,6 +140,13 @@ class Service(object):
|
||||||
# or Kodi is shut down.
|
# or Kodi is shut down.
|
||||||
self._server_online_check()
|
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):
|
if self.monitor.waitForAbort(1):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
|
|
Loading…
Reference in a new issue