自2024年7月31日起, AWS SDK for Java 1.x已进入维护模式,并将于2025年12月31日end-of-support
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 Amazon Pinpoint 中创建分段
用户分段表示基于共同的特征(例如用户最近什么时候打开了您的应用程序或他们使用哪个设备)的用户子集。以下示例演示如何定义用户分段。
创建分段
通过在 Amazon PinpointSegmentDimensions 对象中创建分段的维度,在 中创建新的分段。
导入
import com.amazonaws.services.pinpoint.AmazonPinpoint; import com.amazonaws.services.pinpoint.AmazonPinpointClientBuilder; import com.amazonaws.services.pinpoint.model.CreateSegmentRequest; import com.amazonaws.services.pinpoint.model.CreateSegmentResult; import com.amazonaws.services.pinpoint.model.AttributeDimension; import com.amazonaws.services.pinpoint.model.AttributeType; import com.amazonaws.services.pinpoint.model.RecencyDimension; import com.amazonaws.services.pinpoint.model.SegmentBehaviors; import com.amazonaws.services.pinpoint.model.SegmentDemographics; import com.amazonaws.services.pinpoint.model.SegmentDimensions; import com.amazonaws.services.pinpoint.model.SegmentLocation; import com.amazonaws.services.pinpoint.model.SegmentResponse; import com.amazonaws.services.pinpoint.model.WriteSegmentRequest;
代码
Pinpoint pinpoint = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build(); 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 中设置 SegmentDimensions 对象,接着使用该对象创建 CreateSegmentRequest 对象。然后,将 CreateSegmentRequest 对象传递到 AmazonPinpointClient 的 createSegment
方法。
代码
WriteSegmentRequest writeSegmentRequest = new WriteSegmentRequest() .withName("MySegment").withDimensions(dimensions); CreateSegmentRequest createSegmentRequest = new CreateSegmentRequest() .withApplicationId(appId).withWriteSegmentRequest(writeSegmentRequest); CreateSegmentResult createSegmentResult = client.createSegment(createSegmentRequest);
请参阅 GitHub 上的完整示例
更多信息
-
《Amazon Pinpoint User Guide》中的 Amazon Pinpoint Segments
-
《Amazon Pinpoint Developer Guide》中的 Creating Segments
-
《Amazon Pinpoint API Reference》中的 Segments
-
《Amazon Pinpoint API Reference》中的 Segment