(function () { window.dataLayer = window.dataLayer || []; /* |-------------------------------------------------------------------------- | Support Button |-------------------------------------------------------------------------- */ function initSupportButton() { const supportButton = document.querySelector('.supportBtnToggle'); const links = document.querySelector('.support .links'); if (!supportButton || !links) { return; } supportButton.addEventListener('click', function () { links.style.display = links.style.display === 'block' ? 'none' : 'block'; }); } /* |-------------------------------------------------------------------------- | Normalize Phone Number |-------------------------------------------------------------------------- */ function normalizePhone(value) { if (!value) { return ''; } return String(value) .replace('tel:', '') .replace(/[^\d]/g, ''); } /* |-------------------------------------------------------------------------- | Convert Saudi Number To Local Format |-------------------------------------------------------------------------- */ function toLocalSaudiNumber(value) { let number = normalizePhone(value); if (number.startsWith('00966')) { number = '0' + number.substring(5); } else if (number.startsWith('966')) { number = '0' + number.substring(3); } else if ( number.startsWith('5') && number.length === 9 ) { number = '0' + number; } return number; } /* |-------------------------------------------------------------------------- | Employee Phone Mapping |-------------------------------------------------------------------------- */ const employeePhones = { '0534723964': 'Rasha', '0534723817': 'Reem', '0506194536': 'Abu_Yasser', '0508464944': 'Hussain', '0530005259': 'Noura_AlHassan', '0532106525': 'Noura_AlHarthi', '0506429074': 'Waad', '0535779890': 'Haifa', '0553382815': 'Razan', '0555075507': 'Noura_Mohammed' }; /* |-------------------------------------------------------------------------- | Website Settings Numbers |-------------------------------------------------------------------------- */ const phones = { sales_line_1: toLocalSaudiNumber("0535779890 0555075507"), sales_line_2: toLocalSaudiNumber("0506429074 0503329509"), sales_line_3: toLocalSaudiNumber("0553382815 0530005259"), sales_line_4: toLocalSaudiNumber("0532106525"), main_phone: toLocalSaudiNumber("920010675") }; /* |-------------------------------------------------------------------------- | Find Phone Contact Source |-------------------------------------------------------------------------- */ function getPhoneSource(phoneNumber) { const normalized = toLocalSaudiNumber(phoneNumber); if (employeePhones[normalized]) { return employeePhones[normalized]; } for (const source in phones) { if ( phones[source] && phones[source] === normalized ) { return source; } } return 'other_phone'; } /* |-------------------------------------------------------------------------- | Find WhatsApp Contact Source |-------------------------------------------------------------------------- */ function getWhatsAppSource(whatsappUrl) { let whatsappNumber = ''; try { const url = new URL( whatsappUrl, window.location.origin ); /* |-------------------------------------------------------------------------- | wa.me/9665XXXXXXXX |-------------------------------------------------------------------------- */ if (url.hostname.includes('wa.me')) { whatsappNumber = url.pathname.replace(/[^\d]/g, ''); } /* |-------------------------------------------------------------------------- | api.whatsapp.com/send?phone=9665XXXXXXXX |-------------------------------------------------------------------------- */ else { whatsappNumber = url.searchParams.get('phone') || ''; } } catch (e) { whatsappNumber = String(whatsappUrl) .replace(/[^\d]/g, ''); } const normalized = toLocalSaudiNumber(whatsappNumber); if (employeePhones[normalized]) { return employeePhones[normalized]; } return 'other_whatsapp'; } /* |-------------------------------------------------------------------------- | Global Click Tracking |-------------------------------------------------------------------------- */ document.addEventListener( 'click', function (event) { const link = event.target.closest('a'); if (!link) { return; } const href = link.getAttribute('href') || ''; /* |-------------------------------------------------------------------------- | Phone Click |-------------------------------------------------------------------------- */ if (href.startsWith('tel:')) { let contactSource = link.getAttribute('data-track-contact'); if (!contactSource) { contactSource = getPhoneSource(href); } window.dataLayer.push({ event: 'phone_click', contact_source: contactSource, contact_type: 'phone', page_path: window.location.pathname, page_title: document.title }); console.log( 'GTM phone_click:', contactSource ); } /* |-------------------------------------------------------------------------- | WhatsApp Click |-------------------------------------------------------------------------- */ if ( href.includes('wa.me') || href.includes('api.whatsapp.com') || href.includes('whatsapp.com') ) { let contactSource = getWhatsAppSource(href); if (contactSource === 'other_whatsapp') { contactSource = link.getAttribute('data-track-contact') || 'other_whatsapp'; } window.dataLayer.push({ event: 'whatsapp_click', contact_source: contactSource, contact_type: 'whatsapp', page_path: window.location.pathname, page_title: document.title }); console.log( 'GTM whatsapp_click:', contactSource ); } }, true ); /* |-------------------------------------------------------------------------- | Initialize |-------------------------------------------------------------------------- */ if (document.readyState === 'loading') { document.addEventListener( 'DOMContentLoaded', initSupportButton ); } else { initSupportButton(); } })();
https://www.linkedin.com/company/setup/new/
https://www.google.com/business/
https://www.bayt.com/en/saudi-arabia/
https://www.naukrigulf.com/
https://www.gulftalent.com/
https://sa.indeed.com/
https://www.monster.com/
https://hrsd.gov.sa/
https://www.riyadhchamber.sa/
https://www.yellowpages.com.sa/