From ee1b56d43d7c060048890f92bf430809b56cb2d1 Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Wed, 16 Oct 2019 16:31:56 +0200 Subject: [PATCH 1/6] COM-714 Testing userpilot --- src/helpers/userpilot.js | 12 ++++++++++++ src/index.template.html | 1 + src/pages/customers/Subscriptions.vue | 2 ++ src/router/index.js | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 src/helpers/userpilot.js diff --git a/src/helpers/userpilot.js b/src/helpers/userpilot.js new file mode 100644 index 000000000..3801536f6 --- /dev/null +++ b/src/helpers/userpilot.js @@ -0,0 +1,12 @@ +import { formatIdentity } from './utils'; + +export const identifyUser = (user) => { + window.userpilot.identify( + user._id, + { + name: formatIdentity(user.identity, 'LF'), + email: user.local.email, + created_at: user.createdAt, + } + ); +} diff --git a/src/index.template.html b/src/index.template.html index a85229af1..01abc33d7 100644 --- a/src/index.template.html +++ b/src/index.template.html @@ -29,5 +29,6 @@
+ diff --git a/src/pages/customers/Subscriptions.vue b/src/pages/customers/Subscriptions.vue index 051b34e2e..0362e26d2 100644 --- a/src/pages/customers/Subscriptions.vue +++ b/src/pages/customers/Subscriptions.vue @@ -265,6 +265,7 @@ export default { async mounted () { await this.refreshCustomer(); await this.checkMandates(); + window.userpilot.track('test'); }, methods: { async refreshCustomer () { @@ -337,6 +338,7 @@ export default { }; await this.$customers.addSubscriptionHistory(this.customer._id, payload); await this.refreshCustomer(); + window.userpilot.track('new_subscription'); NotifyPositive('Abonnement validé'); } } catch (e) { diff --git a/src/router/index.js b/src/router/index.js index add143041..fad39fef9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -7,6 +7,7 @@ import routes from './routes' import alenvi from '../helpers/alenvi' import store from '../store/index' import { checkPermission } from '../helpers/checkPermission' +import { identifyUser } from '../helpers/userpilot' Vue.use(VueRouter) Vue.use(VueMeta); @@ -25,6 +26,7 @@ const Router = new VueRouter({ }) Router.beforeEach(async (to, from, next) => { + window.userpilot.reload(); if (to.meta.cookies) { if (!Cookies.get('alenvi_token') || !Cookies.get('user_id')) { if (await alenvi.refreshAlenviCookies()) { @@ -33,6 +35,7 @@ Router.beforeEach(async (to, from, next) => { } if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); + identifyUser(store.getters['main/user']); next(); } else { next('/401'); @@ -46,6 +49,7 @@ Router.beforeEach(async (to, from, next) => { } if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); + identifyUser(store.getters['main/user']); next(); } else { next('/401'); From 684a824ddc62dba408272e1957b05194efe3b901 Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Thu, 17 Oct 2019 17:58:57 +0200 Subject: [PATCH 2/6] COM-714 Implementing userpilot (WIP) --- src/helpers/userpilot.js | 4 ++++ src/pages/customers/Subscriptions.vue | 9 +++++---- src/router/index.js | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/helpers/userpilot.js b/src/helpers/userpilot.js index 3801536f6..092bd5fe8 100644 --- a/src/helpers/userpilot.js +++ b/src/helpers/userpilot.js @@ -1,12 +1,16 @@ +import get from 'lodash/get'; import { formatIdentity } from './utils'; export const identifyUser = (user) => { + console.log('user', user); window.userpilot.identify( user._id, { name: formatIdentity(user.identity, 'LF'), email: user.local.email, created_at: user.createdAt, + role: get(user, 'role.name', ''), + subscriptionsAccepted: get(user, 'subscriptionsAccepted') ? 'yes' : 'no', } ); } diff --git a/src/pages/customers/Subscriptions.vue b/src/pages/customers/Subscriptions.vue index 0362e26d2..7d414e9ea 100644 --- a/src/pages/customers/Subscriptions.vue +++ b/src/pages/customers/Subscriptions.vue @@ -265,7 +265,6 @@ export default { async mounted () { await this.refreshCustomer(); await this.checkMandates(); - window.userpilot.track('test'); }, methods: { async refreshCustomer () { @@ -290,17 +289,19 @@ export default { let value = this.$_.get(this.customer, path); if (this.tmpInput === value) return; + const isIban = path === 'payment.iban'; this.$_.get(this.$v.customer, path).$touch(); if (this.$_.get(this.$v.customer, path).$error) return NotifyWarning('Champ(s) invalide(s)'); - if (path.match(/iban/i)) value = value.split(' ').join(''); + if (isIban) value = value.split(' ').join(''); await this.$customers.updateById(this.customer._id, this.$_.set({}, path, value)); await this.$store.dispatch('main/getUser', this.helper._id); await this.refreshCustomer(); + if (isIban) window.userpilot.track('iban_ok'); NotifyPositive('Modification enregistrée'); - if (path.match(/iban/i)) { + if (isIban) { this.$v.customer.payment.bic.$touch(); if (!this.$v.customer.payment.bic.required) return NotifyWarning('Merci de renseigner votre BIC'); } @@ -338,7 +339,7 @@ export default { }; await this.$customers.addSubscriptionHistory(this.customer._id, payload); await this.refreshCustomer(); - window.userpilot.track('new_subscription'); + window.userpilot.track('subscriptions_accepted'); NotifyPositive('Abonnement validé'); } } catch (e) { diff --git a/src/router/index.js b/src/router/index.js index fad39fef9..a665fd073 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -7,7 +7,7 @@ import routes from './routes' import alenvi from '../helpers/alenvi' import store from '../store/index' import { checkPermission } from '../helpers/checkPermission' -import { identifyUser } from '../helpers/userpilot' +import { identifyUser } from '../helpers/userpilot'; Vue.use(VueRouter) Vue.use(VueMeta); @@ -35,7 +35,7 @@ Router.beforeEach(async (to, from, next) => { } if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); - identifyUser(store.getters['main/user']); + identifyUser(store.getters['main/user']) next(); } else { next('/401'); @@ -49,13 +49,14 @@ Router.beforeEach(async (to, from, next) => { } if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); - identifyUser(store.getters['main/user']); + identifyUser(store.getters['main/user']) next(); } else { next('/401'); } } } else { + identifyUser(store.getters['main/user']) next(); } }); From e3c6bf38567db348e67dcf197c8abd4f4be6c18b Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Fri, 18 Oct 2019 14:57:47 +0200 Subject: [PATCH 3/6] COM-714 Implement userpilot for customer subscription page --- src/helpers/userpilot.js | 7 +++++-- src/pages/customers/Subscriptions.vue | 5 ++++- src/router/index.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/helpers/userpilot.js b/src/helpers/userpilot.js index 092bd5fe8..782fe6cd8 100644 --- a/src/helpers/userpilot.js +++ b/src/helpers/userpilot.js @@ -2,7 +2,8 @@ import get from 'lodash/get'; import { formatIdentity } from './utils'; export const identifyUser = (user) => { - console.log('user', user); + if (!user) return; + const mandates = get(user, 'customers[0].payment.mandates'); window.userpilot.identify( user._id, { @@ -10,7 +11,9 @@ export const identifyUser = (user) => { email: user.local.email, created_at: user.createdAt, role: get(user, 'role.name', ''), - subscriptionsAccepted: get(user, 'subscriptionsAccepted') ? 'yes' : 'no', + payment: get(user, 'customers[0].payment.iban') && get(user, 'customers[0].payment.bic') ? 'yes' : 'no', + signedMandate: !mandates.length ? 'no' : mandates[mandates.length - 1].signedAt ? 'yes' : 'no', + subscriptionsAccepted: get(user, 'customers[0].subscriptionsAccepted') ? 'yes' : 'no', } ); } diff --git a/src/pages/customers/Subscriptions.vue b/src/pages/customers/Subscriptions.vue index 7d414e9ea..7c58daeb8 100644 --- a/src/pages/customers/Subscriptions.vue +++ b/src/pages/customers/Subscriptions.vue @@ -299,6 +299,7 @@ export default { await this.$store.dispatch('main/getUser', this.helper._id); await this.refreshCustomer(); if (isIban) window.userpilot.track('iban_ok'); + window.userpilot.identify(this.$store.getters['main/user']._id, { iban: 'yes' }); NotifyPositive('Modification enregistrée'); if (isIban) { @@ -339,7 +340,8 @@ export default { }; await this.$customers.addSubscriptionHistory(this.customer._id, payload); await this.refreshCustomer(); - window.userpilot.track('subscriptions_accepted'); + window.userpilot.track('subscriptions_ok'); + window.userpilot.identify(this.$store.getters['main/user']._id, { subscriptionsAccepted: 'yes' }); NotifyPositive('Abonnement validé'); } } catch (e) { @@ -396,6 +398,7 @@ export default { const hasSigned = await this.hasSignedDoc(mandate.everSignId); if (hasSigned) { this.$customers.saveSignedDoc({ _id: this.customer._id, mandateId: mandate._id }); + window.userpilot.identify(this.$store.getters['main/user']._id, { signedMandate: 'yes' }); } } await this.refreshCustomer(); diff --git a/src/router/index.js b/src/router/index.js index a665fd073..68483d976 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -26,7 +26,6 @@ const Router = new VueRouter({ }) Router.beforeEach(async (to, from, next) => { - window.userpilot.reload(); if (to.meta.cookies) { if (!Cookies.get('alenvi_token') || !Cookies.get('user_id')) { if (await alenvi.refreshAlenviCookies()) { @@ -36,6 +35,7 @@ Router.beforeEach(async (to, from, next) => { if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); identifyUser(store.getters['main/user']) + window.userpilot.reload(); next(); } else { next('/401'); @@ -50,6 +50,7 @@ Router.beforeEach(async (to, from, next) => { if (checkPermission(to, store.getters['main/user'])) { store.commit('main/changeRefreshState', false); identifyUser(store.getters['main/user']) + window.userpilot.reload(); next(); } else { next('/401'); From 51b7e795251b8661b6be71593c0bcf25832c574e Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Fri, 18 Oct 2019 15:18:04 +0200 Subject: [PATCH 4/6] COM-714 Fix mandate condition --- src/helpers/userpilot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/userpilot.js b/src/helpers/userpilot.js index 782fe6cd8..7f8971ee1 100644 --- a/src/helpers/userpilot.js +++ b/src/helpers/userpilot.js @@ -12,7 +12,7 @@ export const identifyUser = (user) => { created_at: user.createdAt, role: get(user, 'role.name', ''), payment: get(user, 'customers[0].payment.iban') && get(user, 'customers[0].payment.bic') ? 'yes' : 'no', - signedMandate: !mandates.length ? 'no' : mandates[mandates.length - 1].signedAt ? 'yes' : 'no', + signedMandate: mandates && !mandates.length ? 'no' : mandates[mandates.length - 1].signedAt ? 'yes' : 'no', subscriptionsAccepted: get(user, 'customers[0].subscriptionsAccepted') ? 'yes' : 'no', } ); From 1fa8be8fbcc86ddd7f345a64a63d43775e289f45 Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Fri, 18 Oct 2019 15:27:58 +0200 Subject: [PATCH 5/6] COM-714 Fixes after PR comments --- src/pages/customers/Subscriptions.vue | 7 +++++-- src/router/index.js | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/customers/Subscriptions.vue b/src/pages/customers/Subscriptions.vue index 7c58daeb8..997c94f7e 100644 --- a/src/pages/customers/Subscriptions.vue +++ b/src/pages/customers/Subscriptions.vue @@ -275,6 +275,10 @@ export default { this.$store.commit('rh/saveUserProfile', this.customer); this.$v.customer.$touch(); + if (this.$_.get(this.customer, 'payment.bic') && this.$_.get(this.customer, 'payment.iban')) { + window.userpilot.track('payment_ok'); + window.userpilot.identify(this.$store.getters['main/user']._id, { payment: 'yes' }); + } } catch (e) { console.error(e); this.customer = {}; @@ -298,8 +302,6 @@ export default { await this.$customers.updateById(this.customer._id, this.$_.set({}, path, value)); await this.$store.dispatch('main/getUser', this.helper._id); await this.refreshCustomer(); - if (isIban) window.userpilot.track('iban_ok'); - window.userpilot.identify(this.$store.getters['main/user']._id, { iban: 'yes' }); NotifyPositive('Modification enregistrée'); if (isIban) { @@ -398,6 +400,7 @@ export default { const hasSigned = await this.hasSignedDoc(mandate.everSignId); if (hasSigned) { this.$customers.saveSignedDoc({ _id: this.customer._id, mandateId: mandate._id }); + window.userpilot.track('mandate_ok'); window.userpilot.identify(this.$store.getters['main/user']._id, { signedMandate: 'yes' }); } } diff --git a/src/router/index.js b/src/router/index.js index 68483d976..b20f15b00 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -58,6 +58,7 @@ Router.beforeEach(async (to, from, next) => { } } else { identifyUser(store.getters['main/user']) + window.userpilot.reload(); next(); } }); From 732901d047aff8fd9b382bb64460d186abeccb24 Mon Sep 17 00:00:00 2001 From: jctrebalag Date: Fri, 18 Oct 2019 17:31:10 +0200 Subject: [PATCH 6/6] COM-714 Fix ternary --- src/helpers/userpilot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/userpilot.js b/src/helpers/userpilot.js index 7f8971ee1..4b687e7bc 100644 --- a/src/helpers/userpilot.js +++ b/src/helpers/userpilot.js @@ -12,7 +12,7 @@ export const identifyUser = (user) => { created_at: user.createdAt, role: get(user, 'role.name', ''), payment: get(user, 'customers[0].payment.iban') && get(user, 'customers[0].payment.bic') ? 'yes' : 'no', - signedMandate: mandates && !mandates.length ? 'no' : mandates[mandates.length - 1].signedAt ? 'yes' : 'no', + signedMandate: mandates && mandates.length ? mandates[mandates.length - 1].signedAt ? 'yes' : 'no' : 'no', subscriptionsAccepted: get(user, 'customers[0].subscriptionsAccepted') ? 'yes' : 'no', } );