Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make downloads work when Google Analytics is blocked #29

Merged
merged 1 commit into from Jul 3, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -136,8 +136,7 @@ $(function(){
getStarted = $(".get-started"),
getStartedBack = $(".back", getStarted);

// Trigger after a click and its tracking event have finished
download.on('trackedClick', function(e) {
download.on('click', function(e) {
getStarted.show();
});
getStartedBack.click(function(e) {
@@ -156,36 +155,25 @@ $(function(){
});
})

// Downloads page tracking
// This function handles analytics tracking for certain
// download links.
function trackDownload(selector, name) {
$(selector).click(function() {
var downloadElements = $(selector);
downloadElements.click(function() {
var el = $(this)
var version = el.data("version");
if (version) {
var label = name + "-" + version;
} else {
var label = name;
}
function triggerTrackedClick() {
el.trigger('trackedClick');
}
if (window._gaq) {
_gaq.push(
["_set", "hitCallback", triggerTrackedClick],
["_trackEvent", "download", "click", label],
["_set", "hitCallback", null]
);
} else {
// Trigger tracked click immediately if analytics not loaded
triggerTrackedClick();
}
// Stop download for now because it would prevent tracking
return false;
});
// Resume normal click behavior after tracking has happened.
$(selector).on('trackedClick', function() {
location.href = $(this).attr('href');
_gaq.push(["_trackEvent", "download", "click", label]);
return true;
})
// Target downloads at an iframe so they don't unload this
// page. Unloading the page can interrupt Google Analytics
// and mess up our statistics.
downloadElements.attr('target', 'download-iframe');
}
trackDownload(".downloadActivatorLink", "activator");
trackDownload(".downloadStandaloneLink", "standalone");
@@ -162,4 +162,7 @@ <h3>What's next?</h3>
</ul>
</div>
</div>

<!-- Downloads are targeted at this iframe -->
<iframe name="download-iframe" style="display:none" src="data:,">
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.