Cart Interaction
A cart interaction is where a customer modifies the contents of their online shopping
cart.
Cart interactions come in two forms:
- Single Line Item: For modifying individual line items in the customer’s cart.
- Multiple Line Items: For bulk operations against the customer’s cart.
Single Line Item
The interaction names are used for cart interactions that affect individual line items.
| Interaction Name | Value |
|---|---|
| SalesforceInteractions.CartInteractionName.AddToCart | Add To Cart |
| SalesforceInteractions.CartInteractionName.RemoveFromCart | Remove From Cart |
1{
2 interaction: {
3 name: "Add To Cart",
4 lineItem: {
5 catalogObjectType: "Product",
6 catalogObjectId: "product-1",
7 quantity: 1,
8 price: 9.99,
9 currency: "USD",
10 attributes: {
11 giftWrapping: true
12 }
13 }
14 }
15}The fields for a single line cart interaction.
| Field Name | Field Type | Description |
|---|---|---|
| lineItem | Line Item Data | Required. A single Line Item Data value. |
| name | string | Required. The event names. |
Multiple Line Items
The interaction names used for cart interactions that affect all the line items in a cart.
| Interaction Name | Value |
|---|---|
| SalesforceInteractions.CartInteractionName.ReplaceCart | Replace Cart |
1{
2 interaction: {
3 name: "Replace Cart",
4 lineItems: [{
5 catalogObjectType: "Product",
6 catalogObjectId: "product-1",
7 quantity: 1,
8 price: 9.99,
9 currency: "USD",
10 attributes: {
11 giftWrapping: true
12 }
13 }, {
14 catalogObjectType: "Product",
15 catalogObjectId: "product-2",
16 quantity: 3,
17 price: 20,
18 currency: "USD",
19 attributes: {
20 giftWrapping: false
21 }
22 }]
23 }
24}The fields for multi-line cart interaction.
| Field Names | Field Type | Description |
|---|---|---|
| lineItems | array | Required. An array of zero to many Line Item Data values |
| name | string | Required. The event names. |
Example
Here’s an example of capturing a cart interaction using the Web SDK.
1SalesforceInteractions.sendEvent({
2 interaction: {
3 name: "Add To Cart",
4 lineItem: {
5 catalogObjectType: "Product",
6 catalogObjectId: "product-1",
7 quantity: 1,
8 price: 9.99,
9 currency: "USD",
10 attributes: {
11 giftWrapping: true
12 }
13 }
14 }
15})Here’s an example of capturing a cart interaction using the Sitemap.
1SalesforceInteractions.init().then(() => {
2 const sitemapConfig = {
3 global: {},
4 pageTypes: [{
5 name: 'product_detail_page',
6 isMatch: () => true,
7 listeners: [
8 SalesforceInteractions.listener("click", ".add-to-cart-button", () => {
9 SalesforceInteractions.sendEvent({
10 interaction: {
11 name: SalesforceInteractions.CartInteractionName.AddToCart,
12 lineItem: {
13 catalogObjectType: "Product",
14 catalogObjectId: "product-1",
15 quantity: 1,
16 price: 9.99,
17 currency: "USD",
18 attributes: {
19 giftWrapping: true
20 }
21 }
22 }
23 })
24 }
25 ]
26 }]
27 }
28 SalesforceInteractions.initSitemap(sitemapConfig)
29})