Tracking Document Downloads on County Websites
The county has an account with Google Analytics and it appears someone registered several websites for possible data collection:
However, the only entry that is 'turned on' is the one for www.hernandocounty.us (UA-12552598-7):
Analytics does not, however, collect information on document downloads. This can be done, but it requires some JavaScript code to send the information to Analytics.
The first thing to note is that someone added this JavaScript to the hernandocounty.us website pages' <HEAD> section at some point:
<!-- Google Universal Analytics -->
<script type="text/javascript">
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-12552598-7', 'auto');
ga('require', 'displayfeatures');
//TFS 21771, Enhanced Link Attribution, https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-link-attribution
ga('require', 'linkid');
ga('set', 'dimension1', 'Home, ID:1');
ga('set', 'dimension2', '2021');
ga('send', 'pageview');
</script>
<!-- End Google Universal Analytics -->
The above code 'turns on' data collection for the site and gives us access to the Google analytics JavaScript library: analytics.js. This allows us to use the ga() function to send event data to Analytics. One way to do that looks like this:
<a href="/home/showpublisheddocument?id=6068" target="_blank" onclick="ga('send',{hitType: 'event', eventCategory: 'PDF', eventAction: 'download', eventLabel: 'SSRPUpdates'});">
Add the onclick event to your <a> (anchor) tag and use the ga() function to send an event to analytics. (As with anything in software, this is not the only way to do this.)
ga( 'send',
{
hitType: 'event',
eventCatetory: 'PDF',
eventAction: 'download',
eventLabel: 'unique_name_here'
}
);
In this case I gave the document the name 'SSRPUpdates' - the document in question is titled 'Septic System Remediation Plan Updates'. With this code in place we can now see the following information in Analytics:
The above is the Realtime view - from the side menu in Analytics, you select Realtime/Events. You can drill down by clicking PDF to see all PDF type events:
You can also drill down to see all 'download' Event Actions and all of the data for your particular Event Label.
For historical data, select Behavior/Events, then select 'Overview', 'Top Events', 'Pages', and 'Events Flow' from that menu. Below is from the 'Top Events' selection after drilling down to SSRPUpdates:
**** NOTE: it can take 18 to 24 hours before you see the event data in the historical views. So don't look at the realtime data and expect to see anything immediately in the historical.