Making the CartStack APIs Conditional

Description: You may have a login page which can be accessed from the home page and the checkout page. Making the APIs conditional will allow you to use the Capture Only code when a customer is simply logging in, and use the Tracking code when a customer is in the checkout process.

Code Example

The code below is for an example site. In this example, when the cart page leads to the login page, the URL is: https://www.tradetools.com/login?R=Checkout.aspx

When the visitor visits the login page directly, the URL is: https://www.tradetools.com/login

Make sure to update the setSiteID in the snippet. You can find your unique Site ID in the CartStack admin, under the  Code tab.

<script src="https://api.cartstack.com/js/cs.js" type="text/javascript"></script>
<script type="text/javascript">
    var _cartstack = _cartstack || [];
    _cartstack.push(['setSiteID', '*******']); /* required */
    
    if (window.location.href.indexOf("checkout") > -1)
        _cartstack.push(['setAPI', 'tracking']); /* required */
    else
        _cartstack.push(['setAPI', 'capture']); /* required */
    _cartstack.push(['setCartTotal', '']); /* optional */
</script>
		
In "window.location.href.indexOf("checkout"), "checkout" must be part of the URL. 
Did this answer your question? Thanks for the feedback. Click the "Contact Us" button to the right if you need further help. There was a problem submitting your feedback. Please try again later.