Skip to content

scoby-dev/analytics-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Scoby Analytics: Java Client

Scoby Analytics is ethical web analytics built for privacy-first websites. It uses state-of-the-art privacy-preserving design, architecture, and technology to protect your visitors’ digital privacy so effectively that no consent is required under GDPR, ePrivacy, or Schrems II – because there’s nothing to consent to.

Start your free trial today https://app.scoby.io/register

Did you know?

Scoby Analytics is free for non-profit projects. Claim your free account now

Installation

This library can be installed using Maven or Gradle.

Maven

Add this dependency to your pom.xml:

<dependency>
<groupId>io.scoby</groupId>
<artifactId>scoby-analytics-client</artifactId>
<version>1.0.0</version>
</dependency>

Gradle

Add this dependency to your build.gradle:

groovy
implementation 'io.scoby:scoby-analytics-client:1.0.0'

Prerequisites

You need two values to instantiate your Scoby Analytics Client: your API key and a salt. The salt is used to anonymize your traffic before it is sent to our servers. You can generate a cryptographically secure salt using the following command:

shell
openssl rand -base64 32

Please find your API key in your workspace's settings - don't have a workspace yet? Create one for free here

Usage

Instantiate your Scoby Analytics Client using your API key and salt.

java
import io.scoby.analytics.Client;
import io.scoby.analytics.PageViewParams;

Client client = new Client("INSERT_YOUR_API_KEY_HERE", "INSERT_YOUR_SALT_HERE");

The client supports asynchronous logging of page views via its logPageView method:

client.logPageView(new PageViewParams(
    "192.168.1.1",                    // IP_ADDRESS
    "https://example.com/page",       // REQUESTED_URL
    "Mozilla/5.0 (compatible...)",    // USER_AGENT
    "https://referrer.com"            // REFERRING_URL
)).thenAccept(success -> {
    if (success) {
        System.out.println("Page view logged successfully!");
    }
});

Visitor Segments

Visitor segmentation is a way to group website visitors based on their common characteristics or behaviors. By analyzing the browsing behavior of your different visitor segments, you can identify patterns or trends that can inform your website design or marketing strategy.

To use visitor segments, you need to define the characteristics or behaviors that you want to segment your audience by, such as age, gender, location, interests, or purchase history. Once you have defined your segments, you can assign them to your website visitors based on the data you collect from their interactions with your website. It's important to note that segments should always be used in plural, as this makes the most sense in the Scoby Analytics dashboard, where you can view and analyze your visitor segments data. Additionally, it's important to keep in mind that all future interactions of a visitor are associated with the segment they belong to at the time of the interaction. This means that if a visitor's segment changes over time, their new interactions will be associated with the new segment, rather than the previous one.

To log visitor segments using the Scoby Analytics library in your Java code, you can use the visitorSegments parameter when creating PageViewParams. Here's an example:

import io.scoby.analytics.Client;
import io.scoby.analytics.PageViewParams;

Client client = new Client("INSERT_YOUR_API_KEY_HERE", "INSERT_YOUR_SALT_HERE");

client.logPageView(new PageViewParams(
    "192.168.1.1",
    "https://example.com/page",
    "Mozilla/5.0 (compatible...)",
    "https://referrer.com",
    null, // visitorId
    new String[]{"Subscribers", "Women", "Young Adults"} // visitorSegments
)).thenAccept(success -> {
    if (success) {
        System.out.println("Page view with segments logged successfully!");
    }
});

In this example, we are logging a page view event and assigning the visitor segments Subscribers, Women, and Young Adults to the visitor who triggered the event. You can replace these segments with your own segment names based on your segmentation strategy.

It's worth noting that Scoby Analytics is designed to be privacy-preserving, and applies a k-Anonymity of 25 to visitor segments. This means that each segment must have at least 25 unique visitors before it is included in the analytics report, in order to protect the anonymity of individual visitors.

Visitor ID

To help you count your visitors as accurately as possible, you can provide a custom identifier, such as an account id, etc. This value is hashed before being sent to our servers to ensure that no personally identifiable information reaches our servers. However, to be on the safe side, you should talk to your data protection officer before using this feature.

import io.scoby.analytics.Client;
import io.scoby.analytics.PageViewParams;

Client client = new Client("INSERT_YOUR_API_KEY_HERE", "INSERT_YOUR_SALT_HERE");

client.logPageView(new PageViewParams(
    "192.168.1.1",
    "https://example.com/page",
    "Mozilla/5.0 (compatible...)",
    "https://referrer.com",
    "YOUR_VISITOR_ID" // This will be hashed before transmission
)).thenAccept(success -> {
    if (success) {
        System.out.println("Page view with visitor ID logged successfully!");
    }
});

Testing

mvn clean test

Note: For testing, you may need to add the following to your /etc/hosts file and run tests with sudo:

127.0.0.1       xyz789.s3y.io

Then run:

sudo mvn clean test

Support

Something's hard? We're here to help at hello@scoby.io

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages