Sending the cart to Connectif via AJAX

The AJAX event for products added or removed is used to indicate changes to the cart using AJAX, without the need to reload the page. This way, you can ensure that Connectif is immediately notified when products are added or removed from the shopping cart and optimize the tracking of changes to the cart.

  

This article is part of the guide to creating a custom integration.
If your integration is via a module, this tag will be added to your ecommerce platform automatically.

 

How to use it

The AJAX cart event is used to report on a user's shopping cart at a specific time. It notifies you, via JavaScript, when a user accesses a product detail page by using the function connectif.managed.sendEvents, making the following call to Connectif:

connectif.managed.sendEvents([], { cart: cartObject });
  

This event is an alternative to implementing the cart information notification.

  

The "cartObject" object has a structure that contains the el "Product Basket Item" object.

 

Other considerations

It is important to also send the notification when the cart is emptied, so that it does not end up being marked as abandoned.

 

Example

The notification will look like this (not all data is required):

connectif.managed.sendEvents([], { 
    cart: {
        cartId: '123456789',
        totalQuantity: 1,
        totalPrice: 10.2,
        products: [
            {
                quantity: 1,
                price: 10.2,
                productDetailUrl: 'https://mywebsite.com/myproduct-detail-url',
                productId: '12345678910',
                name: 'My product',
                description: 'product description',
                imageUrl: 'https://mywebsite.com/images/myproduct',
                unitPrice: 10.2,
                availability: 'InStock',
                categories: ['/Home'],
                tags: ['tag1','tag2'],
                brand: 'Brand',
                reviewCount: 1,
                rating: 2,
                ratingCount: 2,
                thumbnailUrl: 'https://mywebsite.com/images/thumb/myproduct',
                priority: 20,
                unitPriceOriginal: 10.2,
                unitPriceWithoutVAT: 8,
                discountedAmount: 0,
                discountedPercentage: 0,
                publishedAt: '2020-05-20T15:24:20Z',
                customField1: '',
                customField2: '',
                customField2: ''
            }
        ]
    }
});

 

 

Congratulations!
You’ve reached the end of the tutorial.

  

Do you have questions?
Don’t forget, our Connectif specialists are here to help you. To contact them, just open a Support ticket by clicking the blue “Help” button on your dashboard.


Keep learning!

To make the most of your Connectif account, we recommend reading these articles next:

Esse artigo foi útil?
Usuários que acharam isso útil: 0 de 0