openknowledge-archive / dpr-api

DEPRECATED - Data Package Registry API and Frontend
http://frictionlessdata.io/
MIT License
7 stars 6 forks source link

Track downloads of data package resources #403

Closed anuveyatsu closed 7 years ago

anuveyatsu commented 7 years ago

Download button pushes to google analytics (with irakli) => we are at least recording even if not showing

Acceptance Criteria

Tasks

Analysis

Useful link: https://support.google.com/analytics/answer/1136920?hl=en

Script to be included on Showcase page:

<script>
/**
* Function that tracks a click on an outbound link in Analytics.
* This function takes a valid URL string as an 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.
*/
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>

Then we need to have onclick event on download links that trigger trackOutboundLink function:

<a href="{{ datapackageUrl | replace("/datapackage.json","")}}/{{ resource.path }}" onclick="trackOutboundLink('this.href')">
   <i class="fa fa-download" aria-hidden="true"></i>
</a>
anuveyatsu commented 7 years ago

FIXED but we need to double check with GA dashboard later.