Explorar o código

fix: GA outbound link tracking

Fixes external links opening both in current tab and new tab when `google_analytics` enabled.

Fix #1511
George Cushen %!s(int64=5) %!d(string=hai) anos
pai
achega
1f6beec9f7
Modificáronse 3 ficheiros con 12 adicións e 7 borrados
  1. 2 3
      README.md
  2. 5 3
      layouts/partials/marketing/google_analytics.html
  3. 5 1
      scripts/view_demo.sh

+ 2 - 3
README.md

@@ -4,14 +4,13 @@
 
 ### The Page Builder to Easily Create Professional Websites :pencil2: :newspaper: :rocket:
 
-**Create a free website with Academic using Markdown, Jupyter, or RStudio. Choose a beautiful color theme and build anything with the Page Builder - over 40 _widgets_, _themes_, and _language packs_ included!**
+**Create a free website with Academic using Markdown, Jupyter, or RStudio. Choose a beautiful color theme and build anything with the Page Builder - over 50 _widgets_, _themes_, and _language packs_ included!**
 
 [Check out the latest **demo**](https://academic-demo.netlify.com/) of what you'll get in less than 10 minutes, or [view the **showcase**](https://sourcethemes.com/academic/#expo) of personal, project, and business sites.
 
 - 👉 [**Get Started**](https://sourcethemes.com/academic/docs/install/)
 - 📚 [View the **documentation**](https://sourcethemes.com/academic/docs/)
-- 💬 [**Ask a question** on the forum](https://discourse.gohugo.io)
-- 👥 [Chat with the **community**](https://spectrum.chat/academic)
+- 💬 [Chat with the **Academic community**](https://spectrum.chat/academic) or [**Hugo community**](https://discourse.gohugo.io)
 - 🐦 Twitter: [@source_themes](https://twitter.com/source_themes) [@GeorgeCushen](https://twitter.com/GeorgeCushen) [#MadeWithAcademic](https://twitter.com/search?q=%23MadeWithAcademic&src=typd)
 - 💡 [Request a **feature** or report a **bug**](https://github.com/gcushen/hugo-academic/issues)
 - ⬆️ **Updating?** View the [Update Guide](https://sourcethemes.com/academic/docs/update/) and [Release Notes](https://sourcethemes.com/academic/updates/)

+ 5 - 3
layouts/partials/marketing/google_analytics.html

@@ -12,13 +12,15 @@
       dataLayer.push(arguments);
   }
 
-  function trackOutboundLink(url) {
+  function trackOutboundLink(url, target) {
     gtag('event', 'click', {
          'event_category': 'outbound',
          'event_label': url,
          'transport_type': 'beacon',
          'event_callback': function () {
-           document.location = url;
+           if (target !== '_blank') {
+             document.location = url;
+           }
          }
     });
     console.debug("Outbound link clicked: " + url);
@@ -28,7 +30,7 @@
     if ((event.target.tagName !== 'A') || (event.target.host === window.location.host)) {
       return;
     }
-    trackOutboundLink(event.target);  // Send GA event.
+    trackOutboundLink(event.target, event.target.getAttribute('target'));  // Send GA event.
   }
 
   gtag('js', new Date());

+ 5 - 1
scripts/view_demo.sh

@@ -2,4 +2,8 @@
 
 # View the demo site on any local devices by binding the local IP on port 1315.
 # Run this script from the root Academic dir.
-HUGO_THEME=academic hugo --source exampleSite --themesDir ../../ --i18n-warnings --bind=0.0.0.0 -p 1315 --baseURL=http://0.0.0.0:1315 server
+HUGO_THEME=academic hugo \
+--source exampleSite --themesDir ../../ \
+--bind=0.0.0.0 -p 1315 --baseURL=http://0.0.0.0:1315 \
+--i18n-warnings --minify -e "development" \
+server