AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to create a segment for a campaign in Pinpoint.

/* * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.example.pinpoint; import; import; import*; import java.util.HashMap; import java.util.Map; public class CreateSegment { public static void main(String[] args) { final String USAGE = "\n" + "CreateSegment - create a segment \n\n" + "Usage: CreateSegment <appId>\n\n" + "Where:\n" + " appId - the ID the application to create a segment for.\n\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String appId = args[0]; PinpointClient pinpoint = PinpointClient.builder().region(Region.US_EAST_1).build(); SegmentResponse result = createSegment(pinpoint, appId); System.out.println("Segment " + + " created."); System.out.println(result.segmentType()); } private static SegmentResponse createSegment(PinpointClient client, String appId) { Map<String, AttributeDimension> segmentAttributes = new HashMap<>(); segmentAttributes.put("Team", AttributeDimension.builder() .attributeType(AttributeType.INCLUSIVE) .values("Lakers") .build()); RecencyDimension recencyDimension = RecencyDimension.builder() .duration("DAY_30") .recencyType("ACTIVE") .build(); SegmentBehaviors segmentBehaviors = SegmentBehaviors.builder() .recency(recencyDimension) .build(); SegmentDemographics segmentDemographics = SegmentDemographics .builder() .build(); SegmentLocation segmentLocation = SegmentLocation .builder() .build(); SegmentDimensions dimensions = SegmentDimensions .builder() .attributes(segmentAttributes) .behavior(segmentBehaviors) .demographic(segmentDemographics) .location(segmentLocation) .build(); WriteSegmentRequest writeSegmentRequest = WriteSegmentRequest.builder() .name("MySegment") .dimensions(dimensions) .build(); CreateSegmentRequest createSegmentRequest = CreateSegmentRequest.builder() .applicationId(appId) .writeSegmentRequest(writeSegmentRequest) .build(); CreateSegmentResponse createSegmentResult = client.createSegment(createSegmentRequest); System.out.println("Segment ID: " + createSegmentResult.segmentResponse().id()); return createSegmentResult.segmentResponse(); } }

Sample Details

Service: pinpoint

Last tested: 2019-06-01

Author: jschwarzwalder AWS

Type: full-example

On this page: