Merge pull request #2258 from overleaf/ta-recurly-custom-fields

Recurly Custom Fields Tracking

GitOrigin-RevId: f29f56cf7d0dfa91a8f4152897ba6bd897cb6238
This commit is contained in:
Timothée Alby 2019-10-25 15:22:23 +07:00 committed by sharelatex
parent 61243338be
commit 4d564d5cf1
6 changed files with 72 additions and 5 deletions

View file

@ -250,6 +250,12 @@ module.exports = RecurlyWrapper = {
account_code: user._id account_code: user._id
} }
} }
const customFields = getCustomFieldsFromSubscriptionDetails(
subscriptionDetails
)
if (customFields) {
data.custom_fields = customFields
}
const requestBody = RecurlyWrapper._buildXml('subscription', data) const requestBody = RecurlyWrapper._buildXml('subscription', data)
return RecurlyWrapper.apiRequest( return RecurlyWrapper.apiRequest(
@ -356,6 +362,12 @@ module.exports = RecurlyWrapper = {
data.account.billing_info.three_d_secure_action_result_token_id = data.account.billing_info.three_d_secure_action_result_token_id =
recurlyTokenIds.threeDSecureActionResult recurlyTokenIds.threeDSecureActionResult
} }
const customFields = getCustomFieldsFromSubscriptionDetails(
subscriptionDetails
)
if (customFields) {
data.custom_fields = customFields
}
const requestBody = RecurlyWrapper._buildXml('subscription', data) const requestBody = RecurlyWrapper._buildXml('subscription', data)
return RecurlyWrapper.apiRequest( return RecurlyWrapper.apiRequest(
@ -996,6 +1008,26 @@ module.exports = RecurlyWrapper = {
} }
} }
function getCustomFieldsFromSubscriptionDetails(subscriptionDetails) {
if (!subscriptionDetails.ITMCampaign) {
return null
}
const customFields = [
{
name: 'itm_campaign',
value: subscriptionDetails.ITMCampaign
}
]
if (subscriptionDetails.ITMContent) {
customFields.push({
name: 'itm_content',
value: subscriptionDetails.ITMContent
})
}
return { custom_field: customFields }
}
function __guard__(value, transform) { function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null return typeof value !== 'undefined' && value !== null
? transform(value) ? transform(value)

View file

@ -127,7 +127,9 @@ module.exports = SubscriptionController = {
}), }),
showCouponField: req.query.scf, showCouponField: req.query.scf,
showVatField: req.query.svf, showVatField: req.query.svf,
couponCode: req.query.cc || '' couponCode: req.query.cc || '',
ITMCampaign: req.query.itm_campaign,
ITMContent: req.query.itm_content
}) })
} }
) )

View file

@ -8,6 +8,8 @@ block head-scripts
window.recurlyApiKey = "!{settings.apis.recurly.publicKey}" window.recurlyApiKey = "!{settings.apis.recurly.publicKey}"
window.couponCode = !{StringHelper.stringifyJsonForScript(couponCode)} window.couponCode = !{StringHelper.stringifyJsonForScript(couponCode)}
window.recomendedCurrency = !{StringHelper.stringifyJsonForScript(currency.slice(0,3))} window.recomendedCurrency = !{StringHelper.stringifyJsonForScript(currency.slice(0,3))}
window.ITMCampaign = '#{ITMCampaign}'
window.ITMContent = '#{ITMContent}'
block content block content
.content.content-alt .content.content-alt

View file

@ -2,7 +2,7 @@ define(['base'], App =>
App.controller('FreeTrialModalController', function($scope, eventTracking) { App.controller('FreeTrialModalController', function($scope, eventTracking) {
$scope.buttonClass = 'btn-primary' $scope.buttonClass = 'btn-primary'
$scope.startFreeTrial = function(source) { $scope.startFreeTrial = function(source, version) {
const plan = 'collaborator_free_trial_7_days' const plan = 'collaborator_free_trial_7_days'
const w = window.open() const w = window.open()
@ -18,6 +18,11 @@ define(['base'], App =>
) )
} }
url = `/user/subscription/new?planCode=${plan}&ssp=true` url = `/user/subscription/new?planCode=${plan}&ssp=true`
url = `${url}&itm_campaign=${source}`
if (version) {
url = `${url}&itm_content=${version}`
}
$scope.startedFreeTrial = true $scope.startedFreeTrial = true
eventTracking.sendMB('subscription-start-trial', { source, plan }) eventTracking.sendMB('subscription-start-trial', { source, plan })

View file

@ -225,7 +225,9 @@ define(['base', 'directives/creditCards'], App =>
country: $scope.data.country, country: $scope.data.country,
state: $scope.data.state, state: $scope.data.state,
postal_code: $scope.data.postal_code postal_code: $scope.data.postal_code
} },
ITMCampaign: window.ITMCampaign,
ITMContent: window.ITMContent
} }
} }

View file

@ -649,7 +649,9 @@ describe('RecurlyWrapper', function() {
country: 'some_country', country: 'some_country',
state: 'some_state', state: 'some_state',
zip: 'some_zip' zip: 'some_zip'
} },
ITMCampaign: 'itm-campaign-value',
ITMContent: 'itm-content-value'
} }
this.subscription = {} this.subscription = {}
this.recurlyTokenIds = { this.recurlyTokenIds = {
@ -698,6 +700,16 @@ describe('RecurlyWrapper', function() {
<three_d_secure_action_result_token_id>a-3d-token-id</three_d_secure_action_result_token_id> <three_d_secure_action_result_token_id>a-3d-token-id</three_d_secure_action_result_token_id>
</billing_info> </billing_info>
</account> </account>
<custom_fields>
<custom_field>
<name>itm_campaign</name>
<value>itm-campaign-value</value>
</custom_field>
<custom_field>
<name>itm_content</name>
<value>itm-content-value</value>
</custom_field>
</custom_fields>
</subscription>\ </subscription>\
`) `)
return done() return done()
@ -1000,7 +1012,9 @@ describe('RecurlyWrapper', function() {
country: 'some_country', country: 'some_country',
state: 'some_state', state: 'some_state',
zip: 'some_zip' zip: 'some_zip'
} },
ITMCampaign: 'itm-campaign-value',
ITMContent: 'itm-content-value'
}) })
}) })
}) })
@ -1505,6 +1519,16 @@ describe('RecurlyWrapper', function() {
<account> <account>
<account_code>some_id</account_code> <account_code>some_id</account_code>
</account> </account>
<custom_fields>
<custom_field>
<name>itm_campaign</name>
<value>itm-campaign-value</value>
</custom_field>
<custom_field>
<name>itm_content</name>
<value>itm-content-value</value>
</custom_field>
</custom_fields>
</subscription>\ </subscription>\
`) `)
return done() return done()