@adobe/magento-storefront-event-collector

中文文档
1.18.0发布于 2026/08/11MITTypeScriptESM + CJS近 30 天下载 2.8万

Event Collectors for Adobe Commerce storefronts

原始使用文档
文档目录10 节
  1. Overview
  2. Installation
  3. Quick start
  4. Usage
  5. Turning off collection per edge
  6. Handling custom events
  7. Handling event overrides (custom attributes)
  8. Shopper Consent and Data Collection Opt out
  9. PII Data Collection
  10. Support

Adobe Commerce Events Collectors

version downloads size build typescript contributing

Overview

This package listens for and handles events published by the Adobe Commerce Events SDK to the adobeDataLayeracdl. It runs as a side effect and is meant to be a convenience for users who want to send event data to Adobe Commerce.

Installation

The collector can be used as a hosted script, or bundled in a JavaScript application. The script version is hosted on jsdelivr, and the bundled version is hosted on npm.

To load the Collector as a script, use the following snippet.

<script src="https://cdn.jsdelivr.net/npm/@adobe/commerce-events-collectors/dist/index.js"></script>

To install the script as a dependency, run this command.

npm install @adobe/commerce-events-collectors

Quick start

After loading the collector script, or importing the package as shown below, there is nothing else that needs to be done.

import "@adobe/commerce-events-collectors";

Usage

The collector listens for the following events.

  • pageView
  • addToCart
  • productPageView
  • shoppingCartView
  • initiateCheckout
  • openCart
  • placeOrder
  • recsItemAddToCartClick
  • recsItemClick
  • recsRequestSent
  • recsResponseReceived
  • recsUnitRender
  • recsUnitView
  • removeFromCart
  • searchCategoryClick
  • searchProductClick
  • searchRequestSent
  • searchResponseReceived
  • searchResultsView
  • categoryResultsView
  • searchSuggestionClick
  • createAccount
  • editAccount
  • signIn
  • signOut
  • custom

B2B events

  • createRequisitionList
  • deleteRequisitionList
  • addToRequisitionList
  • removeFromRequisitionList

The handlers forward events to two edges:

  • Adobe Commerce Data Services (maintained by Adobe Engineering and used to power merchant performance dashboards)

    Required contexts:

    • StorefrontInstance

    Events not forwarded to Adobe Commerce:

    • createAccount
    • editAccount
    • openCart
    • removeFromCart
    • signIn
    • signOut
    • custom

    B2B events:

    • createRequisitionList
    • deleteRequisitionList
    • addToRequisitionList
    • removeFromRequisitionList
  • Adobe Experience Platform (AEP) (requires a subscription and additional merchant setup; data can be used by merchants inside the Adobe Experience Platform for detailed analytics, targeted merchandising, real time customer data profiles, and more)

    Required contexts:

    • AEP
    • EventForwarding.aep: true

    Events not forwarded to AEP Edge:

    • recsItemAddToCartClick
    • recsItemClick
    • recsRequestSent
    • searchResponseReceived
    • searchCategoryClick
    • searchProductClick
    • searchResultsView
    • categoryResultsView
    • searchSuggestionClick

Turning off collection per edge

Events are sent to Adobe Commerce Data Services by default. To turn collection off collection, set EventForwarding.commerce: false.

Events are not set to AEP Edge unless explicitly configured (EventForwarding.aep: true);

Handling custom events

Custom events are supported for the Adobe Experience Platform only. Custom data will not be forwarded to Adobe Commerce dashboards and metrics trackers.

For any custom event, the collector:

  • addsidentityMap with ECID as a primary identity
  • includes email in identityMap as a secondary identity if personalEmail.address is set in the event
  • wraps the full event inside an xdm object before forwarding to the Edge

Example:

Custom event published through MSE SDK:

mse.publish.custom({
    commerce: {
        saveForLaters: {
            value: 1,
        },
    },
});

In AEP Edge:

{
  xdm: {
    identityMap: {
      ECID: [
        {
          id: 'ecid1234',
          primary: true
        }
      ],
      email: [
        {
          id: "[email protected]",
          primary: false
        }
      ]
    },
    commerce: {
        saveForLaters: {
            value: 1
        }
    }
  }
}

note Using custom events may affect OOTB Adobe Analytics reports.

