0

I am beginning to set up Marketing Cloud Personalization (former Interaction Studio) and now have to develop the sitemap for a shop.

Currently, the detection of pageTypes works, and also the ViewCatalogObject interaction is detected when viewing a product in the shop. I have set up a listener to the Add to Cart button, but whatever I try, the event is not reflected in Marketing Cloud.

For testing purposes, I also replaced the ViewCatalogObject interaction with AddToCart when viewing the page. This leads to an empty Add To Cart event in MC Personalization when the page is viewed, although with the following error message (even when my interaction object has a field lineItem) :

Response was not OK: Event with .itemAction=[Add To Cart] missing required field [.lineItem or .lineItems].

This is my current sitemap:

SalesforceInteractions.init({
  // Initializes the Personalization module of the Salesforce Interactions SDK
  
}).then(() => {

  // Sitemap configuration object
  const sitemapConfig = {
    
    global: {
        contentZones: []
    }, 
    pageTypeDefault: {
      name: "default",
      interaction: {
        name: "Default Page",
      },
    },
    pageTypes: [
        {
            name: "main",
            isMatch: () => {
                return /https:\/\/my-domain.com\/?$/.test(window.location.href);
            },
            contentZones: [
                {
                    name: "main_hero_img",
                    selector: ".wp-block-cover__image-background"
                }
            ]

        },
        
        {
            name: "product_detail",
            
            isMatch: () => {
                return /\/produkt\/.+/.test(window.location.href);
            },

            interaction: {
                name: SalesforceInteractions.CatalogObjectInteractionName.ViewCatalogObject,
                catalogObject: {
                    type: "Product",
                    id: SalesforceInteractions.util.resolveWhenTrue.bind(() => {
                        return SalesforceInteractions.cashDom(".single_add_to_cart_button").first().val();
                    })
                },
                
            },

            listeners: [
                SalesforceInteractions.listener("click", ".single_add_to_cart_button", (e) => {

                    var item = {
                        catalogObjectType: "Product",
                        catalogObjectId: e.target.value,
                        quantity: 1
                    }

                    SalesforceInteractions.sendEvent({
                        interaction: {
                            name: SalesforceInteractions.CartInteractionName.AddToCart,
                            lineItem: item
                        }
                    });

                })
            ]
        }
        
    ] 

  };

  SalesforceInteractions.initSitemap(sitemapConfig); // Initializes the Sitemap
});

I also noticed that when the Add to Cart button is clicked, the page does a POST to itself to add the item into website's cart and then reloads. Is it possible that this interferes with the SalesforceInteractions.sendEvent() function and reloads the page before the event is registered in Marketing Cloud, or is it just something that I am missing in my sitemap configuration?

Any help is appreciated!

2 Answers 2

1

It is not very well documented, but AddToCart's lineItem requires the "price" attributes to be passed.

Even though the price won't be displayed in the AddToCart event in the Event Stream, it is required in the payload.

So you'll be able to fix the issue by adding "price" to your "item" object.

0

I got the same error during my sitemap testing. You have to add required fields to lineItem object (documented here)

interface LineItem {
  catalogObjectType: string; // Required
  catalogObjectId: string; // Required
  quantity: number; // Required
  price?: number;
  currency?: string;
  attributes?: { [key: string]: any };
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .