Google Analytics added for Companion usage and firmware downloads
statistics
This commit is contained in:
@@ -164,6 +164,7 @@ set(companion_SRCS
|
|||||||
qcustomplot.cpp
|
qcustomplot.cpp
|
||||||
wizarddata.cpp
|
wizarddata.cpp
|
||||||
wizarddialog.cpp
|
wizarddialog.cpp
|
||||||
|
googleanalytics.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(companion_MOC_HDRS
|
set(companion_MOC_HDRS
|
||||||
@@ -190,6 +191,7 @@ set(companion_MOC_HDRS
|
|||||||
qautocombobox.h
|
qautocombobox.h
|
||||||
helpers.h
|
helpers.h
|
||||||
wizarddialog.h
|
wizarddialog.h
|
||||||
|
googleanalytics.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(companion_UIS
|
set(companion_UIS
|
||||||
|
|||||||
@@ -480,7 +480,6 @@ QString AppData::armMcu() { return _armMcu; }
|
|||||||
QString AppData::avrArguments() { return _avrArguments; }
|
QString AppData::avrArguments() { return _avrArguments; }
|
||||||
QString AppData::avrPort() { return _avrPort; }
|
QString AppData::avrPort() { return _avrPort; }
|
||||||
QString AppData::avrdudeLocation() { return _avrdudeLocation; }
|
QString AppData::avrdudeLocation() { return _avrdudeLocation; }
|
||||||
QString AppData::cpuId() { return _cpuId; }
|
|
||||||
QString AppData::dfuArguments() { return _dfuArguments; }
|
QString AppData::dfuArguments() { return _dfuArguments; }
|
||||||
QString AppData::dfuLocation() { return _dfuLocation; }
|
QString AppData::dfuLocation() { return _dfuLocation; }
|
||||||
QString AppData::locale() { return _locale; }
|
QString AppData::locale() { return _locale; }
|
||||||
@@ -531,7 +530,6 @@ void AppData::armMcu (const QString x) { store(x, _armMcu,
|
|||||||
void AppData::avrArguments (const QString x) { store(x, _avrArguments, "avr_arguments" );}
|
void AppData::avrArguments (const QString x) { store(x, _avrArguments, "avr_arguments" );}
|
||||||
void AppData::avrPort (const QString x) { store(x, _avrPort, "avr_port" );}
|
void AppData::avrPort (const QString x) { store(x, _avrPort, "avr_port" );}
|
||||||
void AppData::avrdudeLocation (const QString x) { store(x, _avrdudeLocation, "avrdudeLocation" );}
|
void AppData::avrdudeLocation (const QString x) { store(x, _avrdudeLocation, "avrdudeLocation" );}
|
||||||
void AppData::cpuId (const QString x) { store(x, _cpuId, "cpu_id" );}
|
|
||||||
void AppData::dfuArguments (const QString x) { store(x, _dfuArguments, "dfu_arguments" );}
|
void AppData::dfuArguments (const QString x) { store(x, _dfuArguments, "dfu_arguments" );}
|
||||||
void AppData::dfuLocation (const QString x) { store(x, _dfuLocation, "dfu_location" );}
|
void AppData::dfuLocation (const QString x) { store(x, _dfuLocation, "dfu_location" );}
|
||||||
void AppData::locale (const QString x) { store(x, _locale, "locale" );}
|
void AppData::locale (const QString x) { store(x, _locale, "locale" );}
|
||||||
@@ -655,7 +653,6 @@ AppData::AppData()
|
|||||||
getset( _avrArguments, "avr_arguments" ,"" );
|
getset( _avrArguments, "avr_arguments" ,"" );
|
||||||
getset( _avrPort, "avr_port" ,"" );
|
getset( _avrPort, "avr_port" ,"" );
|
||||||
getset( _avrdudeLocation, "avrdudeLocation" ,"" );
|
getset( _avrdudeLocation, "avrdudeLocation" ,"" );
|
||||||
getset( _cpuId, "cpu_id" ,"" );
|
|
||||||
getset( _dfuArguments, "dfu_arguments" ,"-a 0" );
|
getset( _dfuArguments, "dfu_arguments" ,"-a 0" );
|
||||||
getset( _dfuLocation, "dfu_location" ,"" );
|
getset( _dfuLocation, "dfu_location" ,"" );
|
||||||
getset( _locale, "locale" ,"" );
|
getset( _locale, "locale" ,"" );
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ class AppData: protected CompStoreObj
|
|||||||
QString _avrArguments;
|
QString _avrArguments;
|
||||||
QString _avrPort;
|
QString _avrPort;
|
||||||
QString _avrdudeLocation;
|
QString _avrdudeLocation;
|
||||||
QString _cpuId;
|
|
||||||
QString _dfuArguments;
|
QString _dfuArguments;
|
||||||
QString _dfuLocation;
|
QString _dfuLocation;
|
||||||
QString _locale;
|
QString _locale;
|
||||||
@@ -258,7 +257,6 @@ class AppData: protected CompStoreObj
|
|||||||
QString avrArguments();
|
QString avrArguments();
|
||||||
QString avrPort();
|
QString avrPort();
|
||||||
QString avrdudeLocation();
|
QString avrdudeLocation();
|
||||||
QString cpuId();
|
|
||||||
QString dfuArguments();
|
QString dfuArguments();
|
||||||
QString dfuLocation();
|
QString dfuLocation();
|
||||||
QString lastFw();
|
QString lastFw();
|
||||||
@@ -310,7 +308,6 @@ class AppData: protected CompStoreObj
|
|||||||
void avrArguments (const QString);
|
void avrArguments (const QString);
|
||||||
void avrPort (const QString);
|
void avrPort (const QString);
|
||||||
void avrdudeLocation (const QString);
|
void avrdudeLocation (const QString);
|
||||||
void cpuId (const QString);
|
|
||||||
void dfuArguments (const QString);
|
void dfuArguments (const QString);
|
||||||
void dfuLocation (const QString);
|
void dfuLocation (const QString);
|
||||||
void lastFw (const QString);
|
void lastFw (const QString);
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ void AppPreferencesDialog::writeValues()
|
|||||||
g.profile[g.id()].name(ui->profileNameLE->text());
|
g.profile[g.id()].name(ui->profileNameLE->text());
|
||||||
|
|
||||||
// If a new fw type has been choosen, several things need to reset
|
// If a new fw type has been choosen, several things need to reset
|
||||||
g.cpuId( ui->CPU_ID_LE->text() );
|
|
||||||
current_firmware_variant = getFirmwareVariant();
|
current_firmware_variant = getFirmwareVariant();
|
||||||
if (g.profile[g.id()].fwType() != current_firmware_variant.id) {
|
if (g.profile[g.id()].fwType() != current_firmware_variant.id) {
|
||||||
g.profile[g.id()].fwName("");
|
g.profile[g.id()].fwName("");
|
||||||
@@ -186,8 +185,6 @@ void AppPreferencesDialog::initSettings()
|
|||||||
}
|
}
|
||||||
ui->lblGeneralSettings->setText(hwSettings);
|
ui->lblGeneralSettings->setText(hwSettings);
|
||||||
|
|
||||||
|
|
||||||
ui->CPU_ID_LE->setText(g.cpuId());
|
|
||||||
FirmwareInterface * current_firmware = GetCurrentFirmware();
|
FirmwareInterface * current_firmware = GetCurrentFirmware();
|
||||||
|
|
||||||
foreach(FirmwareInterface * firmware, firmwares) {
|
foreach(FirmwareInterface * firmware, firmwares) {
|
||||||
@@ -470,14 +467,6 @@ void AppPreferencesDialog::firmwareChanged()
|
|||||||
QString stamp;
|
QString stamp;
|
||||||
stamp.append(variant.firmware->getStampUrl());
|
stamp.append(variant.firmware->getStampUrl());
|
||||||
QString url = variant.getFirmwareUrl();
|
QString url = variant.getFirmwareUrl();
|
||||||
// B-Plan
|
|
||||||
if (false) {
|
|
||||||
ui->CPU_ID_LE->show();
|
|
||||||
ui->CPU_ID_LABEL->show();
|
|
||||||
} else {
|
|
||||||
ui->CPU_ID_LE->hide();
|
|
||||||
ui->CPU_ID_LABEL->hide();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppPreferencesDialog::populateFirmwareOptions(const FirmwareInterface * firmware)
|
void AppPreferencesDialog::populateFirmwareOptions(const FirmwareInterface * firmware)
|
||||||
|
|||||||
@@ -162,9 +162,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="1">
|
|
||||||
<widget class="QLineEdit" name="CPU_ID_LE"/>
|
|
||||||
</item>
|
|
||||||
<item row="24" column="1" colspan="3">
|
<item row="24" column="1" colspan="3">
|
||||||
<widget class="QComboBox" name="stickmodeCB">
|
<widget class="QComboBox" name="stickmodeCB">
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
|
|||||||
Executable
+72
@@ -0,0 +1,72 @@
|
|||||||
|
#include "googleanalytics.h"
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#define TRACKING_ID "UA-40098569-1"
|
||||||
|
|
||||||
|
GoogleAnalytics ga;
|
||||||
|
|
||||||
|
GoogleAnalytics::GoogleAnalytics():
|
||||||
|
userId(qrand()),
|
||||||
|
networkManager(new QNetworkAccessManager(this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GoogleAnalytics::~GoogleAnalytics()
|
||||||
|
{
|
||||||
|
delete networkManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoogleAnalytics::sendPageView(QString page)
|
||||||
|
{
|
||||||
|
// create request and set URL of receiver
|
||||||
|
QNetworkRequest request;
|
||||||
|
QUrl host("http://www.google-analytics.com/collect");
|
||||||
|
request.setUrl(host);
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
// setup parameters of request
|
||||||
|
QString requestParams;
|
||||||
|
requestParams += "v=1"; // version of protocol
|
||||||
|
requestParams += "&t=pageview"; // type of request
|
||||||
|
requestParams += "&tid=" TRACKING_ID; // Google Analytics account
|
||||||
|
requestParams += "&cid=" + QString::number(userId); // unique user identifier
|
||||||
|
requestParams += "&dp=" + page; // name of page (or app name)
|
||||||
|
requestParams += "&ul=" + QLocale::system().name(); // language
|
||||||
|
|
||||||
|
// send request via post method
|
||||||
|
networkManager->post(request, requestParams.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoogleAnalytics::sendEvent(QString category, QString action, QString label)
|
||||||
|
{
|
||||||
|
// create request and set URL of receiver
|
||||||
|
QNetworkRequest request;
|
||||||
|
QUrl host("http://www.google-analytics.com/collect");
|
||||||
|
request.setUrl(host);
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
// setup parameters of request
|
||||||
|
QString requestParams;
|
||||||
|
requestParams += "v=1"; // version of protocol
|
||||||
|
requestParams += "&t=event"; // type of request
|
||||||
|
requestParams += "&ec=" + category;
|
||||||
|
requestParams += "&ea=" + action;
|
||||||
|
requestParams += "&el=" + label;
|
||||||
|
requestParams += "&tid=" TRACKING_ID; // Google Analytics account
|
||||||
|
requestParams += "&cid=" + QString::number(userId); // unique user identifier
|
||||||
|
requestParams += "&dt=Companion"; // name of page (or app name)
|
||||||
|
requestParams += "&ul=" + QLocale::system().name(); // language
|
||||||
|
|
||||||
|
// send request via post method
|
||||||
|
networkManager->post(request, requestParams.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoogleAnalytics::slot_receive(QNetworkReply * reply)
|
||||||
|
{
|
||||||
|
// output information about reply
|
||||||
|
qDebug() << "RequestUrl:" << reply->request().url();
|
||||||
|
qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
qDebug() << "Error:"<< reply->error();
|
||||||
|
QByteArray bytes = reply->readAll();
|
||||||
|
qDebug() << "Contents" << QString::fromUtf8(bytes.data(), bytes.size());
|
||||||
|
}
|
||||||
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#include <QtNetwork>
|
||||||
|
|
||||||
|
class GoogleAnalytics: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GoogleAnalytics();
|
||||||
|
~GoogleAnalytics();
|
||||||
|
void sendPageView(QString page);
|
||||||
|
void sendEvent(QString category, QString action, QString label);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void slot_receive(QNetworkReply * reply);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int userId;
|
||||||
|
QNetworkAccessManager * networkManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern GoogleAnalytics ga;
|
||||||
@@ -64,6 +64,7 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "appdata.h"
|
#include "appdata.h"
|
||||||
#include "taranisnotfound.h"
|
#include "taranisnotfound.h"
|
||||||
|
#include "googleanalytics.h"
|
||||||
#include "firmwares/opentx/opentxinterface.h" // TODO get rid of this include
|
#include "firmwares/opentx/opentxinterface.h" // TODO get rid of this include
|
||||||
|
|
||||||
#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2"
|
#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2"
|
||||||
@@ -162,6 +163,8 @@ MainWindow::MainWindow():
|
|||||||
if (printing) {
|
if (printing) {
|
||||||
QTimer::singleShot(0, this, SLOT(autoClose()));
|
QTimer::singleShot(0, this, SLOT(autoClose()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ga.sendPageView("Companion");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::displayWarnings()
|
void MainWindow::displayWarnings()
|
||||||
@@ -319,22 +322,13 @@ void MainWindow::updateDownloaded()
|
|||||||
|
|
||||||
void MainWindow::downloadLatestFW(FirmwareVariant & firmware)
|
void MainWindow::downloadLatestFW(FirmwareVariant & firmware)
|
||||||
{
|
{
|
||||||
QString url, ext, cpuid;
|
QString url, ext;
|
||||||
url = firmware.getFirmwareUrl();
|
url = firmware.getFirmwareUrl();
|
||||||
cpuid = g.cpuId();
|
|
||||||
ext = url.mid(url.lastIndexOf("."));
|
ext = url.mid(url.lastIndexOf("."));
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + firmware.id + ext);
|
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + firmware.id + ext);
|
||||||
if (!fileName.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
needRename = true;
|
needRename = true;
|
||||||
g.profile[g.id()].fwName(fileName);
|
startFirmwareDownload(url, filename);
|
||||||
if (!cpuid.isEmpty()) {
|
|
||||||
url.append("&cpuid=");
|
|
||||||
url.append(cpuid);
|
|
||||||
}
|
|
||||||
g.flashDir(QFileInfo(fileName).dir().absolutePath());
|
|
||||||
downloadDialog * dd = new downloadDialog(this, url, fileName);
|
|
||||||
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
|
|
||||||
dd->exec();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,9 +401,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||||||
{
|
{
|
||||||
bool download = false;
|
bool download = false;
|
||||||
bool ignore = false;
|
bool ignore = false;
|
||||||
QString cpuid;
|
|
||||||
|
|
||||||
cpuid = g.cpuId();
|
|
||||||
QByteArray qba = reply->readAll();
|
QByteArray qba = reply->readAll();
|
||||||
|
|
||||||
long version = 0;
|
long version = 0;
|
||||||
@@ -510,20 +502,9 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||||||
else if (download == true) {
|
else if (download == true) {
|
||||||
QString url = GetFirmwareVariant(current_firmware_variant.id).getFirmwareUrl();
|
QString url = GetFirmwareVariant(current_firmware_variant.id).getFirmwareUrl();
|
||||||
QString ext = url.mid(url.lastIndexOf("."));
|
QString ext = url.mid(url.lastIndexOf("."));
|
||||||
needRename=false;
|
needRename = false;
|
||||||
QString fileName;
|
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + current_firmware_variant.id + ext);
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + current_firmware_variant.id + ext);
|
startFirmwareDownload(url, filename);
|
||||||
if (!fileName.isEmpty()) {
|
|
||||||
if (!cpuid.isEmpty()) {
|
|
||||||
url.append("&cpuid=");
|
|
||||||
url.append(cpuid);
|
|
||||||
}
|
|
||||||
g.profile[g.id()].fwName(fileName);
|
|
||||||
g.flashDir(QFileInfo(fileName).dir().absolutePath());
|
|
||||||
downloadDialog * dd = new downloadDialog(this, url, fileName);
|
|
||||||
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
|
|
||||||
dd->exec();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -534,6 +515,18 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::startFirmwareDownload(QString url, QString filename)
|
||||||
|
{
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
|
g.profile[g.id()].fwName(filename);
|
||||||
|
g.flashDir(QFileInfo(filename).dir().absolutePath());
|
||||||
|
downloadDialog * dd = new downloadDialog(this, url, filename);
|
||||||
|
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
|
||||||
|
dd->exec();
|
||||||
|
ga.sendEvent("Firmwares", "Download", url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
g.mainWinGeo(saveGeometry());
|
g.mainWinGeo(saveGeometry());
|
||||||
|
|||||||
@@ -76,11 +76,11 @@ class MainWindow : public QMainWindow
|
|||||||
MainWindow();
|
MainWindow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void startFirmwareDownload(QString url, QString filename);
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
void dropEvent(QDropEvent *event);
|
void dropEvent(QDropEvent *event);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void downloadLatestFW(FirmwareVariant & firmware);
|
void downloadLatestFW(FirmwareVariant & firmware);
|
||||||
|
|
||||||
|
|||||||
@@ -896,9 +896,6 @@ May be different from firmware language</string>
|
|||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QComboBox" name="downloadVerCB"/>
|
<widget class="QComboBox" name="downloadVerCB"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<widget class="QLineEdit" name="CPU_ID_LE"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="21" column="0">
|
<item row="21" column="0">
|
||||||
|
|||||||
Reference in New Issue
Block a user