Skip to content

Commit

Permalink
Exempt Safari and WebKit-based DDG browsers from using serverTiming t…
Browse files Browse the repository at this point in the history
…o measure load success (#206)
  • Loading branch information
englehardt authored May 15, 2024
1 parent 59e5013 commit e067375
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions adClickFlow/ad/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
7 changes: 4 additions & 3 deletions adClickFlow/ad/track.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
8 changes: 6 additions & 2 deletions adClickFlow/shared/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e067375

Please sign in to comment.