1. Login to your Square Online admin account (https://squareup.com/login)


2. Select Online from the left pane


3. Select Settings then General


4. At the bottom of the General Settings page is the Tracking area. Select Edit to begin adding your ICS scripts


5. Add the first script to the Custom Tracking - Cart Page area:

<script>
    function setICSCookies(){
      var ICSRegex = /invite=([a-zA-Z0-9%]+)/;
      var queryString = location.search;
      var ICSQueryString = queryString.match(ICSRegex);
      if (ICSQueryString) {
        document.cookie = 'invite=' + ICSQueryString[ICSQueryString.length - 1] +'; Max-Age=30000000;' + 'Path=/';  
      }
    }
    setICSCookies();
</script>

6. Add the second script to the Custom Tracking - Receipt Page area:

<script>
    var ICSCookie = null;
    var ICSCookieObject = null;

 function getICSCookie() {
    var allCookies = document.cookie;
    var regex = /invite=([a-zA-Z0-9%]+)/;
    var matches = allCookies.match(regex);
    if (matches) {
      ICSCookie =  matches[0];
    } 
  };
getICSCookie();
ICSCookieObject = Object.fromEntries(new URLSearchParams(ICSCookie));

(function(i,s,r,publicKey,campaignId,a,m,frame,bodyChild){
    i['IceCreamSocialObject'] = r;
    i[r] = i[r] || function(){( i[r].q = i[r].q||[]).push(arguments)},   i[r].l = +new Date();
    a = s.createElement('script'), m = s.scripts[0];
    a.async = a.src = 'https://app.icecreamsocial.io/js/ics.js';
    m.parentNode.insertBefore(a,m);
    frame = s.createElement('iframe'), bodyChild = s.body.firstChild;
    frame.src = 'https://app.icecreamsocial.io/?campaignId='+campaignId+'&publicKey='+publicKey;
    frame.id='SocialIframe', frame.style.cssText = 'position:fixed;height:100%;width:100%;z-index:9999;border: 0';
    bodyChild.parentNode.insertBefore(frame,bodyChild);
})(window ,document ,'ics', 'YOURclientpublickey', 'YOURcampaignid');

ics('addTransaction', {
    locale: 'en-US',
    orderId: '{orderid}',
    email: '{email}',
    revenue: {subtotal},
    inviteCookie: ICSCookieObject.invite,
    name: '{name}',
    transactionId: '{txid}',
});
</script>
7. Edit the above script to replace YOURclientpublickey and YOURcampaignid with the Client Public Key and Campaign ID that are found within your Ice Cream Social admin.