mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Add Google Analytics
This commit is contained in:
parent
e42292e68b
commit
15596645c6
5 changed files with 87 additions and 1 deletions
|
@ -12,6 +12,7 @@ import clientinfo
|
||||||
import read_embyserver as embyserver
|
import read_embyserver as embyserver
|
||||||
import connect.connectionmanager as connectionmanager
|
import connect.connectionmanager as connectionmanager
|
||||||
from dialogs import ServerConnect, UsersConnect, LoginConnect, LoginManual, ServerManual
|
from dialogs import ServerConnect, UsersConnect, LoginConnect, LoginManual, ServerManual
|
||||||
|
from ga_client import GoogleAnalytics
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
@ -137,6 +138,10 @@ class ConnectManager(object):
|
||||||
raise RuntimeError("Connect user is not logged in")
|
raise RuntimeError("Connect user is not logged in")
|
||||||
|
|
||||||
def login(self, server=None):
|
def login(self, server=None):
|
||||||
|
|
||||||
|
ga = GoogleAnalytics()
|
||||||
|
ga.sendEventData("Connect", "UserLogin")
|
||||||
|
|
||||||
# Return user or raise error
|
# Return user or raise error
|
||||||
server = server or self.state['Servers'][0]
|
server = server or self.state['Servers'][0]
|
||||||
server_address = connectionmanager.getServerAddress(server, server['LastConnectionMode'])
|
server_address = connectionmanager.getServerAddress(server, server['LastConnectionMode'])
|
||||||
|
|
|
@ -120,6 +120,7 @@ def doMainListing():
|
||||||
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
||||||
|
|
||||||
def emby_connect():
|
def emby_connect():
|
||||||
|
|
||||||
# Login user to emby connect
|
# Login user to emby connect
|
||||||
connect = connectmanager.ConnectManager()
|
connect = connectmanager.ConnectManager()
|
||||||
try:
|
try:
|
||||||
|
|
66
resources/lib/ga_client.py
Normal file
66
resources/lib/ga_client.py
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
|
import clientinfo
|
||||||
|
import md5
|
||||||
|
from utils import window, settings, language as lang
|
||||||
|
|
||||||
|
log = logging.getLogger("EMBY."+__name__)
|
||||||
|
|
||||||
|
class GoogleAnalytics():
|
||||||
|
|
||||||
|
testing = False
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
client_info = clientinfo.ClientInfo()
|
||||||
|
self.version = client_info.get_version()
|
||||||
|
self.device_id = client_info.get_device_id()
|
||||||
|
self.device_name = client_info.get_device_name() + "-" + client_info.get_platform()
|
||||||
|
|
||||||
|
# Use set user name
|
||||||
|
self.user_name = settings('username') or settings('connectUsername') or 'None'
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
def sendEventData(self, eventCategory, eventAction):
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
data['tid'] = 'UA-85356267-1' # tracking id, this is the account ID
|
||||||
|
|
||||||
|
data['ds'] = 'plugin' # data source
|
||||||
|
|
||||||
|
data['an'] = 'Kodi4Emby' # App Name
|
||||||
|
data['aid'] = '1' # App ID
|
||||||
|
data['av'] = self.version # App Version
|
||||||
|
#data['aiid'] = '1.1' # App installer ID
|
||||||
|
|
||||||
|
data['cid'] = self.device_id # Client ID
|
||||||
|
data['uid'] = self.user_name # User ID
|
||||||
|
|
||||||
|
data['ua'] = self.device_name # user agent string
|
||||||
|
|
||||||
|
data['t'] = 'event' # action type
|
||||||
|
data['ec'] = eventCategory # Event Category
|
||||||
|
data['ea'] = eventAction # Event Action
|
||||||
|
#data['el'] = 'Play' # Event Label
|
||||||
|
|
||||||
|
log.info("GOOGLEANALYTICS : " + str(data))
|
||||||
|
|
||||||
|
if(self.testing):
|
||||||
|
url = "https://www.google-analytics.com/debug/collect" # test URL
|
||||||
|
else:
|
||||||
|
url = "https://www.google-analytics.com/collect" # prod URL
|
||||||
|
|
||||||
|
r = requests.post(url, data)
|
||||||
|
|
||||||
|
if(self.testing):
|
||||||
|
log.error("GOOGLEANALYTICS : " + r.text.encode('utf-8'))
|
||||||
|
|
|
@ -22,6 +22,7 @@ import read_embyserver as embyserver
|
||||||
import userclient
|
import userclient
|
||||||
import videonodes
|
import videonodes
|
||||||
from utils import window, settings, language as lang
|
from utils import window, settings, language as lang
|
||||||
|
from ga_client import GoogleAnalytics
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
@ -75,9 +76,13 @@ class LibrarySync(threading.Thread):
|
||||||
|
|
||||||
def startSync(self):
|
def startSync(self):
|
||||||
|
|
||||||
|
ga = GoogleAnalytics()
|
||||||
|
|
||||||
# Run at start up - optional to use the server plugin
|
# Run at start up - optional to use the server plugin
|
||||||
if settings('SyncInstallRunDone') == "true":
|
if settings('SyncInstallRunDone') == "true":
|
||||||
|
|
||||||
|
ga.sendEventData("SyncAction", "FastSync")
|
||||||
|
|
||||||
# Validate views
|
# Validate views
|
||||||
self.refreshViews()
|
self.refreshViews()
|
||||||
completed = False
|
completed = False
|
||||||
|
@ -99,6 +104,7 @@ class LibrarySync(threading.Thread):
|
||||||
completed = ManualSync().sync()
|
completed = ManualSync().sync()
|
||||||
else:
|
else:
|
||||||
# Install sync is not completed
|
# Install sync is not completed
|
||||||
|
ga.sendEventData("SyncAction", "FullSync")
|
||||||
completed = self.fullSync()
|
completed = self.fullSync()
|
||||||
|
|
||||||
return completed
|
return completed
|
||||||
|
|
|
@ -18,6 +18,7 @@ import player
|
||||||
import videonodes
|
import videonodes
|
||||||
import websocket_client as wsc
|
import websocket_client as wsc
|
||||||
from utils import window, settings, dialog, language as lang
|
from utils import window, settings, dialog, language as lang
|
||||||
|
from ga_client import GoogleAnalytics
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -147,6 +148,10 @@ class Service(object):
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
def _startup(self):
|
def _startup(self):
|
||||||
|
|
||||||
|
ga = GoogleAnalytics()
|
||||||
|
ga.sendEventData("Application", "Startup")
|
||||||
|
|
||||||
# Start up events
|
# Start up events
|
||||||
self.warn_auth = True
|
self.warn_auth = True
|
||||||
|
|
||||||
|
@ -283,6 +288,9 @@ class Service(object):
|
||||||
log.exception(error)
|
log.exception(error)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
|
||||||
|
ga = GoogleAnalytics()
|
||||||
|
ga.sendEventData("Application", "Shutdown")
|
||||||
|
|
||||||
if self.userclient_running:
|
if self.userclient_running:
|
||||||
self.userclient_thread.stop_client()
|
self.userclient_thread.stop_client()
|
||||||
|
|
Loading…
Reference in a new issue