From ee6f2f0a8ebdeede68b6768e1d75d047ec2c50de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 21 Nov 2016 21:18:30 +0100 Subject: [PATCH] NOISSUE implement analytics IP anonymization --- application/MultiMC.cpp | 1 + libraries/ganalytics/include/ganalytics.h | 3 +++ libraries/ganalytics/src/ganalytics.cpp | 10 ++++++++++ libraries/ganalytics/src/ganalytics_worker.cpp | 6 +++++- libraries/ganalytics/src/ganalytics_worker.h | 3 ++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index c3ab78275..49e45c411 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -527,6 +527,7 @@ void MultiMC::initAnalytics() } m_analytics = new GAnalytics(BuildConfig.ANALYTICS_ID, clientID, this); m_analytics->setLogLevel(GAnalytics::Debug); + m_analytics->setAnonymizeIPs(true); m_analytics->setNetworkAccessManager(&ENV.qnam()); m_analytics->startSending(); qDebug() << "Initialized analytics with tid" << BuildConfig.ANALYTICS_ID << "and cid" << clientID; diff --git a/libraries/ganalytics/include/ganalytics.h b/libraries/ganalytics/include/ganalytics.h index 7cbd2c85d..48025dc19 100644 --- a/libraries/ganalytics/include/ganalytics.h +++ b/libraries/ganalytics/include/ganalytics.h @@ -33,6 +33,9 @@ public: void setLanguage(const QString &language); QString language() const; + void setAnonymizeIPs(bool anonymize); + bool anonymizeIPs(); + void setSendInterval(int milliseconds); int sendInterval() const; diff --git a/libraries/ganalytics/src/ganalytics.cpp b/libraries/ganalytics/src/ganalytics.cpp index 8d25efe97..a03dfcadc 100644 --- a/libraries/ganalytics/src/ganalytics.cpp +++ b/libraries/ganalytics/src/ganalytics.cpp @@ -60,6 +60,16 @@ QString GAnalytics::language() const return d->m_language; } +void GAnalytics::setAnonymizeIPs(bool anonymize) +{ + d->m_anonymizeIPs = anonymize; +} + +bool GAnalytics::anonymizeIPs() +{ + return d->m_anonymizeIPs; +} + void GAnalytics::setSendInterval(int milliseconds) { d->m_timer.setInterval(milliseconds); diff --git a/libraries/ganalytics/src/ganalytics_worker.cpp b/libraries/ganalytics/src/ganalytics_worker.cpp index 01aa69ce1..2b03e14cf 100644 --- a/libraries/ganalytics/src/ganalytics_worker.cpp +++ b/libraries/ganalytics/src/ganalytics_worker.cpp @@ -12,7 +12,7 @@ const QLatin1String GAnalyticsWorker::dateTimeFormat("yyyy,MM,dd-hh:mm::ss:zzz"); GAnalyticsWorker::GAnalyticsWorker(GAnalytics *parent) - : QObject(parent), q(parent), m_logLevel(GAnalytics::Error), m_isSending(false) + : QObject(parent), q(parent), m_logLevel(GAnalytics::Error) { m_appName = QCoreApplication::instance()->applicationName(); m_appVersion = QCoreApplication::instance()->applicationVersion(); @@ -57,6 +57,10 @@ QUrlQuery GAnalyticsWorker::buildStandardPostQuery(const QString &type) query.addQueryItem("ul", m_language); query.addQueryItem("vp", m_viewportSize); query.addQueryItem("sr", m_screenResolution); + if(m_anonymizeIPs) + { + query.addQueryItem("aip", "1"); + } return query; } diff --git a/libraries/ganalytics/src/ganalytics_worker.h b/libraries/ganalytics/src/ganalytics_worker.h index 280f9ab29..88fa223a9 100644 --- a/libraries/ganalytics/src/ganalytics_worker.h +++ b/libraries/ganalytics/src/ganalytics_worker.h @@ -37,7 +37,8 @@ public: QString m_screenResolution; QString m_viewportSize; - bool m_isSending; + bool m_anonymizeIPs = false; + bool m_isSending = false; const static int fourHours = 4 * 60 * 60 * 1000; const static QLatin1String dateTimeFormat;