NOISSUE most basic analytics integration possible

This commit is contained in:
Petr Mrázek 2016-11-20 20:40:59 +01:00
parent 2f8c752d1f
commit 905bc2e440
6 changed files with 65 additions and 1 deletions

View File

@ -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@";

View File

@ -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;

View File

@ -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)

View File

@ -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;
}

View File

@ -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;

View File

@ -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)
{