# Active Data

You can use [Active Data](https://help.salesforce.com/s/articleView?id=cc.b2c_active_merchandising.htm\&type=5) in your [Progressive Web App (PWA) Kit](/docs/commerce/b2c-commerce/guide/getting-started.md) site to:

- Observe product performance and order metrics.
- Set automated rules for merchandising (for example, search result sorting).

Active Data works by collecting engagement data from shoppers browsing your site and interacting with products. This data is then aggregated into predefined dimensions that are stored and associated with each product in your catalog. Active Data also collects order metrics. The metrics in Active Data can be used to:

- Analyze shopper on-site behavior so you can enhance the shopper experience and optimize product offerings to drive sales growth.
- Configure site rules - like automated merchandising - in Business Manager.

:::note
When a shopper opts out of [behavior tracking](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-tracking-preferences.md), the Active Data for that shopper’s session isn't collected or reflected in Active Data. This applies regardless of whether you enabled tracking in Business Manager.
:::

## Prerequisites

To use Active Data:

- To access the product impression and product view events, build your site using PWA Kit version 3.3.0 or later. If you have an earlier version that doesn't support Active Data, upgrade your project to use PWA Kit 3.3.0 or later.
- If you haven't already done so, configure an ocapi proxy that points to your B2C Commerce instance. To see the Active Data metrics or attributes in Business Manager, you must use a production environment. See [Configure Managed Runtime Environments](/docs/commerce/b2c-commerce/guide/proxying-requests.md#configure-managed-runtime-environments).
- [Configure Business Manager](#configure-business-manager).

### Configure Business Manager

#### Enable Data Collection

Open a support case asking Salesforce Customer Support to enable data collection.

#### Confirm that Sites are Online

1. Log into Business Manager.
2. Click App Launcher ![App Launcher](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/shared/appLauncher.png) and then select **Administration > Sites > Manage Sites**.
3. Confirm that the status is **Online** for the sites for which you want to track metrics. Active Data is collected only for live (online) sites.

#### Confirm that Tracking (Default for New Storefront Session) is Enabled

1. Log into Business Manager.
2. Click App Launcher ![App Launcher](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/shared/appLauncher.png) and then select **Merchant Tools > Site Preferences > Privacy**.
3. Confirm that Tracking (Default for New Storefront Session) is set to **Enabled**.

## Supported Events

This table identifies the events in a PWA Kit site that Active Data tracks.

| Event              | Description                                                                                                                          | PWA Kit Support |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | --------------- |
| Product Impression | Counts how many times a product is shown in minimal detail on a page. Examples include search results, recommendations, and banners. | Yes             |
| Product View       | Counts how many times a product is shown in great detail on a page. Examples include product detail and comparison pages.            | Yes             |
| Order              | Counts how many times a customer placed an order.                                                                                    | Yes             |

## Install Active Data

After completing the [prerequisites](#prerequisites), install Active Data by following these steps:

1. Run `npm run build` to rebuild the PWA Kit bundle.
2. Run `npm run push` to push the rebuilt bundle to Managed Runtime.

## Verify your Data

:::note
Events from storefront interactions are collated nightly, so there’s latency between when events occur and when you see data appearing on the **Active Data** tab.
:::

Data collected from events on your storefront is automatically associated with the relevant products and aggregated at various time durations. To confirm that this data is flowing correctly:

1. Log into Business Manager.
2. Open your Product Catalog.
3. Open a product.
4. Click the **Active Data** tab to confirm that the traffic and conversion metrics in the sample data shown below are incrementing based on the time durations.

![Associated screenshot](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/pwa-kit-managed-runtime/product-order-data3.png)

## Debug Metrics Issues

If the metrics aren’t incrementing as expected, complete these debugging steps:

- Ensure that you've waited for 24 hours after a [supported event](#supported-events) happened.
- Inspect the network activity for the project and confirm that Active Data requests are returning a 200 status code. The URL for an Active Data request includes "\_Analytics-Start".

If you completed the debugging steps and the metrics still aren’t incrementing, open a support case.

## Configure Sorting

After you [Verify your Data](#verify-your-data), you can use [Active Data attributes](https://help.salesforce.com/s/articleView?id=cc.b2c_sorting_rules.htm\&type=5) to power dynamic sort and search result sorting.

To configure sorting, in Business Manager, click App Launcher ![App Launcher](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/shared/appLauncher.png) and then select **Merchant Tools > Search > Sorting Rules**. For more information, see [Sorting Rules for B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_sorting_rules.htm\&type=5).

![Associated screenshot](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/pwa-kit-managed-runtime/active-data-sorting2.png)

## Limitations

Currently, Active Data in PWA Kit is limited to product-based use cases. Active Data as a mechanism for customer group segmentation isn’t supported.

## See Also

- [Data and Analytics](/docs/commerce/b2c-commerce/guide/data-and-analytics.md)
