Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
com.brsanthu:google-analytics-java
Advanced tools
This is Java API for Google Analytics (Measurement Protocol). More information about the protocol is available at https://developers.google.com/analytics/devguides/collection/protocol/v1/.
Java API for Google Analytics Measurement Protocol (part of Universal Analytics). This library is released under liberal Apache Open source License 2.0
Google Analytics Measurement Protocol is new tracking protocol, which will replace the legacy Tracking protocol. This protocol is documented at https://developers.google.com/analytics/devguides/collection/protocol/v1/
The library is available in Maven Central. Add the following dependency and you are good to go.
Maven:
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>google-analytics-java</artifactId>
<version>2.0.0</version>
</dependency>
Gradle:
compile("com.brsanthu:google-analytics-java:2.0.0")
To get a local build, do
git clone https://github.com/brsanthu/google-analytics-java.git
mvn install
View Javadocs here
Note that Version 2.x has different api than 1.x. Version 2.x is refactoring of majority of structure of the library with goal of making library easy to use and make it feel fluently. It is based on Java 1.8.
Here is V1 Readme
This library implements the measurement protocol with following features.
Before using the library to post events, GoogleAnalytics
instance needs to be initialized. Once it is initialized, same instance can be used
to post events across multiple threads and instance is designed to be thread-safe.
It can be initialized with two types of information. Set of information called configuration (via GoogleAnalyticsConfig
), which is used by the library and default request settings (DefaultRequest
), which defines the default attributes for all subsequent requests.
Builder also provides typed methods to set most-relavent attributes of default request for readability.
Simplified initialization with all defaults is as follows.
ga = GoogleAnalytics.builder()
.withTrackingId("UA-00000000")
.build();
To build with custom configuration:
ga = GoogleAnalytics.builder()
.withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(10))
.withTrackingId("UA-00000000")
.build();
To build with custom configuration and some default request attributes:
ga = GoogleAnalytics.builder()
.withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(10))
.withDefaultRequest(new DefaultRequest().userIp("127.0.0.1").trackingId("UA-00000000"))
.build();
Note that tracking id can be set to one value for all requests (using default request attributes) or it can be set on per request basis.
To send reqeusts, create one of the event type requests, configure the values for that event and call send()
.
Here are some examples:
ga.screenView()
.sessionControl("start")
.send();
ga.pageView()
.documentTitle(entry.getPage())
.documentPath("/" + entry.getPage())
.clientId("Some Id")
.customDimension(1, "Product")
.customDimension(1, "Version")
.userIp("198.165.0.1")
.send();
ga.exception()
.exceptionDescription(e.getMessage())
.send();
ga.screenView()
.sessionControl("end")
.send();
Sending request to Google Analytics is network call and hence it may take a little bit of time. If you would like to avoid this overhead, you can opt in to send requests asynchronously.
Executor is created to process the requests async with default config of minThreads=0, maxThreads=5, threadFormat=googleanalyticsjava-thread-{0}, threadTimeoutSecs=300, queueSize=1000. rejectExecutor=CallerRunsPolicy
.
If you want to change these values, configure them before building GoogleAnalytics
instance. You can also set your own executor in the config, in that case that executor will be used.
To send request async, call .sendAsync()
instead of .send()
as follows
ga.screenView()
.sessionControl("end")
.sendAsync();
Google Analytics api supports sending events in batch to reduce the network overhead. Batching is disabled by default but it can be enabled using batchingEnabled
config. This needs to be set before Google Analytics is built.
Once batching is enabled, usage is same as non-batching. Upon submission, request will be held in a internal list and upon reaching the batch limit, it will be posted to Google api. Note that batching can be used along with Async posting and it work in the same way.
Max batch size is 20 requests and that is the default, which can be changed using config batchSize
Library provides a master switch with config enabled
. If set to false
then requests will be accepted and silently dropped. This config variable can be changed before or after building the ga
instance.
Library tries to discover some default request parameters, which is controlled via config discoverRequestParameters
with default value of true
. Parameters are discoverd during the building process so it is one time activity.
It discovers following parameters:
To discover scren resolution and colors, it needs access to java.awt
. Since not all environments have access to awt, it is not enabled by default. If would like to use it, set config requestParameterDiscoverer
to instance of AwtRequestParameterDiscoverer
Library abstracts http client interaction via HttpClient
interface with default implementation based on Apache HttpClient. If you want to use your own version of http client, set config httpClient
.
There are few Java implementation of Google Analytics api, but found some issues (or protocol mismatch) with each of them.
https://github.com/nhnopensource/universal-analytics-java
https://code.google.com/p/jgoogleanalyticstracker/
https://github.com/siddii/jgoogleanalytics
FAQs
This is Java API for Google Analytics (Measurement Protocol). More information about the protocol is available at https://developers.google.com/analytics/devguides/collection/protocol/v1/.
We found that com.brsanthu:google-analytics-java demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.