BigCommerce Integration Setup

Step One: Integrate Click Tracking

Add the one-line script below to your main site template just before the closing </body> tag. This script must be on every page, as it takes the tracking URL and turns it into a first-party cookie.

<script defer src="https://static.shopmy.us/Affiliates/sms_aff_clicktrack.js"></script>

Step Two: Integrate Order Tracking

Add the following script to the BigCommerce Script Manager. The script placement should be "Footer" and the script location should be "Order confirmation". Replace placeholders (marked with ***) with actual checkout system values.

<script>  
  const cookies = document.cookie.split(';').reduce(
    (res, cookie) => ({
      ...res,
      [(cookie.split('=')[0] || '').trim()]: (cookie.split('=')[1] || '').trim()
    }),
    {}
  );
  const { sms_click_id, sms_click_time } = cookies;
  var code = '***THE CODE USED AT CHECKOUT***';
  function getOrderDetail() {
    return fetch('/api/storefront/order/{{ checkout.order.id }}', {
      credentials: 'include'
    }).then(function(response) {
      return response.json();
    });
  }
  getOrderDetail().then(data => {
    if (data.coupons?.length > 0) {
      code = data.coupons[0].code;
    }
    fetch('https://api.shopmy.us/api/order_confirmation', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        orderAmount: data.baseAmount,
        orderId: '{{ checkout.order.id }}',
        clickId: sms_click_id,
        currency: 'USD',
        is_returning_customer: false,
        page_url: window.location.href,
        code
      })
    })
      .then(r => {
        if (!r.ok) throw new Error('Invalid order request sent');
        return r.json();
      })
      .then(() => {
        const now = new Date();
        document.cookie = `sms_click_id=;expires=${now.toUTCString()};path=/;`;
        document.cookie = `sms_click_time=;expires=${now.toUTCString()};path=/;`;
      })
      .catch(error => {
        console.error('ShopMy error:', error);
      });
  });
</script>

Step Three: Handle Order Cancellations

Configure a POST request to be sent to the following endpoint whenever an order is cancelled. This is crucial for maintaining accurate tracking and reporting in our system.

📘

This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security.

fetch(`https://api.shopmy.us/api/Affiliates/cancel`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
  },
  body: JSON.stringify({
    order_id: '123456',
  })
})

Step Four: Handle Order Updates

Configure a POST request to be sent to the following endpoint whenever an order is updated. We define an order update as whenever a order has new total amount, or currency change. This is crucial for maintaining accurate tracking and reporting in our system.

📘

This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security

fetch(`https://api.shopmy.us/api/Affiliates/update`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
  },
  body: JSON.stringify({
    order_id: '123456',
    currency: 'USD',
    new_order_amount: '1234.56'
  })
})

Step Five: Request Testing

Contact your Brand Success Manager to place a test order and test the integration end-to-end. We will communicate with you any test order IDs we place so they can be cancelled after the integration is verified.


📘

By adding our integration code to your site, you are agreeing to the terms of the ShopMy affiliate network. Please review these terms here.