From d2aa6147369a878ae189792c5a495101388564a1 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Sun, 6 Sep 2015 21:02:59 +0300 Subject: [PATCH] it seems that GA cannot parse custom User-Agent, so send OS and Java version as custom dimensions --- src/net/azib/ipscan/util/GoogleAnalytics.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/azib/ipscan/util/GoogleAnalytics.java b/src/net/azib/ipscan/util/GoogleAnalytics.java index ceba8a67..a990aa97 100644 --- a/src/net/azib/ipscan/util/GoogleAnalytics.java +++ b/src/net/azib/ipscan/util/GoogleAnalytics.java @@ -24,12 +24,14 @@ public class GoogleAnalytics { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); - conn.setRequestProperty("User-Agent", "Java/" + System.getProperty("java.version") + "-" + System.getProperty("os.name") + "-" + System.getProperty("os.version") + "-" + System.getProperty("os.arch")); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); String contentParam = "exception".equals(type) ? "exd" : "cd"; - String payload = "v=1&t=" + type + "&tid=" + Version.GA_ID + "&cid=" + config.getUUID() + "&an=ipscan&av=" + Version.getVersion() + "&" + - contentParam + "=" + URLEncoder.encode(content, "UTF-8") + "&ul=" + config.getLocale(); + String payload = "v=1&t=" + type + "&tid=" + Version.GA_ID + "&cid=" + config.getUUID() + "&an=ipscan&av=" + Version.getVersion() + + "&" + contentParam + "=" + URLEncoder.encode(content, "UTF-8") + + "&ul=" + config.getLocale() + + "&cd1=" + URLEncoder.encode(System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"), "UTF-8") + + "&cd2=" + URLEncoder.encode("Java " + System.getProperty("java.version"), "UTF-8"); os.write(payload.getBytes()); os.close(); conn.getContent();