Add revenue tracking to analytics

This commit is contained in:
Matt Lott 2014-12-09 13:57:01 -08:00
parent c6502f5dab
commit 8df3eed824
3 changed files with 8 additions and 1 deletions

View file

@ -128,6 +128,7 @@ module.exports = class User extends CocoModel
getGemPromptGroup: ->
# A/B Testing whether extra prompt when low gems leads to more gem purchases
# TODO: Rename gem purchase event in BuyGemsModal to 'Started gem purchase' after this test is over
return @gemPromptGroup if @gemPromptGroup
group = me.get('testGroupNumber') % 8
@gemPromptGroup = switch group

View file

@ -57,6 +57,7 @@ module.exports = class BuyGemsModal extends ModalView
Backbone.Mediator.publish 'buy-gems-modal:purchase-initiated', { productID: productID }
else
# TODO: rename this event to 'Started gem purchase' after gemPrompt A/B test is over
application.tracker?.trackEvent 'Started purchase', { productID: productID }
stripeHandler.open({
description: $.t(product.i18n)
@ -78,6 +79,9 @@ module.exports = class BuyGemsModal extends ModalView
@render()
jqxhr = $.post('/db/payment', data)
jqxhr.done(=>
application.tracker?.trackEvent 'Finished gem purchase',
productID: @productBeingPurchased.id
revenue: @productBeingPurchased.amount / 100
document.location.reload()
)
jqxhr.fail(=>

View file

@ -72,6 +72,8 @@ module.exports = class SubscribeModal extends ModalView
amount: 599
}
@purchasedAmount = options.amount
stripeHandler.open(options)
onStripeReceivedToken: (e) ->
@ -88,7 +90,7 @@ module.exports = class SubscribeModal extends ModalView
me.patch({headers: {'X-Change-Plan': 'true'}})
onSubscriptionSuccess: ->
application.tracker?.trackEvent 'Finished subscription purchase', {}
application.tracker?.trackEvent 'Finished subscription purchase', revenue: @purchasedAmount / 100
application.tracker?.trackPageView "subscription/finish-purchase", ['Google Analytics']
Backbone.Mediator.publish 'subscribe-modal:subscribed', {}
@playSound 'victory'