Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/helpers/userpilot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import get from 'lodash/get';
import { formatIdentity } from './utils';

export const identifyUser = (user) => {
if (!user) return;
const mandates = get(user, 'customers[0].payment.mandates');
window.userpilot.identify(
user._id,
{
name: formatIdentity(user.identity, 'LF'),
email: user.local.email,
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 ? mandates[mandates.length - 1].signedAt ? 'yes' : 'no' : 'no',
subscriptionsAccepted: get(user, 'customers[0].subscriptionsAccepted') ? 'yes' : 'no',
}
);
}
1 change: 1 addition & 0 deletions src/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
<body>
<!-- DO NOT touch the following DIV -->
<div id="q-app"></div>
<script src="https://deploy.userpilot.io/33ig98d1.js"></script>
</body>
</html>
13 changes: 11 additions & 2 deletions src/pages/customers/Subscriptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -289,17 +293,18 @@ 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();
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');
}
Expand Down Expand Up @@ -337,6 +342,8 @@ export default {
};
await this.$customers.addSubscriptionHistory(this.customer._id, payload);
await this.refreshCustomer();
window.userpilot.track('subscriptions_ok');
window.userpilot.identify(this.$store.getters['main/user']._id, { subscriptionsAccepted: 'yes' });
NotifyPositive('Abonnement validé');
}
} catch (e) {
Expand Down Expand Up @@ -393,6 +400,8 @@ 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' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi tu as juste unidentify ici alors que pour les souscriptions tu as track et identify ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est un oubli '-_-

}
}
await this.refreshCustomer();
Expand Down
7 changes: 7 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,6 +34,8 @@ 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');
Expand All @@ -46,12 +49,16 @@ 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');
}
}
} else {
identifyUser(store.getters['main/user'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu ne reload pas ici ? pourquoi ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est un oubli ''-_-

window.userpilot.reload();
next();
}
});
Expand Down