Skip to content

Commit

Permalink
fix link behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ave authored Sep 18, 2023
1 parent ce3b98c commit cf72668
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions builders/html/assets/js/src/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ $(function(){
}, 750);
// track outbound links
$("a").click(function(){
var url = $(this).attr("href");
if (!url || url.indexOf("#") === 0)
let href = $(this).attr("href");

// ignore if no href or no length
if(!href || !href.length) return;

try {
// ignore if same hostname
if(window.location.hostname == new URL(href).hostname) return;
} catch(e){
// ignore invalid url
return;
if (url.indexOf("http") === -1){
document.location = url; // ignore local urls
} else {
try {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': url,
'transport_type': 'beacon',
'event_callback': function(){document.location = url;}
});
} catch(e){
document.location = url;
}
}

// only track outgoing links
try {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': href,
'transport_type': 'beacon'
});
} catch(e){}
});
});

Expand Down

0 comments on commit cf72668

Please sign in to comment.