SynXis: Manual or One-click Setup

Use this setup if you'd rather connect your booking data to ShopMy yourself, or if a one-click integration layer runs your SynXis bookings and sends a purchase event to Google Tag Manager.

Prerequisites:

  • Your booking flow must send a purchase event to Google Tag Manager.
  • If your website uses a Content-Security-Policy, make sure it allows *.shopmy.us.

Step One: Add click tracking to your website

Add this script to every page of your website. Either place it just before the closing </body> tag, or add it through Google Tag Manager as a Custom HTML tag that fires on every page view. Replace [domain] with your website's root domain, without www (for example yourhotel.com).

<script
  async
  src="https://static.shopmy.us/Affiliates/sms_aff_clicktrack.js?domain=[domain]&expires=30"
></script>

Step Two: Add the booking confirmation script

  1. In Google Tag Manager, create a new tag titled "ShopMy Booking Confirmation"
  2. Set the Tag Type to Custom HTML
  3. Paste the code below, then replace each {{PLACEHOLDER - ...}} with the GTM variable that holds that value:
    1. transaction_id - the unique identifier for the order (eg. 123456)
    2. value - the total before taxes and shipping (eg: 89.99)
    3. currency - the ISO 4217 currency code (eg: "USD")
    4. coupon - the optional discount code used at checkout (eg: 20PERCENTOFF)
    5. startDate - the arrival date of the booking
  4. Set the tag to trigger on your purchase event
  5. Press Save
<script>
(function() {
  var purchase = {
    transaction_id: '{{PLACEHOLDER - ORDER ID GTM VARIABLE}}',
    value: '{{PLACEHOLDER - ORDER AMOUNT GTM VARIABLE}}',
    currency: '{{PLACEHOLDER - CURRENCY GTM VARIABLE}}',
    coupon: '{{PLACEHOLDER - PROMO CODE GTM VARIABLE}}',
    startDate: '{{PLACEHOLDER - ARRIVAL DATE GTM VARIABLE}}'
  };

  var orderId = String(purchase.transaction_id || '');
  var orderAmount = Number(purchase.value);
  var currency = String(purchase.currency || 'USD').toUpperCase();

  if (!orderId || !isFinite(orderAmount) || orderAmount <= 0) {
    console.warn('ShopMy: purchase is missing an order id or amount.');
    return;
  }

  var cookies = {};
  var cookiesList = document.cookie.split(';');
  for (var j = 0; j < cookiesList.length; j++) {
    if (cookiesList[j]) {
      cookies[(cookiesList[j].split('=')[0] || '').trim()] = (cookiesList[j].split('=')[1] || '').trim();
    }
  }

  var clickId = cookies.sms_click_id;
  if (!clickId) {
    try { clickId = sessionStorage.getItem('sms_click_id'); } catch (_e) { /* blocked */ } // eslint-disable-line no-unused-vars
  }

  var payload = {
    orderAmount: orderAmount,
    orderId: orderId,
    currency: currency,
    page_url: window.location.href
  };
  if (clickId) payload.clickId = clickId;
  if (purchase.coupon) payload.code = purchase.coupon;

  var arrivalDate = toIsoDate(purchase.startDate);
  if (arrivalDate) payload.returnWindowClosesAt = arrivalDate;

  fetch('https://api.shopmy.us/api/order_confirmation', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(payload)
  })
    .then(function(response) {
      if (!response.ok) throw new Error('Invalid order request sent');
      return response.json();
    })
    .then(function() {
      var now = new Date();
      document.cookie = 'sms_click_id=;expires=' + now.toUTCString() + ';path=/;';
      document.cookie = 'sms_click_time=;expires=' + now.toUTCString() + ';path=/;';
      document.cookie = 'sms_code=;expires=' + now.toUTCString() + ';path=/;';
      try { sessionStorage.removeItem('sms_click_id'); } catch (_e) { /* blocked */ } // eslint-disable-line no-unused-vars
    })
    .catch(function(error) {
      console.warn('ShopMy: order confirmation failed.', error);
    });

  function toIsoDate(raw) {
    if (!raw) return null;
    var str = String(raw);
    if (/^\d{4}-\d{2}-\d{2}/.test(str)) return str.slice(0, 10);
    var mdy = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
    if (mdy) return mdy[3] + '-' + ('0' + mdy[1]).slice(-2) + '-' + ('0' + mdy[2]).slice(-2);
    return null;
  }
})();
</script>

Step Three: Publish changes

Whenever you change your Google Tag Manager tags, press Publish at the top-right of the page in each container you changed.