Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Tracking of GUI and batch usage #44

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions src/main/java/net/sf/mzmine/main/GoogleAnalyticsTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright 2006-2015 The MZmine 2 Development Team
*
* This file is part of MZmine 2.
*
* MZmine 2 is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.sf.mzmine.main;

import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.net.HttpURLConnection;

public class GoogleAnalyticsTracker implements Runnable {

// Parameters
String trackingUrl = "http://www.google-analytics.com/__utm.gif";
String trackingCode = "UA-63013892-1"; // Google Analytics Tracking Code
String hostName = "localhost"; // Host name
String userAgent = null; // User Agent name
String os = "Unknown"; // Operating System
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Screen Size
String systemLocale = Locale.getDefault().toString().replace("_", "-"); // Language
String pageTitle, pageUrl;
Random random = new Random();

public GoogleAnalyticsTracker(String title, String url) {
pageTitle = title;
pageUrl = url;
}

public void run() {

// Only send data if SendStatistics variable is not set to 0
String SendStatistics = System.getenv().get("MZ_STATISTICS");
if (SendStatistics == null) {
SendStatistics = "1";
}
if (!SendStatistics.equals("0")) {

// Find screen size for multiple screen setup
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = g.getScreenDevices();
if (devices.length > 1) {
int totalWidth = 0;
for (int i = 0; i < devices.length; i++) {
totalWidth += devices[i].getDisplayMode().getWidth();
}
screenSize = new Dimension(totalWidth,(int) screenSize.getHeight());
}

if (hostName.equals("localhost")) {
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// Ignore
}
}

if (userAgent == null) {
userAgent = "Java/" + System.getProperty("java.version");
os = System.getProperty("os.arch");
if (os == null || os.length() < 1) {
os = "";
} else {
os += "; ";
os += System.getProperty("os.name") + " "
+ System.getProperty("os.version");
}
}

String documentTitle = "Java: MZmine "
+ MZmineCore.getMZmineVersion() + " - " + pageTitle;
int cookie = random.nextInt();
int randomValue = random.nextInt(2147483647) - 1;
long now = new Date().getTime();

StringBuffer url = new StringBuffer(trackingUrl);
url.append("?utmwv=1"); // Analytics version
url.append("&utmn=" + random.nextInt()); // Random int
url.append("&utmcs=UTF-8"); // Encoding
url.append("&utmsr=" + screenSize); // Screen size
url.append("&utmul=" + systemLocale); // User language
url.append("&utmje=1"); // Java Enabled
url.append("&utmcr=1"); // Carriage return
url.append("&utmdt=" + documentTitle.replace(" ", "%20")); // Document title
url.append("&utmhn=" + hostName);// Hostname
url.append("&utmp=" + pageUrl);// Document url
url.append("&utmac=" + trackingCode);// Google Analytics account
url.append("&utmcc=__utma%3D'"
+ cookie
+ "."
+ randomValue
+ "."
+ now
+ "."
+ now
+ "."
+ now
+ ".2%3B%2B__utmb%3D"
+ cookie
+ "%3B%2B__utmc%3D"
+ cookie
+ "%3B%2B__utmz%3D"
+ cookie
+ "."
+ now
+ ".2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D"
+ cookie);

try {
URL urlLink = new URL(url.toString());
HttpURLConnection UC = (HttpURLConnection) urlLink
.openConnection();
UC.setInstanceFollowRedirects(true);
UC.setRequestMethod("GET");
UC.setRequestProperty("User-agent", userAgent + " (" + os + ")");
UC.connect();

int responseCode = UC.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
// Ignore
} else {
// Ignore
}

} catch (Exception e) {
// Ignore
}

}

}

}
9 changes: 9 additions & 0 deletions src/main/java/net/sf/mzmine/main/MZmineCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public void run() {
NewVersionCheck NVC = new NewVersionCheck(CheckType.DESKTOP);
new Thread(NVC).start();

// Tracker
GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("GUI Loaded", "/JAVA/Main/GUI");
new Thread(GAT).start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Thread class has a function setPriority().
I think it could be a good idea to set the priority of these two threads (GAT and NVC) to the lowest possible value.


// register shutdown hook only if we have GUI - we don't want to
// save configuration on exit if we only run a batch
ShutDownHook shutDownHook = new ShutDownHook();
Expand All @@ -229,6 +233,11 @@ public void run() {
// if arguments were specified (= running without GUI), run the batch
// mode
if (args.length > 0) {

// Tracker
GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("Batch Loaded", "/JAVA/Main/Batch");
new Thread(GAT).start();

File batchFile = new File(args[0]);
if ((!batchFile.exists()) || (!batchFile.canRead())) {
logger.severe("Cannot read batch file " + batchFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.sf.mzmine.datamodel.PeakListRow;
import net.sf.mzmine.datamodel.RawDataFile;
import net.sf.mzmine.datamodel.Scan;
import net.sf.mzmine.modules.peaklistmethods.io.mztabexport.MzTabExportParameters;
import net.sf.mzmine.parameters.ParameterSet;
import net.sf.mzmine.taskcontrol.AbstractTask;
import net.sf.mzmine.taskcontrol.TaskStatus;
Expand Down
5 changes: 5 additions & 0 deletions src/main/scripts/startMZmine_Linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ TMP_FILE_DIRECTORY=/tmp
export TMP_FILE_DIRECTORY=$TMP_FILE_DIRECTORY/$MZMINE_UNID
mkdir $TMP_FILE_DIRECTORY

# If you do not want MZmine to sends anonymous statistics of the module
# usage in the software then please set the MZ_STATISTICS parameter to 0.
# 1 = activated, 0 = deactivated.
export MZ_STATISTICS=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor point: can we name it MZMINE_STATISTICS instead of MZ_STATISTICS?


# Set R environment variables.
export R_HOME=/usr/lib64/R

Expand Down
5 changes: 5 additions & 0 deletions src/main/scripts/startMZmine_MacOSX.command
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ TMP_FILE_DIRECTORY=/tmp
export TMP_FILE_DIRECTORY=$TMP_FILE_DIRECTORY/$MZMINE_UNID
mkdir $TMP_FILE_DIRECTORY

# If you do not want MZmine to sends anonymous statistics of the module
# usage in the software then please set the MZ_STATISTICS parameter to 0.
# 1 = activated, 0 = deactivated.
export MZ_STATISTICS=1

# Set R environment variables.
export R_HOME=/Library/Frameworks/R.framework/Versions/Current/Resources/

Expand Down
5 changes: 5 additions & 0 deletions src/main/scripts/startMZmine_Windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ set MZMINE_UNID=MZmine%ldt%
set TMP_FILE_DIRECTORY=%TMP_FILE_DIRECTORY%\\%MZMINE_UNID%
mkdir %TMP_FILE_DIRECTORY%

rem If you do not want MZmine to sends anonymous statistics of the module
rem usage in the software then please set the MZ_STATISTICS parameter to 0.
rem 1 = activated, 0 = deactivated.
set MZ_STATISTICS=1

rem Set R environment variables.
set R_HOME=C:\Program Files\R\R-2.12.0
set R_SHARE_DIR=%R_HOME%\share
Expand Down