From 4d564d5cf1af559e972d899808fd414a5ddceae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Fri, 25 Oct 2019 15:22:23 +0700 Subject: [PATCH] Merge pull request #2258 from overleaf/ta-recurly-custom-fields Recurly Custom Fields Tracking GitOrigin-RevId: f29f56cf7d0dfa91a8f4152897ba6bd897cb6238 --- .../Features/Subscription/RecurlyWrapper.js | 32 +++++++++++++++++++ .../Subscription/SubscriptionController.js | 4 ++- services/web/app/views/subscriptions/new.pug | 2 ++ .../web/public/src/main/account-upgrade.js | 7 +++- .../web/public/src/main/new-subscription.js | 4 ++- .../src/Subscription/RecurlyWrapperTests.js | 28 ++++++++++++++-- 6 files changed, 72 insertions(+), 5 deletions(-) diff --git a/services/web/app/src/Features/Subscription/RecurlyWrapper.js b/services/web/app/src/Features/Subscription/RecurlyWrapper.js index 2762183d92..3252827ed3 100644 --- a/services/web/app/src/Features/Subscription/RecurlyWrapper.js +++ b/services/web/app/src/Features/Subscription/RecurlyWrapper.js @@ -250,6 +250,12 @@ module.exports = RecurlyWrapper = { account_code: user._id } } + const customFields = getCustomFieldsFromSubscriptionDetails( + subscriptionDetails + ) + if (customFields) { + data.custom_fields = customFields + } const requestBody = RecurlyWrapper._buildXml('subscription', data) return RecurlyWrapper.apiRequest( @@ -356,6 +362,12 @@ module.exports = RecurlyWrapper = { data.account.billing_info.three_d_secure_action_result_token_id = recurlyTokenIds.threeDSecureActionResult } + const customFields = getCustomFieldsFromSubscriptionDetails( + subscriptionDetails + ) + if (customFields) { + data.custom_fields = customFields + } const requestBody = RecurlyWrapper._buildXml('subscription', data) 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) { return typeof value !== 'undefined' && value !== null ? transform(value) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index c1b186b476..eda63dfbdd 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -127,7 +127,9 @@ module.exports = SubscriptionController = { }), showCouponField: req.query.scf, showVatField: req.query.svf, - couponCode: req.query.cc || '' + couponCode: req.query.cc || '', + ITMCampaign: req.query.itm_campaign, + ITMContent: req.query.itm_content }) } ) diff --git a/services/web/app/views/subscriptions/new.pug b/services/web/app/views/subscriptions/new.pug index 482a63a14c..c0b1f4f4a4 100644 --- a/services/web/app/views/subscriptions/new.pug +++ b/services/web/app/views/subscriptions/new.pug @@ -8,6 +8,8 @@ block head-scripts window.recurlyApiKey = "!{settings.apis.recurly.publicKey}" window.couponCode = !{StringHelper.stringifyJsonForScript(couponCode)} window.recomendedCurrency = !{StringHelper.stringifyJsonForScript(currency.slice(0,3))} + window.ITMCampaign = '#{ITMCampaign}' + window.ITMContent = '#{ITMContent}' block content .content.content-alt diff --git a/services/web/public/src/main/account-upgrade.js b/services/web/public/src/main/account-upgrade.js index c2e8534854..db076e8cac 100644 --- a/services/web/public/src/main/account-upgrade.js +++ b/services/web/public/src/main/account-upgrade.js @@ -2,7 +2,7 @@ define(['base'], App => App.controller('FreeTrialModalController', function($scope, eventTracking) { $scope.buttonClass = 'btn-primary' - $scope.startFreeTrial = function(source) { + $scope.startFreeTrial = function(source, version) { const plan = 'collaborator_free_trial_7_days' const w = window.open() @@ -18,6 +18,11 @@ define(['base'], App => ) } url = `/user/subscription/new?planCode=${plan}&ssp=true` + url = `${url}&itm_campaign=${source}` + if (version) { + url = `${url}&itm_content=${version}` + } + $scope.startedFreeTrial = true eventTracking.sendMB('subscription-start-trial', { source, plan }) diff --git a/services/web/public/src/main/new-subscription.js b/services/web/public/src/main/new-subscription.js index dae4f91d25..08c00910a9 100644 --- a/services/web/public/src/main/new-subscription.js +++ b/services/web/public/src/main/new-subscription.js @@ -225,7 +225,9 @@ define(['base', 'directives/creditCards'], App => country: $scope.data.country, state: $scope.data.state, postal_code: $scope.data.postal_code - } + }, + ITMCampaign: window.ITMCampaign, + ITMContent: window.ITMContent } } diff --git a/services/web/test/unit/src/Subscription/RecurlyWrapperTests.js b/services/web/test/unit/src/Subscription/RecurlyWrapperTests.js index f2ce8560a8..8e7a22a599 100644 --- a/services/web/test/unit/src/Subscription/RecurlyWrapperTests.js +++ b/services/web/test/unit/src/Subscription/RecurlyWrapperTests.js @@ -649,7 +649,9 @@ describe('RecurlyWrapper', function() { country: 'some_country', state: 'some_state', zip: 'some_zip' - } + }, + ITMCampaign: 'itm-campaign-value', + ITMContent: 'itm-content-value' } this.subscription = {} this.recurlyTokenIds = { @@ -698,6 +700,16 @@ describe('RecurlyWrapper', function() { a-3d-token-id + + + itm_campaign + itm-campaign-value + + + itm_content + itm-content-value + + \ `) return done() @@ -1000,7 +1012,9 @@ describe('RecurlyWrapper', function() { country: 'some_country', state: 'some_state', zip: 'some_zip' - } + }, + ITMCampaign: 'itm-campaign-value', + ITMContent: 'itm-content-value' }) }) }) @@ -1505,6 +1519,16 @@ describe('RecurlyWrapper', function() { some_id + + + itm_campaign + itm-campaign-value + + + itm_content + itm-content-value + + \ `) return done()