Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Creating an item interaction event tracker
Before you can record item interaction events, you must create an item interaction event tracker. An event
tracker directs new event data to the Item interactions dataset in
your dataset group.
You create an event tracker with the Amazon Personalize console or the
CreateEventTracker API operation. You pass as a
parameter the Amazon Resource Name (ARN) of the dataset group that
contains the target Item interactions dataset. For instructions on creating an
event tracker using the Amazon Personalize console, see Creating an event tracker
(console).
An event tracker includes a tracking
ID, which you pass as a parameter when you use the PutEvents operation. Amazon Personalize then appends the new event data to
the Item interactions dataset of the dataset group you specify in your event
tracker.
You can create only one item interaction event tracker for a dataset group.
- Python
-
import boto3
personalize = boto3.client('personalize')
response = personalize.create_event_tracker(
name='MovieClickTracker',
datasetGroupArn='arn:aws:personalize:us-west-2:acct-id
:dataset-group/MovieClickGroup'
)
print(response['eventTrackerArn'])
print(response['trackingId'])
The event tracker ARN and tracking ID display, for
example:
{
"eventTrackerArn": "arn:aws:personalize:us-west-2:acct-id:event-tracker/MovieClickTracker",
"trackingId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
- Amazon CLI
-
aws personalize create-event-tracker \
--name MovieClickTracker \
--dataset-group-arn arn:aws:personalize:us-west-2:acct-id
:dataset-group/MovieClickGroup
The event tracker ARN and tracking ID display, for
example:
{
"eventTrackerArn": "arn:aws:personalize:us-west-2:acct-id:event-tracker/MovieClickTracker",
"trackingId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
- SDK for JavaScript v3
-
// Get service clients module and commands using ES6 syntax.
import { CreateEventTrackerCommand } from
"@aws-sdk/client-personalize";
import { personalizeClient } from "./libs/personalizeClients.js";
// Or, create the client here.
// const personalizeClient = new PersonalizeClient({ region: "REGION"});
// Set the event tracker's parameters.
export const createEventTrackerParam = {
datasetGroupArn: 'DATASET_GROUP_ARN', /* required */
name: 'NAME', /* required */
}
export const run = async () => {
try {
const response = await personalizeClient.send(new CreateEventTrackerCommand(createEventTrackerParam));
console.log("Success", response);
return response; // For unit tests.
} catch (err) {
console.log("Error", err);
}
};
run();
- SDK for Java 2.x
-
public static String createEventTracker(PersonalizeClient personalizeClient,
String eventTrackerName,
String datasetGroupArn) {
String eventTrackerId = null;
String eventTrackerArn = null;
long maxTime = 3 * 60 * 60;
long waitInMilliseconds = 30 * 1000;
String status;
try {
CreateEventTrackerRequest createEventTrackerRequest = CreateEventTrackerRequest.builder()
.name(eventTrackerName)
.datasetGroupArn(datasetGroupArn)
.build();
CreateEventTrackerResponse createEventTrackerResponse =
personalizeClient.createEventTracker(createEventTrackerRequest);
eventTrackerArn = createEventTrackerResponse.eventTrackerArn();
eventTrackerId = createEventTrackerResponse.trackingId();
System.out.println("Event tracker ARN: " + eventTrackerArn);
System.out.println("Event tracker ID: " + eventTrackerId);
maxTime = Instant.now().getEpochSecond() + maxTime;
DescribeEventTrackerRequest describeRequest = DescribeEventTrackerRequest.builder()
.eventTrackerArn(eventTrackerArn)
.build();
while (Instant.now().getEpochSecond() < maxTime) {
status = personalizeClient.describeEventTracker(describeRequest).eventTracker().status();
System.out.println("EventTracker status: " + status);
if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) {
break;
}
try {
Thread.sleep(waitInMilliseconds);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}
return eventTrackerId;
}
catch (PersonalizeException e){
System.out.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return eventTrackerId;
}