Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function prettyText(x){
- return x.replaceAll('+', ' ')
- .replaceAll('%2C', ',')
- .replaceAll('%C5%A0', '\u0160') //Š
- .replaceAll('%C5%A1', '\u0161') //š
- .replaceAll('%C4%8D', '\u010D') //č
- .replaceAll('%C4%8C', '\u010C') //Č
- .replaceAll('%C4%87', '\u0107') //ć
- .replaceAll('%C4%86', '\u0106') //Ć
- .replaceAll('%C7%84', '\u01C4') //DŽ
- .replaceAll('%C7%86', '\u01C6') //dž
- .replaceAll('%C4%91', '\u0111') //đ
- .replaceAll('%C4%90', '\u0110') //Đ
- .replaceAll('%C5%BE', '\u017E') //ž
- .replaceAll('%C5%BD', '\u017D');//Ž
- }
- function extractPrice(x){
- var pattern = '(\"total\"):((\d*\.?\d*)+)';
- const found = x.match(pattern);
- var newNumber = found[2];
- var p = newNumber.match(/[\d\.]+/);
- return p[0];
- }
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- event: 'purchase', // name of the event. In this case, it always must be purchase
- ecommerce: {
- currency: '{CURRENCY}',
- value: '{TOTAL}', // order total (price of total reservations
- transaction_id: '{RESV}', // transaction id
- coupon: '{PROMOCODE}', // if coupon was applied to the reservation, include it here
- items: [{ // an array with all accommodation units
- item_name: prettyText('{ROOMNAME}'), // insert an actual accommodation unit name
- item_id: '{ROOMID}', // insert an actual accommodation ID
- price: extractPrice('{MULTIROOM}'), // insert an actual product price. Number or a string. Don't include currency code
- item_category: prettyText('{HOTELNAME}'), // insert an actual accommodation unit's top-level category
- item_category2: prettyText('{RATENAME}'), // insert rate category
- quantity: '1', // product quantity, hardcoded value
- arrival_date: '{CHECKIN}', // insert check-in date
- departure_date: '{CHECKOUT}', // insert check-out date
- booked_nights: '{NIGHTS}', // insert total number of nights
- number_of_adults: '{ADULTS}', // insert total number of adults
- number_of_children: '{CHD}', // insert total number of children
- }]
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement