Skip to content
Permalink
Browse files

fix: GA outbound link tracking

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

Fix #1511
  • Loading branch information
gcushen committed Jan 26, 2020
1 parent 2f00bea commit 1f6beec9f713cd2f49137d0e931c0ad3dd78edc2
Showing with 12 additions and 7 deletions.
  1. +2 βˆ’3 README.md
  2. +5 βˆ’3 layouts/partials/marketing/google_analytics.html
  3. +5 βˆ’1 scripts/view_demo.sh
@@ -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/)
@@ -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());
@@ -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

0 comments on commit 1f6beec

Please sign in to comment.
You can’t perform that action at this time.