ordering-ui-react-native 0.15.4 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ordering-ui-react-native",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.5",
|
|
4
4
|
"description": "Reusable components made in react native",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"author": "ordering.inc",
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"@react-navigation/material-bottom-tabs": "^5.3.14",
|
|
49
49
|
"@react-navigation/native": "^5.7.6",
|
|
50
50
|
"@react-navigation/stack": "^5.9.3",
|
|
51
|
+
"@segment/analytics-react-native": "^2.1.11",
|
|
52
|
+
"@segment/sovran-react-native": "^0.2.6",
|
|
51
53
|
"@sentry/react-native": "^2.6.0",
|
|
52
54
|
"@stripe/stripe-react-native": "^0.2.0",
|
|
53
55
|
"@types/react-native-loading-spinner-overlay": "^0.5.2",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AddressForm } from './src/components/AddressForm';
|
|
2
2
|
import { AddressDetails } from './src/components/AddressDetails';
|
|
3
|
+
import { AnalyticsSegment } from './src/components/AnalyticsSegment';
|
|
3
4
|
import { Home } from './src/components/Home';
|
|
4
5
|
import { LoginForm } from './src/components/LoginForm';
|
|
5
6
|
import { SignupForm } from './src/components/SignupForm';
|
|
@@ -67,6 +68,7 @@ import {
|
|
|
67
68
|
export {
|
|
68
69
|
AddressForm,
|
|
69
70
|
AddressDetails,
|
|
71
|
+
AnalyticsSegment,
|
|
70
72
|
Home as HomeView,
|
|
71
73
|
SignupForm,
|
|
72
74
|
LoginForm,
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { createClient, AnalyticsProvider } from '@segment/analytics-react-native';
|
|
3
|
+
import { useEvent, useConfig } from 'ordering-components/native';
|
|
4
|
+
|
|
5
|
+
export const AnalyticsSegment = (props: any) => {
|
|
6
|
+
const { children } = props
|
|
7
|
+
|
|
8
|
+
const [events] = useEvent()
|
|
9
|
+
const [configState] = useConfig()
|
|
10
|
+
const [segmentClient, setSegmentClient] = useState<any>({})
|
|
11
|
+
|
|
12
|
+
const handleClickProduct = (product: any) => {
|
|
13
|
+
segmentClient.track('Product Clicked', {
|
|
14
|
+
id: product.id,
|
|
15
|
+
name: product.name,
|
|
16
|
+
category: product.category_id,
|
|
17
|
+
price: product.price
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const handleProductAdded = (product: any) => {
|
|
22
|
+
segmentClient.track('Product Added', {
|
|
23
|
+
id: product.id,
|
|
24
|
+
name: product.name,
|
|
25
|
+
category: product.category_id,
|
|
26
|
+
price: product.price,
|
|
27
|
+
quantity: product.quantity
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const handleProductRemoved = (product: any) => {
|
|
32
|
+
segmentClient.track('Product Removed', {
|
|
33
|
+
id: product.id,
|
|
34
|
+
name: product.name,
|
|
35
|
+
category: product.category_id,
|
|
36
|
+
price: product.price,
|
|
37
|
+
quantity: product.quantity
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const handleOrderPlaced = (order: any) => {
|
|
42
|
+
segmentClient.track('Order Placed', {
|
|
43
|
+
id: order.id,
|
|
44
|
+
affiliation: order.business?.name,
|
|
45
|
+
revenue: order.total,
|
|
46
|
+
tax: order.tax_total,
|
|
47
|
+
shipping: order.delivery_zone_price
|
|
48
|
+
})
|
|
49
|
+
segmentClient.track('Payment Info Entered', {
|
|
50
|
+
order: order.id,
|
|
51
|
+
business: order.business?.name,
|
|
52
|
+
business_id: order.business_id,
|
|
53
|
+
total: order.total,
|
|
54
|
+
tax: order.tax_total,
|
|
55
|
+
delivery: order.delivery_zone_price,
|
|
56
|
+
paymethod: order.paymethod
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const handleUpdateOrder = (order: any) => {
|
|
61
|
+
segmentClient.track('Order Updated', {
|
|
62
|
+
id: order.id,
|
|
63
|
+
affiliation: order.business?.name,
|
|
64
|
+
revenue: order.total,
|
|
65
|
+
tax: order.tax_total,
|
|
66
|
+
shipping: order.delivery_zone_price
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const handleAddOrder = (order: any) => {
|
|
71
|
+
segmentClient.track('Order Added', {
|
|
72
|
+
id: order.id,
|
|
73
|
+
affiliation: order.business?.name,
|
|
74
|
+
revenue: order.total,
|
|
75
|
+
tax: order.tax_total,
|
|
76
|
+
shipping: order.delivery_zone_price
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const handleLogin = (data: any) => {
|
|
81
|
+
segmentClient.identify(data.id, {
|
|
82
|
+
email: data.email,
|
|
83
|
+
name: data.name
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (segmentClient?.config?.writeKey) {
|
|
89
|
+
events.on('product_clicked', handleClickProduct)
|
|
90
|
+
events.on('userLogin', handleLogin)
|
|
91
|
+
events.on('product_added', handleProductAdded)
|
|
92
|
+
events.on('order_placed', handleOrderPlaced)
|
|
93
|
+
events.on('order_updated', handleUpdateOrder)
|
|
94
|
+
events.on('order_added', handleAddOrder)
|
|
95
|
+
events.on('cart_product_removed', handleProductRemoved)
|
|
96
|
+
}
|
|
97
|
+
return () => {
|
|
98
|
+
if (segmentClient?.config?.writeKey) {
|
|
99
|
+
events.off('product_clicked', handleClickProduct)
|
|
100
|
+
events.off('userLogin', handleLogin)
|
|
101
|
+
events.off('product_added', handleProductAdded)
|
|
102
|
+
events.off('order_placed', handleOrderPlaced)
|
|
103
|
+
events.off('order_updated', handleUpdateOrder)
|
|
104
|
+
events.off('order_added', handleAddOrder)
|
|
105
|
+
events.off('cart_product_removed', handleProductRemoved)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, [segmentClient])
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (configState?.configs?.segment_track_id?.value) {
|
|
112
|
+
const _segmentClient: any = createClient({
|
|
113
|
+
writeKey: configState?.configs?.segment_track_id?.value
|
|
114
|
+
});
|
|
115
|
+
setSegmentClient(_segmentClient)
|
|
116
|
+
}
|
|
117
|
+
}, [configState])
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<>
|
|
121
|
+
<AnalyticsProvider client={segmentClient}>
|
|
122
|
+
{children}
|
|
123
|
+
</AnalyticsProvider>
|
|
124
|
+
</>
|
|
125
|
+
|
|
126
|
+
)
|
|
127
|
+
}
|