From 239d01ee672df42c0ce78a06764e4cf8aa0bc368 Mon Sep 17 00:00:00 2001 From: Keith Mitchell Date: Mon, 1 Oct 2012 14:23:33 -0700 Subject: [PATCH] analytics: Track gold checkouts via Analytics This adds the necessary HTML and JS to the gold checkout pages to get google analytics data on those actions. --- r2/r2/controllers/front.py | 2 +- r2/r2/public/static/js/analytics.js | 28 ++++++++++++++++++++++++++++ r2/r2/templates/goldpayment.html | 11 ++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 081c19885..80f4678f6 100755 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -1321,7 +1321,7 @@ class FormsController(RedditController): g.log.info("just set payment_blob-%s" % passthrough) return BoringPage(_("reddit gold"), - show_sidebar = False, + show_sidebar=False, content=GoldPayment(goldtype, period, months, signed, recipient, giftmessage, passthrough) diff --git a/r2/r2/public/static/js/analytics.js b/r2/r2/public/static/js/analytics.js index b9fa10cb0..013bdc8bd 100644 --- a/r2/r2/public/static/js/analytics.js +++ b/r2/r2/public/static/js/analytics.js @@ -10,6 +10,8 @@ r.analytics = { ) $('.promotedlink.promoted:visible, .sponsorshipbox:visible').trigger('onshow') + $('form.google-checkout').on('submit', this.fireGoogleCheckout) + $('form.gold-checkout').one('submit', this.fireGoldCheckout) }, fetchTrackingHashes: function(callback) { @@ -121,6 +123,32 @@ r.analytics = { r.analytics.breadcrumbs.toParams() ) ) + }, + + fireGoldCheckout: function(event) { + var form = $(this), + vendor = form.data('vendor') + form.parent().addClass('working') + + // Track a virtual pageview indicating user went off-site to "vendor." + // If GA is loaded, have GA process form submission after firing + // (and cancel the default). + _gaq.push(['_trackPageview', '/gold/external/' + vendor]) + _gaq.push(function(){ form.submit() }) + + if (_gat && _gat._getTracker){ + // GA is loaded; form will submit via the _gaq.push'ed function + event.preventDefault() + } + }, + + fireGoogleCheckout: function(event) { + var form = $(this) + form.parent().addClass('working') + _gaq.push(function(){ + var pageTracker = _gaq._getAsyncTracker() + setUrchinInputCode(pageTracker) + }) } } diff --git a/r2/r2/templates/goldpayment.html b/r2/r2/templates/goldpayment.html index c8e16e023..7510aea0d 100644 --- a/r2/r2/templates/goldpayment.html +++ b/r2/r2/templates/goldpayment.html @@ -57,6 +57,8 @@ %if thing.google_id:
+
%endif
+ style="display:inline" class="gold-checkout" + data-vendor="paypal"> %if thing.quantity: @@ -94,6 +98,11 @@
${_("Note: Google Checkout does not support ongoing subscriptions at this time.")}
%endif %endif +
+ + +