Track conversion

This page describes how to use Streamshop sales conversion

Initialize

First, we need to import the sdk correctly

<script async src="https://assets.streamshop.com.br/sdk/liveshop-web-sdk-conversion.min.js"></script>

To be able to store the parameters to localStorage, we have the initialization method called: initialize
it carries 3 main parameters, namely: cartId, sectionId and quantityDays (this step is optional).

Usage example to initialize:

liveshopWebSDKTrackConversion.initialize method has the function of loading the initial conversion data, such as cartId and sectionId.

<script>
  liveshopWebSDKTrackConversion.initialize('cartIdExample', 'sectionIdExample', 1);
</script>
Method parameter name initializeTypeRequired
cartIdstringYes
sectionIdstringNo
quantityDaysnumberNo (by default quantityDays has 1 day as its value), parameter used to calculate data expiration in localStorage.

Usage Example

For the correct use of the SDK, some means are used to obtain cart data, namely: localStorage and queryParam.

By LocalStorage

It is necessary that the cart and session identifier data have the following names: liveshop_cart_id and liveshop_section_id.

LocalStorage property nameTypeDescriptionRequired
liveshop_cart_idstringThe liveshop_cart_id is used to identify each user's shopping cart, allowing the SDK to track items added and actions taken on the cart.No
liveshop_section_idstringThe liveshop_section_id is used to identify the user's current shopping session, helping the SDK maintain navigation context and interactions during that session.No

By QueryParam

It is necessary that the cart and session identifier data have the following names: liveshop_cart_id and liveshop_section_id.

QueryParam property nameTypeDescriptionRequired
liveshop_cart_idstringThe liveshop_cart_id is used to identify each user's shopping cart, allowing the SDK to track items added and actions taken on the cart.No
liveshop_section_idstringThe liveshop_section_id is used to identify the user's current shopping session, helping the SDK maintain navigation context and interactions during that session.No

Calling the liveshopWebSDKTrackConversion.trackConversion method and how to send the data:

<script>
  liveshopWebSDKTrackConversion.trackConversion(
    'storeSlugExample',
    9.90,
    [
      {
        id: 'productId',
        name: 'Test product',
        quantity: 4,
        price: 25
      }
    ]
  ); 
</script>

Conversion Types

ConversionData interface

interface ConversionData {
  conversionValue: number;
  products: ProductConversion[] | undefined;
  cartId: string | undefined;
  sectionId: string | undefined;
  slug: string;
}

ProductConversion interface

interface ProductConversion {
  id: string | undefined;
  name: string | undefined;
  quantity: number | undefined;
  price: number | undefined;
}