Squarespace

These instructions cover Squarespace 7.1. You will install the snippet site-wide with Code Injection, then record purchases with the order confirmation page injection point that Squarespace Commerce provides.

Plan requirement

Code Injection requires a Squarespace Business or Commerce plan: it is not available on Personal plans.

Install the snippet

Your snippet comes from Project Settings → Snippet in the A vs B dashboard:

HTML
<script>window.avsb=window.avsb||{};window.avsb.q=window.avsb.q||[];window.avsb.ready=window.avsb.ready||function(f){window.avsb.q.push(f)};window.avsb.on=window.avsb.on||function(n,f){var t=['on',n,f];window.avsb.q.push(t);return function(){t[0]=null}};window.avsb.consent=window.avsb.consent||{set:function(s){window.avsb.q.push(['consent.set',s])},get:function(){return{}}};window.avsb.track=window.avsb.track||{};['event','segment','purchase','cart'].forEach(function(m){window.avsb.track[m]=window.avsb.track[m]||function(a,b){window.avsb.q.push(['track.'+m,a,b])}});(function(){window.avsb._t0=Date.now();window.avsb._df=fetch('https://cdn.avsb.cloud/YOUR_SNIPPET_KEY/datafile.json').catch(function(){});var d=document,e=d.documentElement,s=d.currentScript,a=s&&s.getAttribute('data-avsb-timeout'),t=a==null?3000:+a;if(!(t>0)||window.avsb.version)return;e.style.opacity='0';e.style.pointerEvents='none';window.avsb._t=setTimeout(function(){e.style.removeProperty('opacity');e.style.removeProperty('pointer-events')},t)})();</script><script src="https://cdn.avsb.cloud/snippet.js?id=YOUR_SNIPPET_KEY" data-avsb="YOUR_SNIPPET_KEY" async></script>
HTML9 lines

The first tag is a stub that makes avsb.ready(...), avsb.on(...) and avsb.consent.set(...) calls safe before the bundle loads. Paste both tags into the Header field.

1

Open Code Injection

In your Squarespace dashboard, go to Settings → Advanced → Code Injection.

2

Paste into the Header box

Paste the snippet tag into the Header field. Squarespace injects this into the head of every page.

3

Save

Click Save. Then check Project Settings → Snippet in A vs B: the status turns green once the snippet has been detected.

Record purchases

Squarespace Commerce has a dedicated injection point for the order confirmation page, with tags that Squarespace replaces with the real order values.

1

Open the Order Confirmation Page injection

In the same Code Injection screen, scroll to the Order Confirmation Page field. This field only appears on Commerce plans.

2

Paste the purchase call

Paste the script below and save. Squarespace substitutes the bracketed tags when a buyer lands on the confirmation page.

HTML
<script>  window.addEventListener('load', function () {    if (window.avsb && window.avsb.track) {      window.avsb.track.purchase({        orderId: '{orderId}',        total: parseFloat('{orderGrandTotal}'),        currency: 'USD' // your store currency: ISO 4217      });    }  });</script>
HTML11 lines

The fields:

  • orderId: required. Orders are deduplicated by this ID (last write wins), so a buyer refreshing the confirmation page never double-counts.
  • total: required. The order total as a decimal. The {orderGrandTotal} tag is the order's grand total; {orderSubtotal} is also available if you prefer to exclude shipping and tax.
  • currency: optional. Squarespace does not provide a currency tag. Set it to your store currency yourself, or omit it and A vs B uses your project's configured currency instead.

See Tracking Revenue for the full avsb.track.purchase reference.

Tags only work in the Order Confirmation Page field

The bracketed order tags are replaced only inside the Order Confirmation Page injection field. They will not work in the Header or Footer fields.

Verify

Place a test order, then open Commerce → Orders in the A vs B dashboard. See the orders & attribution guide for how to read that page. Confirm the order arrived and was attributed to an exposure: the moment a visitor is counted in an experiment, usually when they see the part being tested.

Was this helpful?