Handling event overrides (custom attributes)

Attribute overrides for standard events are supported for the Experience Platform only. Custom data will not be forwarded to Commerce dashboards and metrics trackers.

For any event with a set customContext, the collector overrides joins fields set in the relevant contexts with fields in customContext. The use case for overrides is when a developer wants to reuse and extend contexts set by other parts of the page in already supporte events.

Note when overriding custom events, event forwarding to AEP should be turned off for that event type in order to avoid-double counting.

Example:

Product view with Adobe Commerce overrides published though MSE SDK:

Product context (set by another script on the page):

{
}
mse.publish.productPageView({
    productListItems: [
        {
            productCategories: [
                {
                    categoryID: "cat_15",
                    categoryName: "summer pants",
                    categoryPath: "pants/mens/summer",
                },
            ],
        },
    ],
});

In AEP Edge:

{
  xdm: {
    eventType: 'commerce.productViews',
    identityMap: {
      ECID: [
        {
          id: 'ecid1234',
          primary: true,
        }
      ]
    },
    commerce: {
      productViews: {
        value : 1,
      }
    },
    productListItems: [{
        SKU: "1234",
        name: "leora summer pants",
        productCategories: [{
            categoryID: "cat_15",
            categoryName: "summer pants",
            categoryPath: "pants/mens/summer",
        }],
    }],
  }
}

Note Overriding events with custom attributes may affect OOTB Adobe Analytics reports.

The "mg_dnt" cookie is used by Product Recommendations to restrict data collection.

when the cookie restriction mode is enabled, data services will set the "mg_dnt" cookie to true.

const listenForCookieEvents = ($) => {
    const DNT_COOKIE = "mg_dnt";
    let userAllowedSaveCookie = !!$.mage.cookies.get("user_allowed_save_cookie");

    if (userAllowedSaveCookie) {
        $.mage.cookies.clear(DNT_COOKIE);
    } else {
        $.mage.cookies.set(DNT_COOKIE, true);
    }
};

By default, the user consent preference in AEP is set to "opt in", unless the cookie restriction mode is enabled and the "mg_dnt" cookie is present.

The script will keep polling to check for any changes and send the updated preference to AEP.

const doNotTrackCookie = document.cookie.indexOf("mg_dnt") !== -1;
alloy("setConsent", {
    consent: [
        {
            standard: "Adobe",
            version: "1.0",
            value: {
                general: doNotTrackCookie ? "out" : "in",
            },
        },
    ],
});
setInterval(setConsent, 1000);

PII Data Collection

The following events forward a user's email as PII data to AEP:

createAccount

editAccount

signIn

Support

If you have any questions or encounter any issues, please reach out at these locations.

版本与发布记录

@adobe/magento-storefront-event-collector 共发布 310 个版本,首次发布于 2021/03/18;过去 12 个月发布了 9 个版本。

版本发布日期距今
1.18.0latest2026/08/112 个月前
0.0.0-84da724408a456d7ef1cd15b1cb6c1c6da4f83e3qa2026/08/112 个月前
0.0.0-7387e97ff463b8c6f589cb378485c553591016bc2026/07/303 个月前
1.17.02026/05/046 个月前
0.0.0-073607462513e30948d67e0f5de3f6770bc194e02026/05/046 个月前
0.0.0-278062401f574c64949b443e2e19a7d80b93b7d32026/05/016 个月前

关于 @adobe/magento-storefront-event-collector 的常见问题

@adobe/magento-storefront-event-collector 是什么?

Event Collectors for Adobe Commerce storefronts

如何安装 @adobe/magento-storefront-event-collector?

在项目目录运行 npm install @adobe/magento-storefront-event-collector,或使用 pnpm add / yarn add / bun add。

@adobe/magento-storefront-event-collector 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/magento-storefront-event-collector 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adobe/magento-storefront-event-collector 可以商用吗?

@adobe/magento-storefront-event-collector 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/magento-storefront-event-collector 的下载量有多少?

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

@adobe/magento-storefront-event-collector 还在维护吗?

最新版本 1.18.0 发布于 2026/08/11(2 个月前);至今共发布 310 个版本,其中过去 12 个月发布了 9 个;首次发布于 2021/03/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。