Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

使用適用於 JavaScript 的 SDK (v3) 的 Amazon Personalize Events 範例

Focus mode
使用適用於 JavaScript 的 SDK (v3) 的 Amazon Personalize Events 範例 - AWS SDK for JavaScript
This page has not been translated into your language. Request translation

AWS SDK for JavaScript V3 API 參考指南詳細說明 第 3 版 AWS SDK for JavaScript (V3) 的所有 API 操作。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS SDK for JavaScript V3 API 參考指南詳細說明 第 3 版 AWS SDK for JavaScript (V3) 的所有 API 操作。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

下列程式碼範例示範如何使用 AWS SDK for JavaScript (v3) 搭配 Amazon Personalize Events 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

以下程式碼範例顯示如何使用 PutEvents

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutEventsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Convert your UNIX timestamp to a Date. const sentAtDate = new Date(1613443801 * 1000); // 1613443801 is a testing value. Replace it with your sentAt timestamp in UNIX format. // Set put events parameters. const putEventsParam = { eventList: [ /* required */ { eventType: "EVENT_TYPE" /* required */, sentAt: sentAtDate /* required, must be a Date with js */, eventId: "EVENT_ID" /* optional */, itemId: "ITEM_ID" /* optional */, }, ], sessionId: "SESSION_ID" /* required */, trackingId: "TRACKING_ID" /* required */, userId: "USER_ID" /* required */, }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutEventsCommand(putEventsParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 的詳細資訊,請參閱《AWS SDK for JavaScript API 參考》中的 PutEvents

以下程式碼範例顯示如何使用 PutEvents

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutEventsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Convert your UNIX timestamp to a Date. const sentAtDate = new Date(1613443801 * 1000); // 1613443801 is a testing value. Replace it with your sentAt timestamp in UNIX format. // Set put events parameters. const putEventsParam = { eventList: [ /* required */ { eventType: "EVENT_TYPE" /* required */, sentAt: sentAtDate /* required, must be a Date with js */, eventId: "EVENT_ID" /* optional */, itemId: "ITEM_ID" /* optional */, }, ], sessionId: "SESSION_ID" /* required */, trackingId: "TRACKING_ID" /* required */, userId: "USER_ID" /* required */, }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutEventsCommand(putEventsParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 的詳細資訊,請參閱《AWS SDK for JavaScript API 參考》中的 PutEvents

以下程式碼範例顯示如何使用 PutItems

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutItemsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put items parameters. For string properties and values, use the \ character to escape quotes. const putItemsParam = { datasetArn: "DATASET_ARN" /* required */, items: [ /* required */ { itemId: "ITEM_ID" /* required */, properties: '{"PROPERTY1_NAME": "PROPERTY1_VALUE", "PROPERTY2_NAME": "PROPERTY2_VALUE", "PROPERTY3_NAME": "PROPERTY3_VALUE"}' /* optional */, }, ], }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutItemsCommand(putItemsParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 詳細資訊,請參閱AWS SDK for JavaScript 《 API 參考》中的 PutItems

以下程式碼範例顯示如何使用 PutItems

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutItemsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put items parameters. For string properties and values, use the \ character to escape quotes. const putItemsParam = { datasetArn: "DATASET_ARN" /* required */, items: [ /* required */ { itemId: "ITEM_ID" /* required */, properties: '{"PROPERTY1_NAME": "PROPERTY1_VALUE", "PROPERTY2_NAME": "PROPERTY2_VALUE", "PROPERTY3_NAME": "PROPERTY3_VALUE"}' /* optional */, }, ], }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutItemsCommand(putItemsParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 詳細資訊,請參閱AWS SDK for JavaScript 《 API 參考》中的 PutItems

以下程式碼範例顯示如何使用 PutUsers

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutUsersCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put users parameters. For string properties and values, use the \ character to escape quotes. const putUsersParam = { datasetArn: "DATASET_ARN", users: [ { userId: "USER_ID", properties: '{"PROPERTY1_NAME": "PROPERTY1_VALUE"}', }, ], }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutUsersCommand(putUsersParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 詳細資訊,請參閱AWS SDK for JavaScript 《 API 參考》中的 PutUsers

以下程式碼範例顯示如何使用 PutUsers

SDK for JavaScript (v3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Get service clients module and commands using ES6 syntax. import { PutUsersCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put users parameters. For string properties and values, use the \ character to escape quotes. const putUsersParam = { datasetArn: "DATASET_ARN", users: [ { userId: "USER_ID", properties: '{"PROPERTY1_NAME": "PROPERTY1_VALUE"}', }, ], }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutUsersCommand(putUsersParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 如需 API 詳細資訊,請參閱AWS SDK for JavaScript 《 API 參考》中的 PutUsers

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.