Crie segmentos no Amazon Pinpoint - Amazon Pinpoint

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Crie segmentos no Amazon Pinpoint

Para chegar ao público-alvo de uma campanha, crie um segmento baseado nos dados relatados pelo aplicativo. Por exemplo, para entrar em contato com usuários que não usaram o aplicativo recentemente, você pode definir um segmento para aqueles que não o acessaram nos últimos 30 dias.

Para ver mais exemplos de código, consulte Exemplos de código.

Crie segmentos com o AWS SDK for Java

O exemplo a seguir demonstra como criar um segmento com o AWS SDK for Java. O exemplo cria um segmento de usuários cuja equipe é a Lakers e esteve ativa nos últimos 30 dias. Depois que o segmento for criado, você poderá usá-lo como parte de uma campanha ou jornada. Para ver um exemplo de uso de um segmento com uma campanha, consulteCrie campanhas do Amazon Pinpoint de forma programática.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.AttributeDimension; import software.amazon.awssdk.services.pinpoint.model.SegmentResponse; import software.amazon.awssdk.services.pinpoint.model.AttributeType; import software.amazon.awssdk.services.pinpoint.model.RecencyDimension; import software.amazon.awssdk.services.pinpoint.model.SegmentBehaviors; import software.amazon.awssdk.services.pinpoint.model.SegmentDemographics; import software.amazon.awssdk.services.pinpoint.model.SegmentLocation; import software.amazon.awssdk.services.pinpoint.model.SegmentDimensions; import software.amazon.awssdk.services.pinpoint.model.WriteSegmentRequest; import software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest; import software.amazon.awssdk.services.pinpoint.model.CreateSegmentResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import java.util.HashMap; import java.util.Map;
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.AttributeDimension; import software.amazon.awssdk.services.pinpoint.model.SegmentResponse; import software.amazon.awssdk.services.pinpoint.model.AttributeType; import software.amazon.awssdk.services.pinpoint.model.RecencyDimension; import software.amazon.awssdk.services.pinpoint.model.SegmentBehaviors; import software.amazon.awssdk.services.pinpoint.model.SegmentDemographics; import software.amazon.awssdk.services.pinpoint.model.SegmentLocation; import software.amazon.awssdk.services.pinpoint.model.SegmentDimensions; import software.amazon.awssdk.services.pinpoint.model.WriteSegmentRequest; import software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest; import software.amazon.awssdk.services.pinpoint.model.CreateSegmentResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import java.util.HashMap; import java.util.Map; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateSegment { public static void main(String[] args) { final String usage = """ Usage: <appId> Where: appId - The application ID to create a segment for. """; 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 " + result.name() + " created."); System.out.println(result.segmentType()); pinpoint.close(); } public static SegmentResponse createSegment(PinpointClient client, String appId) { try { 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()); System.out.println("Done"); return createSegmentResult.segmentResponse(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } }

Quando você executa esse exemplo, o seguinte é impresso na janela do console do seuIDE:

Segment ID: 09cb2967a82b4a2fbab38fead8d1f4c4

Para ver o SDK exemplo completo, consulte CreateSegment.java on GitHub.