@@ -31,6 +31,37 @@ const initOutboundDomains = () => {
3131    } 
3232  } 
3333
34+   function  extractUrlFromSrcdoc ( srcdoc )  { 
35+     if  ( ! srcdoc )  return  null ; 
36+ 
37+     // Look for URLs in the srcdoc content 
38+     // This is a basic implementation - may need refinement based on actual Cal.com usage 
39+     const  urlRegex  =  / h t t p s ? : \/ \/ [ ^ \s " ' < > ] + / g; 
40+     const  matches  =  srcdoc . match ( urlRegex ) ; 
41+ 
42+     if  ( matches  &&  matches . length  >  0 )  { 
43+       // Return the first URL found - this might need to be more sophisticated 
44+       // depending on how Cal.com structures their srcdoc content 
45+       return  matches [ 0 ] ; 
46+     } 
47+ 
48+     return  null ; 
49+   } 
50+ 
51+   function  updateSrcdocWithTracking ( element ,  originalUrl ,  newUrl )  { 
52+     if  ( ! element . srcdoc )  return  false ; 
53+ 
54+     try  { 
55+       // Replace the original URL with the new URL in the srcdoc content 
56+       const  updatedSrcdoc  =  element . srcdoc . replace ( originalUrl ,  newUrl ) ; 
57+       element . srcdoc  =  updatedSrcdoc ; 
58+       return  true ; 
59+     }  catch  ( e )  { 
60+       console . error ( 'Error updating srcdoc:' ,  e ) ; 
61+       return  false ; 
62+     } 
63+   } 
64+ 
3465  function  addOutboundTracking ( clickId )  { 
3566    // Handle both string and array configurations for outbound domains 
3667    const  outboundDomains  =  Array . isArray ( DOMAINS_CONFIG . outbound ) 
@@ -47,16 +78,19 @@ const initOutboundDomains = () => {
4778    const  existingCookie  =  clickId  ||  cookieManager . get ( DUB_ID_VAR ) ; 
4879    if  ( ! existingCookie )  return ; 
4980
50-     // Get all links and iframes 
51-     const  elements  =  document . querySelectorAll ( 'a[href], iframe[src]' ) ; 
81+     // Get all links and iframes (including those with srcdoc) 
82+     const  elements  =  document . querySelectorAll ( 
83+       'a[href], iframe[src], iframe[srcdoc]' , 
84+     ) ; 
5285    if  ( ! elements  ||  elements . length  ===  0 )  return ; 
5386
5487    elements . forEach ( ( element )  =>  { 
5588      // Skip already processed elements 
5689      if  ( outboundLinksUpdated . has ( element ) )  return ; 
5790
5891      try  { 
59-         const  urlString  =  element . href  ||  element . src ; 
92+         const  urlString  = 
93+           element . href  ||  element . src  ||  extractUrlFromSrcdoc ( element . srcdoc ) ; 
6094        if  ( ! urlString )  return ; 
6195
6296        // Check if the URL matches any of our outbound domains 
@@ -70,15 +104,29 @@ const initOutboundDomains = () => {
70104        // Only add the tracking parameter if it's not already present 
71105        if  ( ! url . searchParams . has ( DUB_ID_VAR ) )  { 
72106          url . searchParams . set ( DUB_ID_VAR ,  existingCookie ) ; 
107+           const  newUrlString  =  url . toString ( ) ; 
73108
74109          // Update the appropriate attribute based on element type 
75110          if  ( element . tagName . toLowerCase ( )  ===  'a' )  { 
76-             element . href  =  url . toString ( ) ; 
111+             element . href  =  newUrlString ; 
112+             outboundLinksUpdated . add ( element ) ; 
77113          }  else  if  ( element . tagName . toLowerCase ( )  ===  'iframe' )  { 
78-             element . src  =  url . toString ( ) ; 
114+             if  ( element . src )  { 
115+               // Standard iframe with src attribute 
116+               element . src  =  newUrlString ; 
117+               outboundLinksUpdated . add ( element ) ; 
118+             }  else  if  ( element . srcdoc )  { 
119+               // Iframe with srcdoc attribute (like Cal.com) 
120+               const  updated  =  updateSrcdocWithTracking ( 
121+                 element , 
122+                 urlString , 
123+                 newUrlString , 
124+               ) ; 
125+               if  ( updated )  { 
126+                 outboundLinksUpdated . add ( element ) ; 
127+               } 
128+             } 
79129          } 
80- 
81-           outboundLinksUpdated . add ( element ) ; 
82130        } 
83131      }  catch  ( e )  { 
84132        console . error ( 'Error processing element:' ,  e ) ; 
0 commit comments