Populating Transaction Data via URL Parameters

Last modified October 5, 2018

This article applies to Contextual Commerce. (Looking for Classic Commerce documentation?)

If you use the Store Builder Library (SBL) on your website, you can optionally populate certain pieces of transaction data via URL parameters - i.e., values passed as part of the URL customers use to access the store page - by adding JavaScript code to parse the URL and apply the parameter values to SBL functions. This is possible for any transaction data that can be applied via SBL functions, including:

  • Products
  • Customer First Name
  • Customer Last Name
  • Coupon Code

 The following example would be implemented near the bottom of your page, just after the closing </body> tag.


The following example is provided "as is" and is intended for illustration purposes. You may need to adjust the code provided in the example to meet your needs or work with your specific implementation.
Example of populating transaction data via URL parameters
    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 {
  return query_string;
        $( document ).ready(function() {

			var s = {};
            if(QueryString.product) {
                s = {
                    'products' : [
            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);

The above example allows you to pass, via the URL, information that will be added to the cart session.  If you specify the product in the URL, be sure to use the product path / product ID (see the example here) rather than the product's Display name.

For example: 

Example URL


In this example, the store page on your website would have a URL ending in cart.html. The name of the page can be whatever you need. The above will add product ID 8675309 to the cart, apply coupon FALLSALE, and apply the customer's first name, last name and email address to the order.

If you only want to pass the product:

Example URL


If you only want to pass the product and the coupon code:

Example URL


If you pass in the customer name or email address, then currently, the first name, last name and email address must all  be passed in order for any of them to work.  For example:

Example URL