Add Google Analytics

This commit is contained in:
shaun 2016-10-09 20:14:45 +11:00
parent e42292e68b
commit 15596645c6
5 changed files with 87 additions and 1 deletions

View file

@ -12,6 +12,7 @@ import clientinfo
import read_embyserver as embyserver
import connect.connectionmanager as connectionmanager
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")
def login(self, server=None):
ga = GoogleAnalytics()
ga.sendEventData("Connect", "UserLogin")
# Return user or raise error
server = server or self.state['Servers'][0]
server_address = connectionmanager.getServerAddress(server, server['LastConnectionMode'])

View file

@ -120,6 +120,7 @@ def doMainListing():
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def emby_connect():
# Login user to emby connect
connect = connectmanager.ConnectManager()
try:

View 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'))

View file

@ -22,6 +22,7 @@ import read_embyserver as embyserver
import userclient
import videonodes
from utils import window, settings, language as lang
from ga_client import GoogleAnalytics
##################################################################################################
@ -75,9 +76,13 @@ class LibrarySync(threading.Thread):
def startSync(self):
ga = GoogleAnalytics()
# Run at start up - optional to use the server plugin
if settings('SyncInstallRunDone') == "true":
ga.sendEventData("SyncAction", "FastSync")
# Validate views
self.refreshViews()
completed = False
@ -99,6 +104,7 @@ class LibrarySync(threading.Thread):
completed = ManualSync().sync()
else:
# Install sync is not completed
ga.sendEventData("SyncAction", "FullSync")
completed = self.fullSync()
return completed

View file

@ -18,6 +18,7 @@ import player
import videonodes
import websocket_client as wsc
from utils import window, settings, dialog, language as lang
from ga_client import GoogleAnalytics
#################################################################################################
@ -147,6 +148,10 @@ class Service(object):
self.shutdown()
def _startup(self):
ga = GoogleAnalytics()
ga.sendEventData("Application", "Startup")
# Start up events
self.warn_auth = True
@ -283,6 +288,9 @@ class Service(object):
log.exception(error)
def shutdown(self):
ga = GoogleAnalytics()
ga.sendEventData("Application", "Shutdown")
if self.userclient_running:
self.userclient_thread.stop_client()