-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed google analytics (#66), action_config required instead of act…
…ions, .data no longer created or used, removed all java.io.File usages
- Loading branch information
1 parent
e277c10
commit fbe2025
Showing
28 changed files
with
173 additions
and
264 deletions.
There are no files selected for viewing
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
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
104 changes: 17 additions & 87 deletions
104
client/src/main/java/me/retrodaredevil/solarthing/analytics/AnalyticsManager.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 |
---|---|---|
@@ -1,112 +1,42 @@ | ||
package me.retrodaredevil.solarthing.analytics; | ||
|
||
import com.brsanthu.googleanalytics.GoogleAnalytics; | ||
import com.brsanthu.googleanalytics.GoogleAnalyticsConfig; | ||
import com.brsanthu.googleanalytics.request.DefaultRequest; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import me.retrodaredevil.solarthing.SolarThingConstants; | ||
import me.retrodaredevil.solarthing.config.options.ProgramType; | ||
import me.retrodaredevil.solarthing.program.JarUtil; | ||
import me.retrodaredevil.solarthing.util.JacksonUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.UUID; | ||
|
||
public class AnalyticsManager { | ||
/* | ||
For future self setting this up again: in the View Settings in Google Analytics, you must have "Bot Filtering" turned off. | ||
*/ | ||
private static final ObjectMapper MAPPER = JacksonUtil.defaultMapper(); | ||
private static final String ANALYTICS_NOTE = "(Note) For this SolarThing version, analytics are not sent. This will be changed in a future version. If you see this log message, a future version of SolarThing may send analytics data (if you decide to update)."; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(AnalyticsManager.class); | ||
private final GoogleAnalytics googleAnalytics; | ||
private final boolean isEnabled; | ||
|
||
public AnalyticsManager(boolean isEnabled, Path dataDirectory) { | ||
/** | ||
* Constructs the object. No connections should be created here and no analytics collection should be done just because the constructor was invoked. | ||
* | ||
* @param isEnabled true if analytics are enabled, false otherwise | ||
*/ | ||
public AnalyticsManager(boolean isEnabled) { | ||
this.isEnabled = isEnabled; | ||
if (isEnabled) { | ||
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Google Analytics is ENABLED!"); | ||
Path file = dataDirectory.resolve("analytics_data.json"); | ||
AnalyticsData analyticsData = null; | ||
try { | ||
analyticsData = MAPPER.readValue(Files.newInputStream(file), AnalyticsData.class); | ||
} catch (IOException e) { | ||
LOGGER.debug(SolarThingConstants.NO_CONSOLE, "Couldn't read analytics data, but that's OK!", e); | ||
} | ||
if (analyticsData == null) { | ||
analyticsData = new AnalyticsData(UUID.randomUUID()); | ||
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Generated a new Analytics UUID"); | ||
try { | ||
MAPPER.writeValue(Files.newOutputStream(file), analyticsData); | ||
} catch (IOException e) { | ||
LOGGER.warn(SolarThingConstants.SUMMARY_MARKER, "Couldn't save analytics data!", e); | ||
} | ||
} | ||
final String clientId = analyticsData.uuid.toString(); | ||
LOGGER.debug("Using Analytics UUID: " + clientId); | ||
googleAnalytics = GoogleAnalytics.builder() | ||
.withConfig(new GoogleAnalyticsConfig() | ||
.setThreadTimeoutSecs(5) | ||
) | ||
.withDefaultRequest(new DefaultRequest() | ||
.applicationName("solarthing-program") | ||
.applicationVersion("V-UNKNOWN") | ||
.clientId(clientId) | ||
) | ||
.withTrackingId("UA-70767765-2") | ||
.build(); | ||
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Analytics are ENABLED! " + ANALYTICS_NOTE); | ||
} else { | ||
// TODO when the --validate argument is present, this is always printed. Think about if we want to let the user know what the actual configuration is | ||
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Google Analytics is disabled"); | ||
googleAnalytics = null; | ||
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Analytics are disabled"); | ||
} | ||
} | ||
|
||
public void sendStartUp(ProgramType programType) { | ||
if (googleAnalytics != null) { | ||
LOGGER.info("Sending program type to Google Analytics"); | ||
googleAnalytics.screenView() | ||
.screenName(programType.getName()) | ||
.sendAsync(); | ||
googleAnalytics.event() | ||
.eventCategory("startup") | ||
.eventAction(programType.getName()) | ||
.eventLabel(JarUtil.getJarFileName()) // so we know what version they're running | ||
.sendAsync(); | ||
if (isEnabled) { | ||
LOGGER.info("Sending program type to analytics (" + programType + ") " + ANALYTICS_NOTE); | ||
} | ||
} | ||
public void sendMateStatus(String data, int uptimeHours) { | ||
if (googleAnalytics != null) { | ||
LOGGER.info("Sending Mate status to Google Analytics. data=" + data + " uptime hours=" + uptimeHours); | ||
googleAnalytics.event() | ||
.eventCategory("status") | ||
.eventAction("mate") | ||
.eventLabel(data) | ||
.eventValue(uptimeHours) | ||
.sendAsync(); | ||
if (isEnabled) { | ||
LOGGER.info("Sending Mate status to analytics. data=" + data + " uptime hours=" + uptimeHours + " " + ANALYTICS_NOTE); | ||
} | ||
} | ||
public void sendRoverStatus(String data, int uptimeHours) { | ||
if (googleAnalytics != null) { | ||
LOGGER.info("Sending Rover status to Google Analytics. data=" + data + " uptime hours=" + uptimeHours); | ||
googleAnalytics.event() | ||
.eventCategory("status") | ||
.eventAction("rover") | ||
.eventLabel(data) | ||
.eventValue(uptimeHours) | ||
.sendAsync(); | ||
} | ||
} | ||
private static final class AnalyticsData { | ||
@JsonProperty("uuid") | ||
private final UUID uuid; | ||
|
||
@JsonCreator | ||
private AnalyticsData(@JsonProperty(value = "uuid", required = true) UUID uuid) { | ||
this.uuid = uuid; | ||
if (isEnabled) { | ||
LOGGER.info("Sending Rover status to analytics. data=" + data + " uptime hours=" + uptimeHours + " " + ANALYTICS_NOTE); | ||
} | ||
} | ||
} |
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
7 changes: 0 additions & 7 deletions
7
client/src/main/java/me/retrodaredevil/solarthing/config/options/ActionsOption.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
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
Oops, something went wrong.