diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-11-20 20:40:59 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-11-21 01:19:34 +0100 |
commit | 905bc2e440060a6228725fe1e7abd9a1fce7b1e8 (patch) | |
tree | bbc763b9b15e0c812321b263b3ae27af55ad793d /application/MultiMC.cpp | |
parent | 2f8c752d1fe9976fdbd683d34ae3dcbf4e797591 (diff) | |
download | PrismLauncher-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar.gz PrismLauncher-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar.bz2 PrismLauncher-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.zip |
NOISSUE most basic analytics integration possible
Diffstat (limited to 'application/MultiMC.cpp')
-rw-r--r-- | application/MultiMC.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 64c380ec..c3ab7827 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -64,6 +64,7 @@ #include <FileSystem.h> #include <DesktopServices.h> #include <LocalPeer.h> +#include <ganalytics.h> #if defined Q_OS_WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -104,7 +105,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) } #endif setOrganizationName("MultiMC"); + setOrganizationDomain("multimc.org"); setApplicationName("MultiMC5"); + setApplicationDisplayName("MultiMC 5"); + setApplicationVersion(BuildConfig.printableVersionString()); startTime = QDateTime::currentDateTime(); @@ -310,6 +314,8 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) setIconTheme(settings()->get("IconTheme").toString()); setApplicationTheme(settings()->get("ApplicationTheme").toString()); + initAnalytics(); + if(!m_instanceIdToLaunch.isEmpty()) { auto inst = instances()->getInstanceById(m_instanceIdToLaunch); @@ -499,6 +505,42 @@ void MultiMC::shutdownLogger() qInstallMessageHandler(nullptr); } +void MultiMC::initAnalytics() +{ + if(BuildConfig.ANALYTICS_ID.isEmpty()) + { + qDebug() << "Analytics disabled by build."; + return; + } + if(!m_settings->get("Analytics").toBool()) + { + qDebug() << "Analytics disabled by user."; + return; + } + QString clientID = m_settings->get("AnalyticsClientID").toString(); + if(clientID.isEmpty()) + { + clientID = QUuid::createUuid().toString(); + clientID.remove(QLatin1Char('{')); + clientID.remove(QLatin1Char('}')); + m_settings->set("AnalyticsClientID", clientID); + } + m_analytics = new GAnalytics(BuildConfig.ANALYTICS_ID, clientID, this); + m_analytics->setLogLevel(GAnalytics::Debug); + m_analytics->setNetworkAccessManager(&ENV.qnam()); + m_analytics->startSending(); + qDebug() << "Initialized analytics with tid" << BuildConfig.ANALYTICS_ID << "and cid" << clientID; + // TODO: load unsent messages? +} + +void MultiMC::shutdownAnalytics() +{ + if(m_analytics) + { + // TODO: persist unsent messages? send them now? + } +} + void MultiMC::initInstances() { auto InstDirSetting = m_settings->getSetting("InstanceDir"); @@ -656,6 +698,10 @@ void MultiMC::initGlobalSettings() // paste.ee API key m_settings->registerSetting("PasteEEAPIKey", "multimc"); + // Analytics + m_settings->registerSetting("Analytics", true); + m_settings->registerSetting("AnalyticsClientID", QString()); + // Init page provider { m_globalSettingsProvider = std::make_shared<GenericPageProvider>(tr("Settings")); @@ -915,6 +961,10 @@ MainWindow* MultiMC::showMainWindow(bool minimized) m_mainWindow->checkInstancePathForProblems(); m_openWindows++; } + if(m_analytics) + { + m_analytics->sendScreenView("Main Window"); + } return m_mainWindow; } |