Use this setup if guests book on a synxis.com address, such as be.synxis.com. Complete the SynXis prerequisites first.
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&splitcookies=1&decoratehosts=be.synxis.com"
></script>Step Two: Add click tracking to your booking engine
This tag saves the click on your booking engine, including clicks from creator links that open it directly.
- In Google Tag Manager, open the container connected to your SynXis booking engine
- Title the tag "ShopMy Click Tracking"
- Set the Tag Type to Custom HTML
- Set the HTML to the script below
- Set the Triggering field to fire on a "Page View" on "All Pages"
- Press Save
<script
async
src="https://static.shopmy.us/Affiliates/sms_aff_clicktrack.js?expires=30&splitcookies=1"
></script>Step Three: Add the booking confirmation script
- In the same container, create a new tag titled "ShopMy Booking Confirmation"
- Set the Tag Type to Custom HTML
- Paste the code below without editing it
- Set the tag to trigger on order confirmation
- Press Save
<script>
/*
Order confirmation pixel for hotels on the SynXis Booking Engine (SBE).
*/
(function() {
var POLL_INTERVAL_MS = 1000;
var POLL_TIMEOUT_MS = 30000;
var reported = false;
var requestInFlight = false;
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;
}
function reportOrderIfConfirmed() {
if (reported || requestInFlight) return;
var globalTracking = window._globalTracking || {};
var cartReservation = (globalTracking.Cart && globalTracking.Cart[0]) || {};
var confirmedReservation = (globalTracking.ConfirmedReservations && globalTracking.ConfirmedReservations[0]) || {};
var reservation = cartReservation.ConfirmNo ? cartReservation : confirmedReservation;
var hotelId = String(globalTracking.HOTEL_ID || (window.location.search.match(/[?&]hotel=([^&]+)/i) || [])[1] || '');
var orderAmount = globalTracking.TotalCost || reservation.TotalCost;
if (!hotelId || !reservation.ConfirmNo || !orderAmount) return;
var cookies = {};
var cookiesList = document.cookie.split(';');
for (var i = 0; i < cookiesList.length; i++) {
if (cookiesList[i]) {
cookies[(cookiesList[i].split('=')[0] || '').trim()] = (cookiesList[i].split('=')[1] || '').trim();
}
}
var clickId = cookies['sms_click_id_' + hotelId];
if (!clickId) {
try { clickId = sessionStorage.getItem('sms_click_id_' + hotelId); } catch (_e) { /* blocked */ } // eslint-disable-line no-unused-vars
}
var payload = {
orderAmount: orderAmount,
orderId: reservation.ConfirmNo,
currency: reservation.CurrCode || globalTracking.CurrCode || 'USD',
is_returning_customer: false,
page_url: window.location.href,
propertyId: hotelId,
returnWindowClosesAt: toIsoDate(reservation.ArrivalDt || globalTracking.ArrivalDt)
};
if (clickId) payload.clickId = clickId;
requestInFlight = true;
fetch('https://api.shopmy.us/api/order_confirmation', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(function(r) {
reported = true;
if (!r.ok) throw new Error('Invalid order request sent');
return r.json();
})
.then(function() {
var now = new Date();
document.cookie = 'sms_click_id_' + hotelId + '=;expires=' + now.toUTCString() + ';path=/;';
document.cookie = 'sms_click_time_' + hotelId + '=;expires=' + now.toUTCString() + ';path=/;';
try { sessionStorage.removeItem('sms_click_id_' + hotelId); } catch (_e) { /* blocked */ } // eslint-disable-line no-unused-vars
})
.catch(function(e) {
console.warn('ShopMy: order confirmation failed', e);
})
.then(function() {
requestInFlight = false;
});
}
try {
if (window.location.pathname.indexOf('/confirm') === -1) {
return;
}
reportOrderIfConfirmed();
if (!reported) {
var pollStartedAt = new Date().getTime();
var poll = setInterval(function() {
try {
if (new Date().getTime() - pollStartedAt >= POLL_TIMEOUT_MS) return clearInterval(poll);
reportOrderIfConfirmed();
if (reported) clearInterval(poll);
} catch (pollError) {
clearInterval(poll);
console.warn('We had an issue with the ShopMy order confirmation', pollError);
}
}, POLL_INTERVAL_MS);
}
} catch (error) {
console.warn('We had an issue with the ShopMy order confirmation', error);
}
})();
</script>Step Four: Publish changes
Whenever you change your Google Tag Manager tags, press Publish at the top-right of the page in each container you changed.
