[Alpha]{class="badge informative"}

配置服务器SDK

本页介绍如何配置Server SDK。 对于Web SDK,请参阅配置Web SDK。

您使用​ configure ​方法配置服务器SDK。 在服务器启动时以及在调用forRequest或任何其他方法之前,在每个实例上调用一次。 每个forRequest句柄都使用创建它的实例的配置。

需要datastreamId、orgId和edgeCredentials属性。 所有其他属性都是可选的。 以下示例显示了一个使用每个可用属性的配置对象:

import { createInstance } from "@adobe/alloy-node";

const alloy = createInstance();

await alloy.configure({
  datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
  orgId: "ADB3LETTERSANDNUMBERS@AdobeOrg",
  edgeCredentials: {
    clientId: process.env.ADOBE_CLIENT_ID,
    clientSecret: process.env.ADOBE_CLIENT_SECRET,
    scopes: process.env.ADOBE_SCOPES.split(",")
  },
  debugEnabled: false,
  defaultConsent: "in",
  edgeBasePath: "ee",
  edgeConfigOverrides: {
    com_adobe_target: {
      propertyToken: "01dbc634-07c1-d8f9-ca69-b489a5ac5e94"
    }
  },
  edgeDomain: "data.example.com",
  idMigrationEnabled: false,
  onBeforeEventSend: (content) => {
    content.xdm.application ??= {};
    content.xdm.application.name = "Example storefront";
  },
  thirdPartyCookiesEnabled: false
});

配置属性 properties

属性
类型
必需
默认
datastreamId
字符串
是
无
orgId
字符串
是
无
edgeCredentials
对象
是
无
debugEnabled
布尔值
否
false
defaultConsent
字符串
否
"in"
edgeBasePath
字符串
否
"ee"
edgeConfigOverrides
对象
否
无
edgeDomain
字符串
否
"edge.adobedc.net"
idMigrationEnabled
布尔值
否
true
onBeforeEventSend
函数
否
无
thirdPartyCookiesEnabled
布尔值
否
true

仅当实例包含Consent组件时,defaultConsent属性才可用,默认情况下,createInstance包含Consent组件。 请参阅创建自定义实例。

Server SDK不支持的选项 unsupported

Web SDK为依赖于浏览器的功能提供了配置选项,例如链接点击收藏集、呈现个性化内容和推送通知。 服务器SDK不接受这些选项。 如果您包括一个,则configure将拒绝并显示命名该选项的Unknown field错误。

以下Web SDK选项不可用: autoCollectPropositionInteractions、clickCollection、clickCollectionEnabled、context、conversation、downloadLinkQualifier、onBeforeLinkClickSend、personalizationStorageEnabled、prehidingStyle、pushNotifications、streamingMedia和targetMigrationEnabled。

结果和错误 result

configure方法返回在配置成功时使用空对象解析的promise。 在以下情况下,该请求将拒绝:

  • edgeCredentials缺失或缺少其必需属性之一。
  • defaultConsent设置为"pending"。 请参阅defaultConsent。
  • 属性的值无效或无法识别。
  • 已在同一实例上成功调用configure。 每个实例只能配置一次。

如果configure拒绝,实例将保持未配置状态,forRequest将引发错误,直到调用configure成功。

recommendation-more-help
experience-platform-help-collection