diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-22 09:36:36 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-22 09:36:36 +0200 |
| commit | aaff840fc8c4129e489121bf63b8c012847cf9ec (patch) | |
| tree | b7aff592ae7967bc4308e24af7d61d6d48ec26c3 | |
| parent | 4a7afa81b055336ca99683755c40d9185a9d0a4e (diff) | |
| download | gohugo-theme-ed-aaff840fc8c4129e489121bf63b8c012847cf9ec.tar.gz | |
Improve code style
| -rw-r--r-- | assets/js/ga.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/assets/js/ga.js b/assets/js/ga.js index afa7662..c69867f 100644 --- a/assets/js/ga.js +++ b/assets/js/ga.js @@ -28,21 +28,21 @@ function gtag() { /** * Function that tracks a click on an outbound link in Analytics. * - * This function takes a valid URL string as an argument and target argument, - * and uses that URL string as the event label. + * This function takes a valid URL string as an argument, optional + * 'isBlank' argument, and uses that URL string as the event label. * * Setting the transport method to 'beacon' lets the hit be sent using * navigator.sendBeacon() in browser that support it. The navigator.sendBeacon() * method asynchronously sends an HTTP POST request containing a small amount of * data to a web server. */ -function trackOutboundLink(url, target) { +function trackOutboundLink(url, isBlank = false) { gtag('event', 'click', { 'event_label': url, 'event_category': 'outbound', 'transport_type': 'beacon', - 'event_callback': function () { - if (target !== '_blank') { + 'event_callback': () => { + if (!isBlank) { document.location = url; } } @@ -71,7 +71,7 @@ function onClickCallback(event) { // Send GA event. trackOutboundLink( event.target, - event.target.getAttribute('target') + event.target.getAttribute('target') !== '_blank' ); } |
