Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.rlill:google-analytics-java:google-analytics-java-1.1.2'
}
dependencies {
implementation("com.github.rlill:google-analytics-java:google-analytics-java-1.1.2")
}
<dependency>
<groupId>com.github.rlill</groupId>
<artifactId>google-analytics-java</artifactId>
<version>google-analytics-java-1.1.2</version>
</dependency>
libraryDependencies += "com.github.rlill" % "google-analytics-java" % "google-analytics-java-1.1.2"
:dependencies [[com.github.rlill/google-analytics-java "google-analytics-java-1.1.2"]]
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.
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>google-analytics-java</artifactId>
<version>1.1.2</version>
</dependency>
To get a local build, do
git clone https://github.com/brsanthu/google-analytics-java.git
mvn install
View Javadocs here http://brsanthu.github.io/google-analytics-java/javadocs/
This library implements the measurement protocol with following features.
Version 1.1.2 - Apr 29 2015 <to be updated>
Version 1.1.1 - May 21 2014
Version 1.1.0 - Apr 22 2014
Version 1.0.5 - Apr 09 2014
Version 1.0.4 - Mar 3 2014
Version 1.0.3 - Jan 20 2014
GoogleAnalytics ga = new GoogleAnalytics("UA-12345678-1");
ga.post(new PageViewHit("https://www.google.com", "Google Search"));
Or
GoogleAnalytics ga = new GoogleAnalytics("UA-12345678-1");
ga.postAsync(new PageViewHit("https://www.google.com", "Google Search"));
Or
GoogleAnalytics ga = new GoogleAnalytics("UA-12345678-1");
ga.postAsync(new RequestProvider() {
public GoogleAnalyticsRequest getRequest() {
return new PageViewHit("https://www.google.com", "Google Search");
}
});
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