This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Tracking of GUI and batch usage #44
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f74196
Initial module usage tracking using Google Analytics
dyrlund dd288d0
Added GoogleAnalyticsTracker.java
dyrlund c6fb347
Added calculation to find screen size for multiple screen setups
dyrlund efad3e4
Removed tracking code from io modules
dyrlund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
src/main/java/net/sf/mzmine/main/GoogleAnalyticsTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.