(function () { // ✅ FIX 1: Initialize digitalData IMMEDIATELY — before Launch reads it if (!window.digitalData) { window.digitalData = { page: {}, component: [], search: {}, user: { consent: {} }, event: {} }; } function init() { if (document.readyState === 'complete') { onDomReady(); } else { window.addEventListener('load', onDomReady); } // Declare components var componentList = {}; const components = [] function shouldExcludeComponent(el, name) { if (el.closest('#onetrust-consent-sdk')) return true if (el.classList.contains('phs-location-link')) return true return false } function detectComponents() { document.querySelectorAll('a, button').forEach((el) => { const ariaLabel = el.getAttribute('aria-label') || '' const textContent = el.textContent.trim().replace(/\s+/g, ' ') let name = ariaLabel || textContent || 'Unnamed' name = name.replace(/^\d+\s+/, '').trim() if (shouldExcludeComponent(el, name)) return let type = 'Unknown' if (el.classList.contains('phw-btn')) { type = 'Button' } else if (el.classList.contains('phw-link')) { type = 'Link' } else if (el.classList.contains('phw-header-logo')) { type = 'Image' } else { type = el.tagName.toLowerCase() === 'button' ? 'Button' : 'Link' } const inHeader = el.closest('header') const inFooter = el.closest('footer') let prefix = '' if (inHeader) prefix = 'header_' else if (inFooter) prefix = 'footer_' let componentId = prefix + name componentId = componentId.replace(/^\d+\s+/, '').trim() if (componentList[componentId]) return componentList[componentId] = { type: type, name: name, linkId: el.getAttribute('href') || 'None', } components.push({ componentInfo: { componentId: componentId, name: name, type: type, }, }) }) if (components.length > 0) { window.digitalData.component = components } } function tryDetectComponentsWithDelay(retries = 5, delay = 1000) { if (retries <= 0) return if (document.readyState !== 'complete') { return setTimeout(() => tryDetectComponentsWithDelay(retries - 1, delay), delay) } if (!window.digitalData.component || window.digitalData.component.length === 0) { detectComponents() if (!window.digitalData.component || window.digitalData.component.length === 0) { setTimeout(() => tryDetectComponentsWithDelay(retries - 1, delay), delay) } } } // ✅ FIX 2: Safety net — fix tracker ready state after page load beacons function fixTrackerReadyState() { try { var tracker = Object.values(window.s_c_il).find(function(o) { return o._c === 's_c'; }); if (tracker && typeof tracker.isReadyToTrack === 'function' && !tracker.isReadyToTrack()) { var originalIsReady = tracker.isReadyToTrack.bind(tracker); tracker.isReadyToTrack = function() { if (!originalIsReady() && tracker.visitor && tracker.visitor.getMarketingCloudVisitorID()) { return true; } return originalIsReady(); }; console.log('[Tracking] ✅ Tracker ready state fix applied'); } } catch (e) { console.warn('[Tracking] Could not apply tracker fix:', e); } } function onDomReady() { setTimeout(() => { detectPageDetails(); tryDetectComponentsWithDelay(); analyticsTrack('pageview'); }, 3000); setTimeout(() => { checkCookies(); }, 5000); // ✅ FIX 2: Apply tracker fix after page load beacons have fired setTimeout(fixTrackerReadyState, 6000); const checkPathForJobSearch = window.location.pathname; if (checkPathForJobSearch.includes('/search-results')) { setTimeout(() => { try { performJobSearchAnalytics(); } catch (error) { console.warn('[Tracking] Error in performJobSearchAnalytics:', error); } analyticsTrack('jobsearch'); }, 4000); } if (checkPathForJobSearch.includes('/job/')) { setTimeout(() => { try { performJobViewAnalytics(); } catch (error) { console.warn('[Tracking] Error in performJobViewAnalytics:', error); } analyticsTrack('jobViewed'); }, 4000); } document.addEventListener('click', function (e) { let id = e.target.getAttribute('id'); let className = e.target.getAttribute('class'); if (className && className.includes('save-preference-btn-handler') || (id !== undefined && (id === 'onetrust-accept-btn-handler' || id === 'onetrust-reject-all-handler' || id === 'accept-recommended-btn-handler'))) { checkCookies(); } const checkPathForJobSearch = window.location.pathname; if (checkPathForJobSearch.includes('/search-results')) { setTimeout(() => { try { performJobSearchAnalytics(); } catch (error) { console.warn('[Tracking] Error in performJobSearchAnalytics:', error); } analyticsTrack('jobsearch'); }, 4000); } const clickedEl = e.target.closest('a, button') if (!clickedEl) return const ariaLabel = clickedEl.getAttribute('aria-label') || '' const textContent = clickedEl.textContent.trim().replace(/\s+/g, ' ') const name = (ariaLabel || textContent || 'Unnamed').replace(/^\d+\s+/, '').trim() const inHeader = clickedEl.closest('header') const inFooter = clickedEl.closest('footer') let prefix = '' if (inHeader) prefix = 'header_' else if (inFooter) prefix = 'footer_' const componentId = prefix + name const componentExists = Array.isArray(window.digitalData.component) && window.digitalData.component.some(c => c.componentInfo.componentId === componentId) if (componentExists) { publishEvent(componentId, 'Click') if (textContent != undefined && textContent != null) { const viewProfileTexts = [ 'View Profile', 'Profil anzeigen', 'Profiel weergeven', 'Visualiser le profil', 'Ver perfil', 'Consulte el perfil', 'Visualizza profilo', 'Вижте профила', 'Zobraziť profil', 'Ogled profila', 'ดูโปรไฟล์' ]; // ✅ setTimeout safety net for viewprofile if (viewProfileTexts.includes(textContent.trim())) { setTimeout(() => { analyticsTrack('viewprofile'); }, 500); } } const phAtId = clickedEl.getAttribute('data-ph-at-id'); // ✅ setTimeout safety net for applynow if (phAtId && phAtId === 'apply-link') { setTimeout(() => { analyticsTrack('applynow'); }, 500); } } else { console.log('[Tracking] Click on unknown component:', name) } }); } function publishEvent(cmpID, action) { var eventName = 'None'; var componentName = 'None'; var componentType = 'None'; var editedLinkId = ' None'; for (var index = 0; index < window.digitalData.component.length; ++index) { var componentInfo = window.digitalData.component[index].componentInfo; if (cmpID === componentInfo.componentId && action === 'Click') { eventName = 'Click on clickable ' + componentInfo.type; componentName = componentInfo.name; componentType = componentInfo.type; } } var componentDetails = componentList[cmpID]; if (componentDetails) { componentType = componentDetails.type; componentName = componentDetails.name; editedLinkId = componentDetails.linkId; } var event = { eventInfo: { componentId: cmpID, type: action, timeStamp: new Date(), eventName: eventName, componentType: componentType, componentName: componentName, linkId: editedLinkId, }, }; var componentClick = new CustomEvent('componentClick', { detail: { componentClick: { componentId: cmpID, type: action, timeStamp: new Date(), eventName: eventName, componentType: componentType, componentName: componentName, linkId: editedLinkId, }, }, }); pushData(event, componentClick); } function pushData(data, componentClick) { if (typeof window.digitalData != 'undefined') { if (data.hasOwnProperty('componentInfo')) { window.digitalData.component = window.digitalData.component.filter( function (item) { return ( data.componentInfo.componentId !== item.componentInfo.componentId ); } ); window.digitalData.component.push(data); } else { window.digitalData.event = data; if (typeof componentClick != 'undefined') { document.body.dispatchEvent(componentClick); } } } } function analyticsTrack(msg, retries = 20, delay = 500) { const w = window; if ( w && w._satellite && w._satellite.track && typeof w._satellite.track === 'function' ) { w._satellite.track(msg); console.log('[Tracking] ✅ _satellite.track fired:', msg); } else if (retries > 0) { console.log('[Tracking] ⏳ _satellite not ready, retrying...', msg, 'Retries left:', retries); setTimeout(() => { analyticsTrack(msg, retries - 1, delay); }, delay); } else { console.warn('[Tracking] ❌ _satellite not available. Failed to track:', msg); } } function checkCookies() { var consentGroup = window.OnetrustActiveGroups; if (consentGroup) { consentGroup = consentGroup.split(',').filter(element => element != ''); const consent = { any: consentGroup.length === 1 ? false : true, constentGroups: window.OnetrustActiveGroups, functional: consentGroup.includes('3') ? true : false, gdprEnabled: true, isAny: consentGroup.length === 1 ? false : true, isFunctionalAllowed: consentGroup.includes('3') ? true : false, isNone: consentGroup.length === 1 ? true : false, isPerformanceAllowed: consentGroup.includes('2') ? true : false, isSocialAllowed: false, isTargetingAllowed: consentGroup.includes('4') ? true : false, none: consentGroup.length === 1 ? true : false, performance: consentGroup.includes('2') ? true : false, social: false, targeting: consentGroup.includes('4') ? true : false } window.digitalData.user = { consent: consent }; } } function performJobSearchAnalytics() { const element = document.querySelector('[data-ph-at-id="search-page-top-job-count"]'); const searchRecord = element?.textContent || null; const sliderElement = document.querySelector('.noUi-handle-lower'); const location_search_radius = sliderElement?.getAttribute('aria-valuetext') || ''; const frequencySelect = document.querySelector('#frequency'); const frequencySelectedValue = frequencySelect?.value || null; let filter = ""; const searchTermInput = document.querySelector('#typehead'); const searchTermInputValue = searchTermInput?.value || ''; const locationInput = document.querySelector('#locationInput_0'); const inputValue = locationInput?.value || null; if (inputValue != undefined && inputValue != '' && inputValue != null) { filter = appendFilterPart(filter, "Location", inputValue); } if (location_search_radius != undefined && location_search_radius != '') { filter = appendFilterPart(filter, "Location Search Radius", location_search_radius); } const areaofExpertiseFilter = getSelectedValues('[data-ph-at-facetkey="facet-category"]', 'data-ph-at-text'); if (areaofExpertiseFilter != undefined && areaofExpertiseFilter != '') { filter = appendFilterPart(filter, "Area of Expertise", areaofExpertiseFilter); } const countryListFilter = getSelectedValues('[data-ph-at-facetkey="facet-country"]', 'data-ph-at-text'); if (countryListFilter != undefined && countryListFilter != '') { filter = appendFilterPart(filter, "Country", countryListFilter); } const stateListFilter = getSelectedValues('[data-ph-at-facetkey="facet-state"]', 'data-ph-at-text'); if (stateListFilter != undefined && stateListFilter != '') { filter = appendFilterPart(filter, "State", stateListFilter); } const cityListFilter = getSelectedValues('[data-ph-at-facetkey="facet-city"]', 'data-ph-at-text'); if (cityListFilter != undefined && cityListFilter != '') { filter = appendFilterPart(filter, "City", cityListFilter); } const remoteJobListFilter = getSelectedValues('[data-ph-at-facetkey="facet-remote"]', 'data-ph-at-text'); if (remoteJobListFilter != undefined && remoteJobListFilter != '') { filter = appendFilterPart(filter, "Remote Job", remoteJobListFilter); } const employmentTypeListFilter = getSelectedValues('[data-ph-at-facetkey="facet-employmentType"]', 'data-ph-at-text'); if (employmentTypeListFilter != undefined && employmentTypeListFilter != '') { filter = appendFilterPart(filter, "Employment Type", employmentTypeListFilter); } const jobLevelListFilter = getSelectedValues('[data-ph-at-facetkey="facet-jobLevel"]', 'data-ph-at-text'); if (jobLevelListFilter != undefined && jobLevelListFilter != '') { filter = appendFilterPart(filter, "Job Level", jobLevelListFilter); } const jobTypeListFilter = getSelectedValues('[data-ph-at-facetkey="facet-type"]', 'data-ph-at-text'); if (jobTypeListFilter != undefined && jobTypeListFilter != '') { filter = appendFilterPart(filter, "Job Type", jobTypeListFilter); } const unitFilter = getSelectedValues('[data-ph-at-facetkey="facet-unit"]', 'data-ph-at-text'); if (unitFilter != undefined && unitFilter != '') { filter = appendFilterPart(filter, "Unit", unitFilter); } var inputElement = document.getElementById('subSearchTextbox'); var inputValuekeywords = inputElement?.value || ''; if (inputValuekeywords != undefined && inputValuekeywords != '') { filter = appendFilterPart(filter, "keywords", inputValuekeywords); } const nameSearch = "Job Search"; const searchTerm = searchTermInputValue; const typedSearchTerm = searchTermInputValue; const numberOfResults = searchRecord; const searchObj = createSearchObject(nameSearch, searchTerm, typedSearchTerm, filter, numberOfResults, frequencySelectedValue); window.digitalData.search = searchObj; function getSelectedValues(selector, attribute) { const elements = document.querySelectorAll(selector); const selectedValues = []; elements.forEach(element => { if (element.checked) { const value = element.getAttribute(attribute); selectedValues.push(value); } }); return selectedValues.join(','); } function createSearchObject(name, searchTerm, typedSearchTerm, filter, numberOfResults, frequencySelectedValue) { const searchObject = { name: name, searchTerm: searchTerm, typedSearchTerm: typedSearchTerm, numberOfResults: numberOfResults, filter: filter }; if (frequencySelectedValue) { if (frequencySelectedValue == 1) { searchObject.alert = 1; } else if (frequencySelectedValue == 2) { searchObject.alert = 7; } else if (frequencySelectedValue == 3) { searchObject.alert = 30; } } return searchObject; } function appendFilterPart(filter, key, value) { if (value !== undefined && value !== '') { if (filter) { filter += '|'; } filter += `${key}:${value}`; } return filter; } } function performJobViewAnalytics() { var locationElement = document.querySelector('span.location'); var locationText = locationElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (locationText.includes("Location")) { locationText = locationText.replace("Location: ", ""); } var jobLevelElement = document.querySelector('span.jobLevel'); var jobLevelText = jobLevelElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (jobLevelText.includes("undefined")) { jobLevelText = jobLevelText.replace("undefined: ", ""); } var typeElement = document.querySelector('span.type'); var typeText = typeElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (typeText.includes("widget")) { typeText = typeText.replace("widget: ", ""); } var jobIdElement = document.querySelector('span.jobId'); var jobIdText = jobIdElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (jobIdText.includes("Job ID")) { jobIdText = jobIdText.replace("Job ID: ", ""); } var employmentTypeElement = document.querySelector('span.employmentType'); var employmentTypeText = employmentTypeElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (employmentTypeText.includes("undefined")) { employmentTypeText = employmentTypeText.replace("undefined: ", ""); } var jobTitleElement = document.querySelector('h1.job-title'); var jobTitleText = jobTitleElement?.textContent?.trim() || ''; var remoteElement = document.querySelector('span.remote'); var remoteText = remoteElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (remoteText.includes("Remote")) { remoteText = remoteText.replace("Remote: ", ""); } var categoryElement = document.querySelector('span.category'); var categoryText = categoryElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (categoryText.includes("Category")) { categoryText = categoryText.replace("Category: ", ""); } var unitElement = document.querySelector('span.unit'); var unitText = unitElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (unitText.includes("undefined")) { unitText = unitText.replace("undefined: ", ""); } var employingEntityElement = document.querySelector('span.employingEntity'); var employingEntityText = employingEntityElement?.querySelector('span.phw-g-text-default-light')?.textContent?.trim() || ''; if (employingEntityText.includes("undefined")) { employingEntityText = employingEntityText.replace("undefined: ", ""); } const searchObj = createSearchViewObject(locationText, jobLevelText, categoryText, unitText, employingEntityText, typeText, remoteText, employmentTypeText, jobIdText, jobTitleText); window.digitalData.search = searchObj; function createSearchViewObject(locationText, jobLevelText, categoryText, unitText, employingEntityText, typeText, remoteText, employmentTypeText, jobIdText, jobTitleText) { const searchObject = { location: locationText, jobLevel: jobLevelText, areaOfExp: categoryText, unit: unitText, entity: employingEntityText, jobType: typeText, remoteJob: remoteText, emplType: employmentTypeText, jobId: jobIdText, selectedItem: jobTitleText }; return searchObject; } } function detectPageDetails() { if (!window.digitalData || window.digitalData.length === 0) { const currentPath = location.pathname.split('/').filter(Boolean); let pageName; const pathWithoutLocale = currentPath.slice(2); if (pathWithoutLocale.length === 0) { pageName = 'Home'; } else { const lastSegment = pathWithoutLocale[pathWithoutLocale.length - 1]; const cleaned = lastSegment.replace(/[\r\n_-]+/gm, ' '); pageName = /\d/.test(cleaned) && pathWithoutLocale.length > 1 ? pathWithoutLocale[pathWithoutLocale.length - 2].replace(/[\r\n_-]+/gm, ' ') : cleaned; } if (pathWithoutLocale[0] === 'job') { pageName = 'jobDetails'; } const selectedCountryElement = document.querySelector('.selected-country'); let countryValue = selectedCountryElement?.textContent?.trim() || 'unknown'; if (countryValue === 'United States') { countryValue = 'US'; } const langPart = currentPath[1]?.toLowerCase() || ''; const regionPart = currentPath[0]?.toLowerCase() || ''; let language = 'unknown'; if (langPart === 'en') { language = regionPart === 'us' ? 'en_US' : 'en_GB'; } else if (langPart) { language = `${langPart}_${langPart.toUpperCase()}`; } const isInternalUser = document.getElementsByClassName('empLogoutLink').length > 0; const normalizedCountry = countryValue.replace(/\s+/g, ''); const isHome = pathWithoutLocale.length === 0; const pageId = `/${normalizedCountry}/${isHome ? 'home' : pathWithoutLocale.join('/')}`; window.digitalData = { page: { pageInfo: { pageId: pageId, pageName: pageName, fullURL: window.location.href, URL: window.location.href.replace(window.location.search, ''), referringURL: document.referrer, language: language, country: countryValue, siteSection: countryValue, isInternal: isInternalUser, }, attributes: { organisationalEntity: 'azcom (careers)', }, }, }; } } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();