Amazon Pinpoint
Developer Guide

Building Segments

To reach the intended audience for a campaign, build a segment based on the data reported by your app. For example, to reach users who haven’t used your app recently, you can define a segment for users who haven’t used your app in the last 7 days.

Building Segments With the AWS SDK for Java

The following example demonstrates how to build a segment with the AWS SDK for Java.

import; import; import; import; import; import; import; import; import; import; import; import; import java.util.HashMap; import java.util.Map; public class PinpointSegmentSample { public SegmentResponse createSegment(AmazonPinpointClient client, String appId) { Map<String, AttributeDimension> segmentAttributes = new HashMap<>(); segmentAttributes.put("Team", new AttributeDimension().withAttributeType(AttributeType.INCLUSIVE).withValues("Lakers")); SegmentBehaviors segmentBehaviors = new SegmentBehaviors(); SegmentDemographics segmentDemographics = new SegmentDemographics(); SegmentLocation segmentLocation = new SegmentLocation(); RecencyDimension recencyDimension = new RecencyDimension(); recencyDimension.withDuration("DAY_30").withRecencyType("ACTIVE"); segmentBehaviors.setRecency(recencyDimension); SegmentDimensions dimensions = new SegmentDimensions() .withAttributes(segmentAttributes) .withBehavior(segmentBehaviors) .withDemographic(segmentDemographics) .withLocation(segmentLocation); WriteSegmentRequest writeSegmentRequest = new WriteSegmentRequest() .withName("MySegment").withDimensions(dimensions); CreateSegmentRequest createSegmentRequest = new CreateSegmentRequest() .withApplicationId(appId).withWriteSegmentRequest(writeSegmentRequest); CreateSegmentResult createSegmentResult = client.createSegment(createSegmentRequest); System.out.println("Segment ID: " + createSegmentResult.getSegmentResponse().getId()); return createSegmentResult.getSegmentResponse(); } }

When you run this example, the following is printed to the console window of your IDE:

Segment ID: 09cb2967a82b4a2fbab38fead8d1f4c4