Use JavaScript Code To Pass Order Data

You can customize the JavaScript code sample to collect order data from your site using Bronto Order Service.

About this task

Order Service is the back-end service Bronto uses to automatically pass order data from your site into your Bronto account. To collect order data using this method, you will need to construct a JavaScript snippet, embed code on your site, and configure order settings in Bronto.

The Order Capture Script on the Commerce Settings page is a JavaScript code example. You can take this example, replace the placeholders in the code with data from your site, and then add your customized snippet to any page where order data is captured.

Note: If you already use Legacy Conversion Tracking you will need to work with Bronto to fully move from Legacy Conversion Tracking to this process or a JSON implementation. See Migrate From Legacy Conversion Tracking for more information.

There are a few important things to understand:

  1. If you are a Cart Recovery customer, you should use JSON Object integration to pass order data from your site to Bronto. The JSON and JavaScript code implementations are separate and should not be used together.
  2. JavaScript has browser and configuration dependencies; we cannot guarantee the accuracy of order data when it is sent by this method. Typically 90% of orders will be captured. If you're concerned about orders being "lost", we suggest using Bronto's REST API or Data Loader to pass the order data to Bronto in addition to this process.
  3. In order for Bronto to be able to collect data with this script you must also add the Script Manager code to your site. The script must be modified so that it passes in order data from your site.
  4. The only required values are emailAddress and grandTotal. If you have included line item data then quantity and totalPrice are also required. You should delete any values you do not want to pass to Bronto.
  5. This method can only be used to collect order data; it cannot collect cart data.

To implement:

Procedure

  1. Go to Settings > Integrations > Script Manager.
  2. Copy the code in the black box.
    1. Paste the copied code into the code for your site.

      The code should be added to each page on your site.

  3. Go to the Settings > Platform Settings > Commerce and copy the script in the black Order Capture box.
    Remove any order fields you do not want to collect and send to Bronto.
    Update the JavaScript code to properly collect the order data you do want to pass from your site. The values on the right should be replaced with variables from your site. Here is an example snippet. Your snippet may look different:
    <script type="text/javascript">
      bronto('order:send', {
      "customerOrderId": <?= $order_data['customerOrderId'] ?>,
      "emailAddress": <?= $order_data['emailAddresss'] ?>,
      "lineItems": [{
        "sku": <?= $order_data['sku1']; ?>,
        "totalPrice": <?= $order_data['totalPrice'] ?>,
        "quantity": <?= $order_data['quantity'] ?>,
        "unitPrice": <?= $order_data['unitPrice'] ?>,
        "salePrice": <?= $order_data['salePrice'] ?>,
        "name": <?= $order_data['name'] ?>,
      }],
      "shippingDate": <?= $order_data['shippingDate'] ?>, 
      "grandTotal": <?= $order_data['grandTotal'] ?>,
      "currency": <?= $order_data['currency'] ?>
      }
    );
    </script>
  4. Add your modified JavaScript code to any page on your site where order data is captured.

    This script currently does not capture cart data, so you only need to add it to order pages.

  5. In Bronto, configure your order settings.
  6. Test that the order data is being captured correctly:
    1. After you have completed the previous steps, place a test order on your site.
    2. In Bronto, navigate to Commerce > Orders.
    3. Click Show Advanced Options.
    4. Use the Order Date fields to search for orders from the current day.
    5. Find your test order in the list and compare the order details in Bronto to the order details on your site.

      We recommend exporting your order data from both Bronto and your commerce platform and running a comparison. Roughly 90% of the data from your site should be represented in your Bronto export file.

    6. If the order is missing in Bronto or the order details do not match, make sure your JavaScript snippet is constructed properly and both the snippet and the Web Information Manager code are included in your site code appropriately. Make any necessary adjustments and test again.