diff --git a/adClickFlow/ad/convert.js b/adClickFlow/ad/convert.js index 64471df..86e7f4b 100644 --- a/adClickFlow/ad/convert.js +++ b/adClickFlow/ad/convert.js @@ -2,7 +2,7 @@ console.log('Ad conversion'); const pixelUrl = new URL('./ping.gif', document.currentScript.src); -function fireResource (status) { +function fireConvertPingStatus (status) { window.dispatchEvent(new CustomEvent('resourceLoad', { detail: { url: pixelUrl.href, @@ -16,9 +16,9 @@ img.src = pixelUrl; img.style.display = 'none'; img.onload = () => { console.log('Ad conversion complete'); - fireResource('loaded'); + fireConvertPingStatus('loaded'); }; img.onerror = () => { - fireResource('blocked'); + fireConvertPingStatus('blocked'); }; document.body.appendChild(img); diff --git a/adClickFlow/ad/track.js b/adClickFlow/ad/track.js index efc0cc9..f73b8e8 100644 --- a/adClickFlow/ad/track.js +++ b/adClickFlow/ad/track.js @@ -1,7 +1,8 @@ console.log('Tracking'); const trackingImgUrl = new URL('./ping.gif', document.currentScript.src); -function fireResource (status) { + +function fireTrackingPingStatus (status) { window.dispatchEvent(new CustomEvent('resourceLoad', { detail: { url: trackingImgUrl.href, @@ -14,9 +15,9 @@ const trackingImg = document.createElement('img'); trackingImg.src = trackingImgUrl; trackingImg.style.display = 'none'; trackingImg.onload = () => { - fireResource('loaded'); + fireTrackingPingStatus('loaded'); }; trackingImg.onerror = () => { - fireResource('blocked'); + fireTrackingPingStatus('blocked'); }; document.body.appendChild(trackingImg); diff --git a/adClickFlow/shared/utils.mjs b/adClickFlow/shared/utils.mjs index 635ee18..7b4c2f8 100644 --- a/adClickFlow/shared/utils.mjs +++ b/adClickFlow/shared/utils.mjs @@ -14,6 +14,10 @@ function getAdHostname (hostname) { return isLocalTest ? 'ad-company.example' : 'ad-company.site'; } +function isSafariOrDDG() { + return navigator.vendor && navigator.vendor.indexOf('Apple') > -1; +} + function getAdUrl (id, hostname) { // Build Ad Redirection URL const adHostname = getAdHostname(hostname); @@ -341,8 +345,8 @@ export class FinishObserver { this.observer = new PerformanceObserver((list) => { const entries = list.getEntries(); entries.map((entry) => { - // Safari doesn't support serverTiming nor does it fire events for blocked loads either. - if (entry.serverTiming) { + // WebKit doesn't seem to support serverTiming for cross-origin loads + if (entry.serverTiming && !isSafariOrDDG()) { if (entry.serverTiming.length === 0) { this.setResourceStatus(entry.name, 'blocked'); } else {