Add GA display of clicked outbound links

This commit is contained in:
Thomas Jensen 2018-07-07 21:45:12 +02:00
parent b51d90172e
commit f528e457d3
3 changed files with 24 additions and 12 deletions

View File

@ -58,8 +58,9 @@ There are many improvements big and small over front-cover, making *Fuse Core* a
because a myriad of problems are already handled by the folks at Bootstrap. because a myriad of problems are already handled by the folks at Bootstrap.
- [SASS](https://sass-lang.com/) styling instead of raw CSS - [SASS](https://sass-lang.com/) styling instead of raw CSS
- Up-to-date libraries, especially Font Awesome 5. - Up-to-date libraries, especially Font Awesome 5.
- Support for [Google Analytics ](https://analytics.google.com/analytics/web/), including some legal details - Support for [Google Analytics ](https://analytics.google.com/analytics/web/), including tracking of outbound links
such as IP anonymization and cookie consent popup (all optional). (so you'll know which social media profiles people clicked on), and some legal details such as IP anonymization
and cookie consent popup (all optional).
- Search engine control via configurable meta tags - Search engine control via configurable meta tags
- Responsive sticky footer - Responsive sticky footer

17
_includes/analytics.html Normal file
View File

@ -0,0 +1,17 @@
{% if site.ga %}
<!-- Google Analytics -->{% comment %} should be the first script in the HEAD section {% endcomment %}
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '{{ site.ga.account }}', 'auto');{% if site.ga.anonymizeip %}
ga('set', 'anonymizeIp', true);{% endif %}
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script>
var trackOutboundLink = function(targetName, targetUrl) {
ga('send', 'event', 'outbound', 'click', targetName, {
'transport': 'beacon',
'hitCallback': function(){document.location = targetUrl;}
});
}
</script>{% endif %}

View File

@ -14,15 +14,7 @@ permalink: /
<meta name="HandheldFriendly" content="true" /> <meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if site.url %}<link rel="canonical" href="{{ site.url }}">{% endif %} {% if site.url %}<link rel="canonical" href="{{ site.url }}">{% endif %}
{% include analytics.html %}
{% if site.ga %}<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.ga.account }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.ga.account }}'{% if site.ga.anonymizeip %}, {'anonymize_ip': true}{% endif %});
</script>{% endif %}
<!-- favicons --> <!-- favicons -->
<link rel="apple-touch-icon" sizes="180x180" href="{{ site.baseurl }}/images/favicons/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="{{ site.baseurl }}/images/favicons/apple-touch-icon.png">
@ -90,7 +82,9 @@ permalink: /
<div class="row justify-content-center links pt-1 pt-sm-2"> <div class="row justify-content-center links pt-1 pt-sm-2">
{% for hash in site.links %}{% for linkInfo in hash %}{% if linkInfo[1].show %} {% for hash in site.links %}{% for linkInfo in hash %}{% if linkInfo[1].show %}
<div class="col-xs-12 col-sm-2 col-lg-1 px-3 px-sm-0 mt-2 mt-sm-3 text-sm-center"><a <div class="col-xs-12 col-sm-2 col-lg-1 px-3 px-sm-0 mt-2 mt-sm-3 text-sm-center"><a
href="{{ linkInfo[1].href }}"><i class="{{ linkInfo[1].icon }} fa-fw"></i> href="{{ linkInfo[1].href }}"{% if site.ga %}
onclick="trackOutboundLink('{{ linkInfo[1].name }}', '{{ linkInfo[1].href }}'); return false;"
{% endif %}><i class="{{ linkInfo[1].icon }} fa-fw"></i>
<span class="d-inline d-sm-none">{{ linkInfo[1].name }}</span></a></div> <span class="d-inline d-sm-none">{{ linkInfo[1].name }}</span></a></div>
{% endif %}{% endfor %}{% endfor %} {% endif %}{% endfor %}{% endfor %}
</div> </div>