Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save campaignupgrade/7a7b96ec8c91c32c234d988513754d20 to your computer and use it in GitHub Desktop.
Save campaignupgrade/7a7b96ec8c91c32c234d988513754d20 to your computer and use it in GitHub Desktop.
Send donatoin_KEY and amount to Google Analytics (GA) from the thank you page that follows a successful donation in Salsa.
<script>
// Script to retrieve donation_KEY and amount from the URL and send
// them to Google Anaylitics eCommerce.
// See https://salsasupport.zendesk.com/entries/98811317
var m = /donation_KEY=(\d+)/.exec(window.location.search);
var donation_KEY = (m != null) ? donation_KEY = m[1] : 'Unknown';
var m = /amount=(\d+)/.exec(window.location.search);
var amount = parseFloat(window.location.href.split("amount=")[1].split('&'));
(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', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', UA-23578262-1, 'auto', {
'allowLinker': true
});
ga('require', 'linker');
ga('linker:autoLink', [www.truth-out.org]);
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': donation_KEY,
'affiliation': 'Donation',
'revenue': amount,
'shipping': '',
'tax': '',
'currency': 'USD' // local currency code.
});
ga('ecommerce:send');
ga('send', 'pageview');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment