mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 06:18:08 -05:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
%if thing.google_id:
|
||||
<form action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/${thing.google_id}"
|
||||
id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"
|
||||
class="gold-checkout google-checkout"
|
||||
data-vendor="google-checkout"
|
||||
target="_top" style="display:inline">
|
||||
<input name="item_name_1" type="hidden" value="creddits"/>
|
||||
<input name="item_description_1" type="hidden"
|
||||
@@ -75,12 +77,14 @@
|
||||
value="${thing.passthrough}"/>
|
||||
<input name="item_currency_1" type="hidden" value="USD"/>
|
||||
<input name="_charset_" type="hidden" value="utf-8"/>
|
||||
<input type="hidden" name="analyticsdata" value="">
|
||||
<button class="btn gold-button">${_("Google Checkout")}</button>
|
||||
</form>
|
||||
%endif
|
||||
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"
|
||||
style="display:inline">
|
||||
style="display:inline" class="gold-checkout"
|
||||
data-vendor="paypal">
|
||||
<input type="hidden" name="cmd" value="_s-xclick" />
|
||||
<input type="hidden" name="custom" value="${thing.passthrough}" />
|
||||
%if thing.quantity:
|
||||
@@ -94,6 +98,11 @@
|
||||
<div class="note">${_("Note: Google Checkout does not support ongoing subscriptions at this time.")}</div>
|
||||
%endif
|
||||
%endif
|
||||
<div class="throbber"></div>
|
||||
</%utils:round_field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="//checkout.google.com/files/digital/ga_post.js"
|
||||
type="text/javascript"></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user