jGMP

Java library for Google's Measurement Protocol.

License

License

GroupId

GroupId

com.github.tasubo
ArtifactId

ArtifactId

jgmp
Last Version

Last Version

1.7
Release Date

Release Date

Type

Type

jar
Description

Description

jGMP
Java library for Google's Measurement Protocol.
Project URL

Project URL

https://github.com/tasubo/jgmp.git
Source Code Management

Source Code Management

https://github.com/tasubo/jgmp.git

Download jgmp

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tasubo/jgmp/ -->
<dependency>
    <groupId>com.github.tasubo</groupId>
    <artifactId>jgmp</artifactId>
    <version>1.7</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tasubo/jgmp/
implementation 'com.github.tasubo:jgmp:1.7'
// https://jarcasting.com/artifacts/com.github.tasubo/jgmp/
implementation ("com.github.tasubo:jgmp:1.7")
'com.github.tasubo:jgmp:jar:1.7'
<dependency org="com.github.tasubo" name="jgmp" rev="1.7">
  <artifact name="jgmp" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tasubo', module='jgmp', version='1.7')
)
libraryDependencies += "com.github.tasubo" % "jgmp" % "1.7"
[com.github.tasubo/jgmp "1.7"]

Dependencies

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
org.hamcrest : hamcrest-library jar 1.3
org.mutabilitydetector : MutabilityDetector jar 0.9
org.mockito : mockito-core jar 1.9.5

Project Modules

There are no modules declared in this project.

jGMP

Build Status

Java library for Google's Measurement Protocol

https://developers.google.com/analytics/devguides/collection/protocol/v1/

Supports almost all features. 97% of lines covered by tests.

All builders and payload messages are immutable.

Notice

While aim of this library was to reduce chance of making invalid requests it is still possible to make invalid requests to GA due to not always consistent specs. If you find cases where this is true, please fill an issue and we will address it.

Maven

<dependency>
    <groupId>com.github.tasubo</groupId>
    <artifactId>jgmp</artifactId>
    <version>1.7</version>
</dependency>

Examples

        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withCacheBuster()
                .create();

        App app = App.named("jGMP integration test").create();

        ClientID clientID = ClientID.seeded("192.168.0.1", "MyString");

        mpClient.send(AppView.hit("View description").with(app).with(clientId));
        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withCacheBuster()
                .create();

        ClientID clientID = ClientID.seeded("my_cookie=789");

        Document document = Document.with()
                .description("long document")
                .hostname("localhost.com")
                .path("/root")
                .title("my document title")
                .create();

        mpClient.send(PageView.hit().with(document).with(clientID));
        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withClientId(clientId)
                .withCacheBuster()
                .create();

        App app = App.named("jGMP integration test").create();

        mpClient.send(Event.ofCategory("Test").withAction("testhit").labeled("Integration").create().with(app));
        App app = App.named("jGMP integration test")
                .version("0.1337")
                .create();

        SystemInfo systemInfo = SystemInfo.with()
                .colorBits(24)
                .screenResolution(800, 600)
                .userLanguage("lt_LT")
                .documentEncoding("UTF-8")
                .javaEnabled()
                .create();

        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withClientId(clientId)
                .withCacheBuster()
                .using(systemInfo)
                .using(app)
                .create();

        mpClient.send(Timing.pageLoad(23));
        App app = App.named("jGMP integration test")
                .version("0.8008")
                .create();

        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withClientId(clientId)
                .withCacheBuster()
                .using(app)
                .create();

        Decorating referrer = Referrer.from("http://localhost/");
        UserTiming userTiming = Timing.user().name("test").time(4).create();

        mpClient.send(userTiming.with(referrer));
        MpClient mpClient = MpClient.withTrackingId("UA-40659159-1")
                .withCacheBuster()
                .noCacheBuster()
                .anonymizingIp()
                .noAnonymizingIp()
                .usePost()
                .useSsl()
                .usePlainHttp()
                .useGet()
                .create();

        App app = App.named("jGMP integration test").create();

        mpClient.send(AppView.hit("View description").with(app));
		// example for asynchronous, non-blocking requests

		int concurrentRequests = 10;

        JavaGetConnectionRequester blockingHttpRequester = 
				new JavaGetConnectionRequester();		
		AsyncHttpRequester asyncHttpRequester = 
				new AsyncHttpRequester(blockingHttpRequester, concurrentRequests);
		
		MpClient asyncMpClient = MpClient.withTrackingId("UA-40659159-1")
				.withClientId(clientId)
				.httpRequester(asyncHttpRequester)
				.create();

        App app = App.named("jGMP integration test").create();

        asyncMpClient.send(AppView.hit("View description").with(app));

		// when your program shuts down you have to shutdown AsyncHttpRequester
		asyncHttpRequester.shutdown();

For more usage examples please see tests

Versions

Version
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0