Populate Order Information with the URL

Use URL parameters to populate transaction information in your customer's order session.

Parameters are values that the SBL passes as part of the customer-facing URL. Add a JavaScript code to parse the URL and apply parameter values to SBL functions. Then, you can pass the following transaction data in the URL:

  • Products
  • Customer's first name
  • Customer's last name
  • Coupon code

For example, you can add similar code following the tag at the bottom of your page. Use URL parameters to add information to an existing cart session. If you specify the product in the URL, include the product path instead of the display name.

<script>
    var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = decodeURIComponent(pair[1]);
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(decodeURIComponent(pair[1]));
    }
  } 
  return query_string;
}();
</script>
    <script>
        $( document ).ready(function() {

            var s = {};
            
            if(QueryString.product) {
                s = {
                    'products' : [
                        {
                            'path':QueryString.product,
                            'quantity':1
                        }
                    ]
                }
            }
 
            if(QueryString.email && QueryString.fname && QueryString.lname) {
                s.paymentContact = {};
                s.paymentContact.email = QueryString.email;
                s.paymentContact.firstName = QueryString.fname;
                s.paymentContact.lastName = QueryString.lname;
            }
 
            if(QueryString.coupon) {
                s.coupon = QueryString.coupon;
            }
            
            if (s) fastspring.builder.push(s);
        });
    </script>

Example URLs

The following URLs format order-specific information following cart.html?. You can pass multiple pieces of information within one URL.

Pass the Product:

Following cart.html? pass product= and insert the product path or ID.

.../cart.html?product=8675309

Pass the Coupon Code:

Following cart.html? pass the ID or path of the product to which the coupon applies. Then, pass &coupon=' and insert the coupon code. FastSpring will apply the associated discount to the specified product.

.../cart.html?product=8675309&coupon=FALLSALE

Pass Customer Information:

To pass customer information, include the first name, last name, and email address following cart.html. The information will not pass if one of these fields is missing.

  • fname= Add the first name.
  • &lname= Add the last name.
  • &email= Add the email address.
.../cart.html?fname=Leeroy&lname=Jenkins&[email protected]

Pass All Information

The following example includes the product, coupon, and customer information from the examples above.

.../cart.html?product=8675309&coupon=FALLSALE&fname=Leeroy&lname=Jenkins&[email protected]

Did this page help you?