summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-11-20 20:40:59 +0100
committerPetr Mrázek <peterix@gmail.com>2016-11-21 01:19:34 +0100
commit905bc2e440060a6228725fe1e7abd9a1fce7b1e8 (patch)
treebbc763b9b15e0c812321b263b3ae27af55ad793d
parent2f8c752d1fe9976fdbd683d34ae3dcbf4e797591 (diff)
downloadMultiMC-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar
MultiMC-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar.gz
MultiMC-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar.lz
MultiMC-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.tar.xz
MultiMC-905bc2e440060a6228725fe1e7abd9a1fce7b1e8.zip
NOISSUE most basic analytics integration possible
-rw-r--r--application/BuildConfig.cpp.in1
-rw-r--r--application/BuildConfig.h3
-rw-r--r--application/CMakeLists.txt5
-rw-r--r--application/MultiMC.cpp50
-rw-r--r--application/MultiMC.h5
-rw-r--r--libraries/ganalytics/src/ganalytics_worker.cpp2
6 files changed, 65 insertions, 1 deletions
diff --git a/application/BuildConfig.cpp.in b/application/BuildConfig.cpp.in
index 62bf53d7..80620c82 100644
--- a/application/BuildConfig.cpp.in
+++ b/application/BuildConfig.cpp.in
@@ -13,6 +13,7 @@ Config::Config()
BUILD_PLATFORM = "@MultiMC_BUILD_PLATFORM@";
CHANLIST_URL = "@MultiMC_CHANLIST_URL@";
+ ANALYTICS_ID = "@MultiMC_ANALYTICS_ID@";
NOTIFICATION_URL = "@MultiMC_NOTIFICATION_URL@";
FULL_VERSION_STR = "@MultiMC_VERSION_MAJOR@.@MultiMC_VERSION_MINOR@.@MultiMC_VERSION_BUILD@";
diff --git a/application/BuildConfig.h b/application/BuildConfig.h
index 64d07065..75109b1c 100644
--- a/application/BuildConfig.h
+++ b/application/BuildConfig.h
@@ -31,6 +31,9 @@ public:
/// URL for the updater's channel
QString CHANLIST_URL;
+ /// Google analytics ID
+ QString ANALYTICS_ID;
+
/// URL for notifications
QString NOTIFICATION_URL;
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index 18351cce..2e2992cf 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -23,6 +23,9 @@ set(MultiMC_NOTIFICATION_URL "" CACHE STRING "URL for checking for notifications
# paste.ee API key
set(MultiMC_PASTE_EE_API_KEY "" CACHE STRING "API key you can get from paste.ee when you register an account")
+# Google analytics ID
+set(MultiMC_ANALYTICS_ID "" CACHE STRING "ID you can get from Google analytics")
+
#### Check the current Git commit and branch
include(GetGitRevisionDescription)
get_git_head_revision(MultiMC_GIT_REFSPEC MultiMC_GIT_COMMIT)
@@ -330,7 +333,7 @@ qt5_add_resources(MULTIMC_RESOURCES ${MULTIMC_QRCS})
# Add executable
add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS})
-target_link_libraries(MultiMC MultiMC_gui ${QUAZIP_LIBRARIES} hoedown rainbow LocalPeer)
+target_link_libraries(MultiMC MultiMC_gui ${QUAZIP_LIBRARIES} hoedown rainbow LocalPeer ganalytics)
if(APPLE)
find_library(OSX_CORE_FOUNDATION CoreFoundation)
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;
}
diff --git a/application/MultiMC.h b/application/MultiMC.h
index 23cafdb1..55f63ac4 100644
--- a/application/MultiMC.h
+++ b/application/MultiMC.h
@@ -34,6 +34,7 @@ class BaseDetachedToolFactory;
class TranslationDownloader;
class ITheme;
class MCEditTool;
+class GAnalytics;
#if defined(MMC)
#undef MMC
@@ -173,6 +174,8 @@ private:
void initInstances();
void initAccounts();
void initMCEdit();
+ void initAnalytics();
+ void shutdownAnalytics();
private:
QDateTime startTime;
@@ -218,6 +221,8 @@ private:
// peer MultiMC instance connector - used to implement single instance MultiMC and signalling
LocalPeer * m_peerInstance = nullptr;
+
+ GAnalytics * m_analytics = nullptr;
public:
QString m_instanceIdToLaunch;
bool m_liveCheck = false;
diff --git a/libraries/ganalytics/src/ganalytics_worker.cpp b/libraries/ganalytics/src/ganalytics_worker.cpp
index 3dbbb50a..01aa69ce 100644
--- a/libraries/ganalytics/src/ganalytics_worker.cpp
+++ b/libraries/ganalytics/src/ganalytics_worker.cpp
@@ -209,6 +209,8 @@ void GAnalyticsWorker::postMessage()
m_request.setRawHeader("Connection", connection.toUtf8());
m_request.setHeader(QNetworkRequest::ContentLengthHeader, buffer.postQuery.toString().length());
+ logMessage(GAnalytics::Debug, "Query string = " + buffer.postQuery.toString());
+
// Create a new network access manager if we don't have one yet
if (networkManager == NULL)
{