Skip to content

Commit

Permalink
Merge pull request #5 from NHERI-SimCenter/master
Browse files Browse the repository at this point in the history
Google Analytics
  • Loading branch information
charlesxwang authored Mar 31, 2019
2 parents fb8db6b + d94f7e9 commit 45a0399
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
41 changes: 4 additions & 37 deletions WorkflowAppPBE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

#include "CustomizedItemModel.h"
#include <ResultsPelicun.h>
#include <GoogleAnalytics.h>

// static pointer for global procedure set in constructor
static WorkflowAppPBE *theApp = 0;
Expand Down Expand Up @@ -306,29 +307,6 @@ WorkflowAppPBE::WorkflowAppPBE(RemoteService *theService, QWidget *parent)
// manager->get(QNetworkRequest(QUrl("https://simcenter.designsafe-ci.org/multiple-degrees-freedom-analytics/")));


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;
QUuid uuid = WorkflowAppPBE::getUserId();
QString hostname = QHostInfo::localHostName() + "." + QHostInfo::localDomainName();
requestParams += "v=1"; // version of protocol
requestParams += "&tid=UA-126256136-1"; // Google Analytics account
requestParams += "&cid=" + uuid.toString(); // unique user identifier
requestParams += "&t=event"; // hit type = event others pageview, exception
requestParams += "&an=PBE"; // app name
requestParams += "&av=1.1.0"; // app version
requestParams += "&ec=PBE"; // event category
requestParams += "&ea=start"; // event action
requestParams += "&aip=1"; // Anonymize IP

// send request via post method
manager->post(request, requestParams.toStdString().c_str());

/*
QFile fileS(":/styles/stylesheet.qss");
if(fileS.open(QFile::ReadOnly)) {
Expand All @@ -341,20 +319,6 @@ WorkflowAppPBE::WorkflowAppPBE(RemoteService *theService, QWidget *parent)

}

//TODO: This code may need to be refactored and shared in SimCenterCommon
QUuid WorkflowAppPBE::getUserId()
{
QSettings commonSettings("SimCenter", "Common"); //These names will need to be constants to be shared
QVariant userIdSetting = commonSettings.value("userId");
if (!userIdSetting.isValid())
{
commonSettings.setValue("userId", QUuid::createUuid());
userIdSetting = commonSettings.value("userId");
}
return userIdSetting.toUuid();
}


WorkflowAppPBE::~WorkflowAppPBE()
{

Expand Down Expand Up @@ -569,6 +533,7 @@ WorkflowAppPBE::inputFromJSON(QJsonObject &jsonObject)
void
WorkflowAppPBE::onRunButtonClicked() {
theRunWidget->showLocalApplication();
GoogleAnalytics::ReportLocalRun();
}

void
Expand All @@ -585,6 +550,8 @@ WorkflowAppPBE::onRemoteRunButtonClicked(){
} else {
errorMessage("ERROR - You Need to Login");
}

GoogleAnalytics::ReportDesignSafeRun();
}

void
Expand Down
1 change: 0 additions & 1 deletion WorkflowAppPBE.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public slots:
QStackedWidget *theStackedWidget;
QNetworkAccessManager *manager;

static QUuid getUserId();
};

#endif // WORKFLOW_APP_PBE_H
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <QTime>
#include <QTextStream>
#include <GoogleAnalytics.h>

// customMessgaeOutput code from web:
// https://stackoverflow.com/questions/4954140/how-to-redirect-qdebug-qwarning-qcritical-etc-output
Expand Down Expand Up @@ -54,6 +55,10 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("SimCenter");
QCoreApplication::setApplicationVersion("1.2.0");

GoogleAnalytics::SetTrackingId("UA-126256136-1");
GoogleAnalytics::StartSession();
GoogleAnalytics::ReportStart();

//
// set up logging of output messages for user debugging
//
Expand Down Expand Up @@ -183,6 +188,7 @@ int main(int argc, char *argv[])
theRemoteService->logout();
thread->quit();

GoogleAnalytics::EndSession();
// done
return res;
}

0 comments on commit 45a0399

Please sign in to comment.