@adobe-mcid/visitor-js-server

中文文档
2.1.0发布于 2021/06/10ADOBE VISITOR.JS SERVER LIBRARY LICENSE AGREEMENTCommonJS近 30 天下载 2.2万

Server compatible Visitor ID service

原始使用文档
文档目录10 节
  1. Provided Interfaces
  2. What is an sdid
  3. What is an sdidConsumerID
  4. getVisitorValues()
  5. getSupplementalDataID(sdidConsumerID)
  6. attemptToPopulateSdidFromUrl(redirectURL)
  7. getState
  8. getCookieName
  9. setCustomerIDs
  10. Visitor#AuthState

Visitor JS - Server Side

This is a trimmed down version of the VisitorAPI JS library. It is designed to run on your server, either in a NodeJS or Rhino environment.

Provided Interfaces

  • getVisitorValues() : Object
  • getSupplementalDataID(sdidConsumerID): String
  • attemptToPopulateSdidFromUrl(redirectURL)
  • setCustomerIDs(object: customerIDs)
  • getState() : State { OrgID: { sdid, customerIDs }
  • getCookieName() : String, AMCV cookie name
  • Visitor#AuthState : Static Enum

What is an sdid

SDID is a randomly generated string that is sent in on each call that needs to be combined into a single Analytics entry.

When implementing Target server side, and Analytics client side, you need some sort of mechanism to synchronize the states between the client and the server. SDID is part of this state, which is an ID that allows us to combine calls to Target and calls to Analytics into a cohesive set of data.

Customer who are implementing Target client-side, don't need to worry about sdid.

What is an sdidConsumerID

sdidConsumerID is a unique string used to intentify the consumer.

All calls to Target that needs to combined must have the same SDID. Each of those calls need to have a unique sdidConsumerID in order for them to receive the SAME SDID.

In order to properly combine data, you must call visitor#generatePayload for every call to target, passing a unique sdidConsumerID for each call. We recommend using mbox names as sdidConsumerID.

getVisitorValues()

This method should be called to retrieve marketing cloud visitor ID, Audience Manager location hint and Audience Manger blob.

    // 1. Retrieve the AMCV cookie from the request.
    const cookies = cookie.parse(req.headers.cookie || "");
    const cookieName = visitor.getCookieName();
    const amcvCookie = cookies[cookieName];

    // 2. Instantiate Visitor instance
    const visitor = new Visitor("<orgId>", amcvCookie); 

    //3. Retrieve Visitor instance values
    const visitorValues = visitor.getVisitorValues();

    ...

getSupplementalDataID(sdidConsumerID)

This method should be called to generate a supplemental data ID.

Parameter is an object with the following props:

  • sdidConsumerID: As mentioned above, an sdidConsumerID must be provided.
    // 1. Retrieve the AMCV cookie from the request.
    var cookies = cookie.parse(req.headers.cookie || "");
    var cookieName = visitor.getCookieName();
    var amcvCookie = cookies[cookieName];

    // 2. Instantiate Visitor instance
    const visitor = new Visitor("<orgId>", amcvCookie);

    //3. Retrieve SDID
    const sdid = visitor.getSupplementalDataID("<some mbox>");

    ...

attemptToPopulateSdidFromUrl(redirectURL)

This method looks for an adobe_mc_sdid param in the URL. If found, parse it and look for SDID and CONSUMER, and try to set those IDs as supplemental Data IDs.

    // 1. Retrieve the AMCV cookie from the request.
    var cookies = cookie.parse(req.headers.cookie || "");
    var cookieName = visitor.getCookieName();
    var amcvCookie = cookies[cookieName];

    // 2. Instantiate Visitor instance
    const visitor = new Visitor("<orgId>", amcvCookie);

    //3. Attempt to populate SDIDs from
    visitor.attemptToPopulateSdidFromUrl(redirectURL);

    ...

getState

This method returns the internal state of the Visitor instance, which should be shared with the VisitorAPI client side library later on.

getCookieName

Simple helper that provides the AMCV cookie name to be retrieved from the Request.

setCustomerIDs

The setCustomerIDs method accepts multiple customer IDs for the same visitor. This helps you identify or target an individual user across different devices. For example, you can upload these IDs as customer attributes to the Marketing Cloud and access this data across the different solutions.

On the server, we are using this method to share those ids with Target, as well as adding them to the state that is shared with the client side VisitorAPI library.

IMPORTANT:

  • In order for those IDs to make it into the Target call, make sure you call setCustomerIDs before calling generatePayload.
  • If you call setCustomerIDs on the server, those IDs will be added to the state that gets shared with the client, and setCustomerIDs will be automatically called on the client so you don't have to do it again. You only need to call setCustomerIDs on the client if you have more ids to set, in addition to the ones you set on the server already.
  • Use the static enum Visitor.AuthState to set the authState property of the customerIds.
// Single ID with a single authentication state
visitor.setCustomerIDs({
    "userid": {
        "id": "67312378756723456",
        "authState": Visitor.AuthState.AUTHENTICATED
    }
});

/* 
Multiple IDs with only the first ID explicitly assigned an authentication state.
The second ID is not explicitly assigned an authentication state and is implicitly
assigned Visitor.AuthState.Unknown by default.
*/
visitor.setCustomerIDs({
    "userid": {
        "id": "67312378756723456",
        "authState": Visitor.AuthState.AUTHENTICATED
    },
    "puuid": "550e8400-e29b-41d4-a716-446655440000"
});

See Customer IDs and Authentication States

Visitor#AuthState

AuthState enum to be used when setting Customer IDs.

{ UNKNOWN: 0, AUTHENTICATED: 1, LOGGED_OUT: 2 }

版本与发布记录

@adobe-mcid/visitor-js-server 共发布 13 个版本,首次发布于 2016/09/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2021/06/105 年前
2.0.02018/05/228 年前
1.0.02016/12/029 年前
0.0.9-alpha.22016/11/0110 年前
0.0.92016/10/0110 年前
0.0.82016/10/0110 年前

关于 @adobe-mcid/visitor-js-server 的常见问题

@adobe-mcid/visitor-js-server 是什么?

Server compatible Visitor ID service

如何安装 @adobe-mcid/visitor-js-server?

在项目目录运行 npm install @adobe-mcid/visitor-js-server,或使用 pnpm add / yarn add / bun add。

@adobe-mcid/visitor-js-server 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe-mcid__visitor-js-server 是否存在。

@adobe-mcid/visitor-js-server 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe-mcid/visitor-js-server 可以商用吗?

@adobe-mcid/visitor-js-server 使用 ADOBE VISITOR.JS SERVER LIBRARY LICENSE AGREEMENT 许可。声明的许可为 ADOBE VISITOR.JS SERVER LIBRARY LICENSE AGREEMENT,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@adobe-mcid/visitor-js-server 的下载量有多少?

根据 npm 官方下载统计,@adobe-mcid/visitor-js-server 在 2026/10/05 – 2026/11/03 这 30 天内被下载 21,878 次,日均约 729 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe-mcid/visitor-js-server 还在维护吗?

最新版本 2.1.0 发布于 2021/06/10(5 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2016/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。