Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
[#524] GA improvements - Package ZIP now also sends a GA event.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Oct 20, 2016
1 parent 1fb31a1 commit 034f831
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ckanext/dgu/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,19 @@ def get_organization_from_resource(res_dict):
return None
return res.resource_group.package.get_organization()

def ga_download_tracking_package_zip(pkg, pkg_dict, publisher_name):
dataset_openness_score = \
(pkg_dict.get('qa') or {}).get('openness_score', '')
from ckanext.packagezip.helpers import packagezip_url
return ga_download_tracking(
dict(
url=packagezip_url(pkg),
format='Data Package ZIP',
archiver={'is_broken': False},
qa={'openness_score': dataset_openness_score}
),
pkg_dict, publisher_name)

def ga_download_tracking(resource, pkg_dict, publisher_name, action='download'):
'''Google Analytics event tracking for downloading a resource. (Universal
Analytics syntax)
Expand Down
4 changes: 2 additions & 2 deletions ckanext/dgu/theme/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2>Data Package</h2>
</p>
{% elif not h.packagezip_has_data(c.pkg) %}
<p style="margin-bottom: 20px;">
The <a href="{{h.packagezip_url(c.pkg)}}">Data Package Zip</a> is not recommended for this dataset
The <a href="{{h.packagezip_url(c.pkg)}}" onclick="{{h.ga_download_tracking_package_zip(c.pkg, c.pkg_dict, publisher_name)}}">Data Package Zip</a> is not recommended for this dataset
<a class="js-tooltip" data-toggle="tooltip" data-html='true' data-placement="right" title="The zip file may not contain data. This occurs if the source data is not available, there are problems encountered during archival, or the data is only accessible via an API." href="javascript:0" style="text-decoration:none;color:#000;">
<i class="icon-info-sign"></i>
</a>
Expand All @@ -149,7 +149,7 @@ <h2>Data Package</h2>
</div>
<div class="inner-row actions">
<div class="inner-cell">
<a href="{{h.packagezip_url(c.pkg)}}" class="dataset-resource-chevron" style="pointer-events:auto;">
<a href="{{h.packagezip_url(c.pkg)}}" class="dataset-resource-chevron" style="pointer-events:auto;" onclick="{{h.ga_download_tracking_package_zip(c.pkg, c.pkg_dict, publisher_name)}}">
<strong>
Download ZIP
</strong>
Expand Down

0 comments on commit 034f831

Please sign in to comment.