How do I manually add Audiences add to cart tracking for BigCommerce?

If you have installed the Instant pixel for BigCommerce and are not receiving added to cart events from Audiences, please manually add tracking directly to your website.

  1. Proceed to the BigCommerce dashboard, and click on Storefront in the sidebar
  2. Click on Script Manager
  3. Click on Create a script in the top right
  4. Select these settings for the script.
    Script name: Instant Audiences Add to Cart
    Placement: Header
    Location: All pages
    Script category: Essential

    Script type: Script
  5. Copy and paste the following code into the "Script contents" text box. 
<script>
    (function () {
        const originalOpen = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function () {
            try {
                this._interceptedUrl = arguments[1].toString();
            } catch (err) {
                console.error("Error setting intercepted URL");
            }
            return originalOpen.apply(this, arguments);
        };

        const originalSend = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype.send = function (body) {
            try {
                const urlToCheck = this._interceptedUrl;
                if (
                    urlToCheck &&
                    (urlToCheck.includes("remote/v1/cart/add") || urlToCheck.includes("remote/v1/cart/update"))
                ) {
                    window.InstantJS.track("ITEM_ADDED_TO_CART");
                }
            } catch (err) {
                console.error("Error adding event listener for handling interception");
            }
            return originalSend.apply(this, arguments);
        };
    })();
</script>
Click on Save.