Data Collection

Before the Salesforce Interactions SDK can begin capturing data, initialize the Salesforce Interactions SDK and gain the user’s consent to track their activity.

If your site has an existing consent management platform, integrate its signals with the SDK’s init function to confirm the user has granted permission to track.

1SalesforceInteractions.init({
2  consents: [
3    {
4      purpose: "Tracking",
5      provider: "OneTrust",
6      status: "Opt In",
7    },
8  ],
9});

For more information, see Initialization and Consent

Capture User Engagement Data 

Once initialization is complete, you can track a user’s actions by sending an interaction object within the sendEvent() function’s payload. The name field of the interaction specifies the type of action that occurred.

This is the foundation for understanding user behavior, tracking conversions, and personalizing the user experience.

1// Example: Tracking when a user views a specific product.
2SalesforceInteractions.sendEvent({
3  interaction: {
4    name: "View Catalog Object",
5    catalogObject: {
6      type: "Product",
7      id: "65e4e737",
8      attributes: {
9        description: "Classic black running shoes",
10      },
11    },
12  },
13});

Capture Profile Data 

To identify a user or update their profile attributes, send a user object within the sendEvent() function’s payload. This is essential for building a unified profile of your customer across different sessions and devices.

1SalesforceInteractions.sendEvent({
2  user: {
3    attributes: {
4      email: "user@domain.com",
5    },
6  },
7});

Combine Profile and Engagement Data 

When capturing profile data, you aren’t limited to that minimal interaction format. You can combine any of the interaction data models with profile information to collect as much context for an event as possible.

1SalesforceInteractions.sendEvent({
2  interaction: {
3    name: "View Catalog Object",
4    catalogObject: {
5      type: "Product",
6      id: "65e4e737",
7      attributes: {
8        description: "Classic black running shoes",
9      },
10    },
11  },
12  user: {
13    attributes: {
14      email: "user@domain.com",
15    },
16  },
17});