File tree Expand file tree Collapse file tree 1 file changed +36
-3
lines changed
Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,50 @@ import db from '.';
22import analytics from '../components/stats' ;
33
44const 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 ,
You can’t perform that action at this time.
0 commit comments