Skip to main content

šŸ’² Track your e-commerce sales with tracked links

From your campaigns, you can create tracked links and share them with the KOLs of your choice. Several useful metrics can then be retrieved:

  • Number of clicks

  • Sources of clicks

    • Geographic (Country/City)

    • Social networks

You can now track sales on your e-commerce site from these links generated in the application. Shopify and PrestaShop are supported natively. For other CMSs or custom sites, contact your Kolsquare representative or our support team.

Shopify

First step

  1. Go to your Shopify admin

  2. Go to the "Themes" tab of your online store from the left menu, or go directly to this link: https://admin.shopify.com/store/kolshopp/themes
    ​
    ​

  3. On the ā€œThemesā€ page, find your current theme and click its three-dot menu, then on "Edit code"
    ​
    ​

  4. Look for the "theme.liquid" file. You will find it more easily thanks to the search bar at the top left, then click on it (the file will open on the right panel)
    ​
    ​

  5. In this file, scroll to the bottom and paste the following code (Be careful not to delete the existing code):

    WARNING: Paste the code just before the </body> and </html> tags as in the following screenshot

    <script>
    if (window) {const urlParams = new URLSearchParams(window?.location?.search);
    const sales_token = urlParams.get('ts');
    if (sales_token) {window.localStorage.setItem('kolsquare', JSON.stringify({ sales_token }));}}
    </script>
  6. Save your changes

Second step

  1. Go to your Shopify admin

  2. Search for "Pixels" in the search bar and click on "Pixels" in the search results
    ​
    ​

    Capture d’écran 2024-10-14 aĢ€ 17.11.37.png
  3. Once in the "Pixels" menu (Customer Events), click on "Add custom pixel"
    ​
    ​

    Capture d’écran 2024-10-14 aĢ€ 17.11.52.png
  4. Name the custom pixel ā€œKolsquareā€ to make it easier to find.
    ​

    Capture d’écran 2024-10-14 aĢ€ 17.12.13.png

  5. In the Customer Privacy section, expand the ā€œPermissionā€ and ā€œData saleā€ sections, then select ā€œNot requiredā€ for the first one, and "Data collected does not qualify as data sale" for the second one.
    ​

  6. In the "Code" section, delete the existing content and paste the following code :
    ​

    function getCoupons(checkout) {
    const allDiscountCodes = checkout.discountApplications.map((discount) => {
    if (discount.type === 'DISCOUNT_CODE') {
    return discount.title;
    }
    });

    return allDiscountCodes.join(", ");
    }

    analytics.subscribe('checkout_completed', (event) => {
    const { sales_token } = JSON.parse(window.localStorage.getItem('kolsquare'));

    if (!sales_token) return null;

    const checkoutTracking = async data => {
    if (!sales_token) return null;
    const response = await
    fetch(`https://api.kolsquare.com/influence/tracking_links/sales/${sales_token}`, {
    method: 'POST',
    body: JSON.stringify({ tracking_link_sale: {
    order_id: event.data.checkout.order?.id,
    total_price: event.data.checkout.totalPrice.amount,
    currency: event.data.checkout.totalPrice.currencyCode,
    items_count: event.data.checkout.lineItems.length,
    created_at: event.timestamp,
    discount_code: getCoupons(event.data.checkout),
    store_framework: 'shopify_pixel'
    }}),
    headers: {
    'Content-type': 'application/json',
    'Access-Control-Allow-Origin': '*',
    },
    })
    return response;
    }

    checkoutTracking(event).then(() =>
    window.localStorage.removeItem('kolsquare'));
    });
    Capture d’écran 2024-10-14 aĢ€ 17.14.00.png
  7. Click ā€œSaveā€ at the top of the page and confirm if prompted.
    ​

  8. Click "Connect" to activate the pixel.
    ​

  9. The pixel is installed!

From now on, when a person places an order from a tracked link generated from Kolsquare, the sales information will be visible in the "Reporting" tab of your campaign.

Prestashop

  1. Go to your Prestashop admin

  2. Got to "Modules" > "Module Manager"
    ​
    ​

    Capture d’écran 2023-10-20 aĢ€ 11.13.03.png
  3. Once on the page, click on "Upload a module" at the top right of the page
    ​
    ​

    Capture d’écran 2023-10-20 aĢ€ 11.13.21.png
  4. Capture d’écran 2023-10-20 aĢ€ 11.13.29.png
  5. The module is installed!
    ​

    Capture d’écran 2023-10-20 aĢ€ 11.15.48.png

From now on, when a person places an order from a tracked link generated from Kolsquare, the sales information will be visible in the "Reporting" tab of your campaign.

Other e-shop and custom e-shop

We will be able to track sales only by sharing tracking links generated in Kolsquare.

campaigns -> tracking links

To let Kolsquare link your campaign with your sales, you need to add two code snippets to your codebase.

To do so, paste the code below so that it runs on the first page load. It must be loaded on every page.

const urlParams = new URLSearchParams(window.location.search);

const sales_token = urlParams.get('ts');

if (sales_token) {
window.localStorage.setItem('kolsquare', JSON.stringify({ sales_token }));
}

Then add the code below to your checkout page. The function must run when the order is submitted.

const kolsquare_tracking_sales = async () => {
const { sales_token } = JSON.parse(window.localStorage.getItem('kolsquare'));
const data = {
order_id: // put your order_id,
order_number: // put your order_number,
total_price: // put your total_price,
currency: // put your currency,
items_count: // put your items_count,
created_at: // put your created_at,
discount_code: // put your discount_code,
}

if (!sales_token) return null;

return await fetch(`https://api.kolsquare.com/influence/tracking_links/sales/${sales_token}`, {
method: 'POST',
body: JSON.stringify({ tracking_link_sale: data }),
headers: {
'Content-type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
'Cache-Control': 'no-cache',
})
}

kolsquare_tracking_sales().then(() => window.localStorage.removeItem('kolsquare'));

The code is written as an example. You can modify it as you wish. The only parts you must not change are the data object and the retrieval URL.

Once your setup is done, we will collect the data and add it to your campaign reporting šŸŽ‰

Data imported into the application

Sales data is synchronized twice a day to update your reports

  • Number of sales

  • Revenue

  • Average order value

  • Number of articles

  • Average number of articles per sale

  • ROI (Revenue - Invested budget)

  • ROAS (Revenue / Invested budget)

  • Conversion rate (Number of sales / Number of clicks)

Did this answer your question?