Create a Custom Feed on the Setup page to generate server-to-server API credentials.
Our Java SDK is available via Gradle or Maven.
Add the SDK dependency to your build.gradle
file.
dependencies {
implementation 'com:mparticle:server-events-sdk:2+'
}
Add the SDK dependency to your pom.xml
file.
<dependency>
<groupId>com.mparticle</groupId>
<artifactId>server-events-sdk</artifactId>
<version>2.0.0</version>
</dependency>
Now you can integrate mParticle in your Java application.
// configure API
EventsApi api = new ApiClient(
"YOUR_API_KEY",
"YOUR_API_SECRET")
.createService(EventsApi.class);
// assemble an event batch
Batch batch = new Batch();
batch.environment(Batch.Environment.DEVELOPMENT);
batch.userIdentities(new UserIdentities()
.customerId("1234")
.email("example@foo.com")
);
// Set a Data Plan
Context context = new Context();
DataPlanContext dpContext = new DataPlanContext();
dpContext.planId("mobile_data_plan");
dpContext.planVersion(2);
context.dataPlan(dpContext);
batch.context(context);
// create an event
CustomEvent customEvent = new CustomEvent().data(
new CustomEventData()
.eventName("bid")
);
// create attributes
Map<String, String> customAttributes = new HashMap<>();
customAttributes.put("price", 33);
// add them to an event
customEvent.getData().customAttributes(customAttributes);
batch.addEventsItem(customEvent);
// upload
Call<Void> singleResult = api.uploadEvents(batch);
Response<Void> singleResponse = singleResult.execute();
System.out.println("Returned code: " + singleResponse.code());
Go to the Live Stream and watch new events come in as you run your application.
Congrats on sending your first event to mParticle!
Some suggestions on what to do next:
Was this page helpful?