Skip to content

Commit 981ab6e

Browse files
authored
Merge pull request #243 from abakusbackup/update-tracks
Add more information to the product sale track call
2 parents 8105243 + 1e42d5b commit 981ab6e

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/models/transactionProduct.model.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,50 @@ import db from '.';
22
import analytics from '../components/stats';
33

44
const trackProductUsage = transactionProduct => {
5+
let product = null;
6+
let customer = null;
7+
let transaction = null;
8+
59
db.Product.findOne({
610
where: {
711
id: transactionProduct.productId
812
}
913
})
10-
.then(product => {
11-
if (product) {
14+
.then(result => {
15+
product = result;
16+
return result;
17+
})
18+
.then(() =>
19+
db.Transaction.findOne({
20+
where: {
21+
id: transactionProduct.transactionId
22+
}
23+
})
24+
)
25+
.then(result => {
26+
if (result) {
27+
transaction = result;
28+
return result;
29+
}
30+
return Promise.resolve();
31+
})
32+
.then(() => transaction.getCustomer())
33+
.then(result => {
34+
customer = result;
35+
return result;
36+
})
37+
38+
.then(() => {
39+
if (product && customer && transaction) {
1240
return analytics.track({
13-
anonymousId: 'system',
41+
userId: customer.id,
1442
event: 'product_sale',
1543
properties: {
44+
systemId: product.systemId,
45+
username: customer.username,
46+
displayName: customer.displayName,
47+
sellerId: transaction.sellerId,
48+
transactionId: transaction.id,
1649
productId: product.id,
1750
name: product.name,
1851
type: product.type,

0 commit comments

Comments
 (0)