OpL Insights

Docs Platform guides

BigCommerce

Add OpL Insights to a BigCommerce store with Script Manager.

BigCommerce runs your store on its own servers, so there is nothing to install: you add three scripts in Script Manager. They record visits on every page, the checkout steps and each order.

1. Create the site

In OpL Insights, go to Sites > Add site, choose BigCommerce and enter your store's address. Copy the site ID: it replaces SITE_ID below.

2. The script for every page

In BigCommerce, go to Storefront > Script Manager > Create a Script. Name: OpL Insights. Location: Head. Pages: All pages. Category: Analytics. Type: Script. Paste:

<script>
window.OPL_INSIGHTS = {
  m: 'https://app.oplinsights.com/', s: SITE_ID,
  cart: '/api/storefront/carts', cartFormat: 'bigcommerce', cartRe: '/cart\\.php|/api/storefront/carts|/remote/v1/cart',
  uid: '{{#if customer}}{{customer.id}}{{/if}}',
  ctx: {
    route: ({ 'default': 'common/home', 'product': 'product/product', 'category': 'product/category', 'search': 'product/search', 'cart': 'checkout/cart', 'checkout': 'checkout/checkout', 'order_confirmation': 'checkout/success', '404': 'error/not_found' })['{{page_type}}'] || 'page/{{page_type}}',
    cur: '{{currency_selector.active_currency_code}}'{{#if product}},
    product: { sku: {{{json product.sku}}} || '{{product.id}}', name: {{{json product.title}}}, price: {{product.price.with_tax.value}}{{#unless product.price.with_tax}}{{product.price.without_tax.value}}{{/unless}} }{{/if}}
  }
};
(function () {
  var q = new URLSearchParams(location.search).get('search_query');
  if (q !== null) { window.OPL_INSIGHTS.ctx.search = q; }
})();
</script>
<script async src="https://app.oplinsights.com/plugins/OplReplay/javascripts/opl-insights.js"></script>

3. Checkout steps

Create a second script. Location: Footer. Pages: Checkout (Optimized One-Page Checkout). Category: Analytics.

<script>
(function () {
  var q = function (c) { (window._oplq = window._oplq || []).push(c); };
  var shipped = false, pay = '';
  q(['step', 'begin_checkout', '']);
  new MutationObserver(function () {
    if (!shipped && document.querySelector('.checkout-step--payment .checkout-view-content')) { shipped = true; q(['step', 'add_shipping_info', '']); }
  }).observe(document.body, { childList: true, subtree: true });
  document.addEventListener('change', function (e) {
    var t = e.target;
    if (t && t.name === 'paymentProviderRadio') {
      var l = ((document.querySelector('label[for="' + t.id + '"]') || {}).textContent || t.value || '').trim().slice(0, 100);
      if (l !== pay) { pay = l; q(['step', 'add_payment_info', l]); }
    }
  });
})();
</script>

4. Orders

Create a third script. Location: Footer. Pages: Order confirmation. Category: Analytics.

<script>
fetch('/api/storefront/order/{{checkout.order.id}}', { credentials: 'include' })
  .then(function (r) { return r.json(); })
  .then(function (o) {
    var li = (o.lineItems.physicalItems || []).concat(o.lineItems.digitalItems || []);
    (window._oplq = window._oplq || []).push(['order', {
      id: String(o.orderId), total: o.orderAmount, subtotal: o.baseAmount, tax: o.taxTotal,
      shipping: o.shippingCostTotal, discount: o.discountAmount,
      items: li.map(function (i) { return { sku: i.sku || String(i.productId), name: i.name, price: i.salePrice, qty: i.quantity }; })
    }]);
  });
</script>

5. Check it works

BigCommerce doesn't run Script Manager scripts in theme preview. Place a real test order on the live store, then check the visit, checkout steps and order in OpL Insights. Visitors who decline analytics cookies in BigCommerce's consent banner are not recorded.