Creating campaigns - Amazon Pinpoint

Creating campaigns

To help increase engagement between your app and its users, use Amazon Pinpoint to create and manage push notification campaigns that reach out to particular segments of users.

For example, your campaign might invite users back to your app who haven’t run it recently or offer special promotions to users who haven’t purchased recently.

A campaign sends a tailored message to a user segment that you specify. The campaign can send the message to all users in the segment, or you can allocate a holdout, which is a percentage of users who receive no messages.

You can set the campaign schedule to send the message once or at a recurring frequency, such as once a week. To prevent users from receiving the message at inconvenient times, the schedule can include a quiet time during which no messages are sent.

To experiment with alternative campaign strategies, set up your campaign as an A/B test. An A/B test includes two or more treatments of the message or schedule. Treatments are variations of your message or schedule. As your users respond to the campaign, you can view campaign analytics to compare the effectiveness of each treatment.

For more information, see Campaigns in the Amazon Pinpoint REST API Guide or Campaigns in the Amazon Pinpoint User Guide .

Creating standard campaigns

A standard campaign sends a custom push notification to a specified segment according to a schedule that you define.

Creating campaigns with the AWS SDK for Java

The following example demonstrates how to create a campaign with the AWS SDK for Java. For an example of creating a segment to pass in, see Building segments.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.CampaignResponse; import software.amazon.awssdk.services.pinpoint.model.Message; import software.amazon.awssdk.services.pinpoint.model.Schedule; import software.amazon.awssdk.services.pinpoint.model.Action; import software.amazon.awssdk.services.pinpoint.model.MessageConfiguration; import software.amazon.awssdk.services.pinpoint.model.WriteCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignResponse; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException;
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.CampaignResponse; import software.amazon.awssdk.services.pinpoint.model.Message; import software.amazon.awssdk.services.pinpoint.model.Schedule; import software.amazon.awssdk.services.pinpoint.model.Action; import software.amazon.awssdk.services.pinpoint.model.MessageConfiguration; import software.amazon.awssdk.services.pinpoint.model.WriteCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignResponse; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException; /** * 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 CreateCampaign { public static void main(String[] args) { final String usage = """ Usage: <appId> <segmentId> Where: appId - The ID of the application to create the campaign in. segmentId - The ID of the segment to create the campaign from. """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String appId = args[0]; String segmentId = args[1]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); createPinCampaign(pinpoint, appId, segmentId); pinpoint.close(); } public static void createPinCampaign(PinpointClient pinpoint, String appId, String segmentId) { CampaignResponse result = createCampaign(pinpoint, appId, segmentId); System.out.println("Campaign " + result.name() + " created."); System.out.println(result.description()); } public static CampaignResponse createCampaign(PinpointClient client, String appID, String segmentID) { try { Schedule schedule = Schedule.builder() .startTime("IMMEDIATE") .build(); Message defaultMessage = Message.builder() .action(Action.OPEN_APP) .body("My message body.") .title("My message title.") .build(); MessageConfiguration messageConfiguration = MessageConfiguration.builder() .defaultMessage(defaultMessage) .build(); WriteCampaignRequest request = WriteCampaignRequest.builder() .description("My description") .schedule(schedule) .name("MyCampaign") .segmentId(segmentID) .messageConfiguration(messageConfiguration) .build(); CreateCampaignResponse result = client.createCampaign(CreateCampaignRequest.builder() .applicationId(appID) .writeCampaignRequest(request).build()); System.out.println("Campaign ID: " + result.campaignResponse().id()); return result.campaignResponse(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } }

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

Campaign ID: b1c3de717aea4408a75bb3287a906b46

For the full SDK example, see CreateCampaign.java on GitHub.

Creating A/B test campaigns

An A/B test campaign behaves like a standard campaign, but enables you to define different treatments for the campaign message or schedule. An A/B test includes two or more treatments of the message or schedule. Treatments are variations of your message or schedule. As your users respond to the campaign, you can view campaign analytics to compare the effectiveness of each treatment.

Creating A/B test campaigns with the AWS SDK for Java

The following example demonstrates how to create an A/B test campaign with the AWS SDK for Java.

import com.amazonaws.services.pinpoint.AmazonPinpointClient; import com.amazonaws.services.pinpoint.model.Action; import com.amazonaws.services.pinpoint.model.CampaignResponse; import com.amazonaws.services.pinpoint.model.CreateCampaignRequest; import com.amazonaws.services.pinpoint.model.CreateCampaignResult; import com.amazonaws.services.pinpoint.model.Message; import com.amazonaws.services.pinpoint.model.MessageConfiguration; import com.amazonaws.services.pinpoint.model.Schedule; import com.amazonaws.services.pinpoint.model.WriteCampaignRequest; import com.amazonaws.services.pinpoint.model.WriteTreatmentResource; import java.util.ArrayList; import java.util.List; public class PinpointCampaignSample { public CampaignResponse createAbCampaign(AmazonPinpointClient client, String appId, String segmentId) { Schedule schedule = new Schedule() .withStartTime("IMMEDIATE"); // Default treatment. Message defaultMessage = new Message() .withAction(Action.OPEN_APP) .withBody("My message body.") .withTitle("My message title."); MessageConfiguration messageConfiguration = new MessageConfiguration() .withDefaultMessage(defaultMessage); // Additional treatments WriteTreatmentResource treatmentResource = new WriteTreatmentResource() .withMessageConfiguration(messageConfiguration) .withSchedule(schedule) .withSizePercent(40) .withTreatmentDescription("My treatment description.") .withTreatmentName("MyTreatment"); List<WriteTreatmentResource> additionalTreatments = new ArrayList<WriteTreatmentResource>(); additionalTreatments.add(treatmentResource); WriteCampaignRequest request = new WriteCampaignRequest() .withDescription("My description.") .withSchedule(schedule) .withSegmentId(segmentId) .withName("MyCampaign") .withMessageConfiguration(messageConfiguration) .withAdditionalTreatments(additionalTreatments) .withHoldoutPercent(10); // Hold out of A/B test CreateCampaignRequest createCampaignRequest = new CreateCampaignRequest() .withApplicationId(appId).withWriteCampaignRequest(request); CreateCampaignResult result = client.createCampaign(createCampaignRequest); System.out.println("Campaign ID: " + result.getCampaignResponse().getId()); return result.getCampaignResponse(); } }

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

Campaign ID: b1c3de717aea4408a75bb3287a906b46