创建物品交互事件跟踪器 - Amazon Personalize

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建物品交互事件跟踪器

必须先创建物品交互事件跟踪器,然后才能记录物品交互事件。事件跟踪器会将新事件数据定向到数据集组中的物品交互数据集

您可以使用 Amazon Personalize 控制台或CreateEventTrackerAPI操作创建事件跟踪器。您可以将包含目标项目交互数据集的数据集组的 Amazon 资源名称 (ARN) 作为参数传递。有关使用 Amazon Personalize 控制台创建事件跟踪器的说明,请参阅创建事件跟踪器(控制台)

事件跟踪器包括跟踪 ID,您在使用PutEvents操作时将其作为参数传递。然后,Amazon Personalize 将新事件数据附加到您在事件跟踪器中指定的数据集组的物品交互数据集中。

注意

您只能为一个数据集组创建一个物品交互事件跟踪器。

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'])

显示的事件跟踪ARN器和跟踪 ID,例如:

{ "eventTrackerArn": "arn:aws:personalize:us-west-2:acct-id:event-tracker/MovieClickTracker", "trackingId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
AWS CLI
aws personalize create-event-tracker \ --name MovieClickTracker \ --dataset-group-arn arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieClickGroup

显示的事件跟踪ARN器和跟踪 ID,例如:

{ "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; }