@akson/cortex-analytics-react 2.0.0 → 2.1.0
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/README.md +91 -73
- package/dist/index.js +574 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +544 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -61
package/README.md
CHANGED
|
@@ -23,36 +23,37 @@ npm install @akson/cortex-analytics-react
|
|
|
23
23
|
### 1. Setup Provider
|
|
24
24
|
|
|
25
25
|
```tsx
|
|
26
|
-
import React from
|
|
27
|
-
import {
|
|
28
|
-
|
|
26
|
+
import React from "react";
|
|
27
|
+
import {
|
|
28
|
+
AnalyticsProvider,
|
|
29
|
+
type AnalyticsConfig,
|
|
30
|
+
} from "@akson/cortex-analytics-react";
|
|
31
|
+
import { LEAD_GENERATION_EVENTS } from "@akson/cortex-utilities/events";
|
|
29
32
|
|
|
30
33
|
const analyticsConfig: AnalyticsConfig = {
|
|
31
34
|
platforms: {
|
|
32
35
|
gtm: {
|
|
33
|
-
containerId:
|
|
36
|
+
containerId: "GTM-XXXXXXX",
|
|
34
37
|
workspaceId: 40,
|
|
35
38
|
},
|
|
36
39
|
posthog: {
|
|
37
|
-
apiKey:
|
|
38
|
-
host:
|
|
40
|
+
apiKey: "phc_your_key",
|
|
41
|
+
host: "https://app.posthog.com",
|
|
39
42
|
},
|
|
40
43
|
ga4: {
|
|
41
|
-
measurementId:
|
|
44
|
+
measurementId: "G-XXXXXXXXXX",
|
|
42
45
|
},
|
|
43
46
|
},
|
|
44
47
|
conversions: {
|
|
45
|
-
[LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED]:
|
|
46
|
-
[LEAD_GENERATION_EVENTS.LEAD_WHATSAPP_CONTACT]:
|
|
48
|
+
[LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED]: "CONVERSION_LABEL_1",
|
|
49
|
+
[LEAD_GENERATION_EVENTS.LEAD_WHATSAPP_CONTACT]: "CONVERSION_LABEL_2",
|
|
47
50
|
},
|
|
48
|
-
debug: process.env.NODE_ENV ===
|
|
51
|
+
debug: process.env.NODE_ENV === "development",
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
export default function App({ children }) {
|
|
52
55
|
return (
|
|
53
|
-
<AnalyticsProvider config={analyticsConfig}>
|
|
54
|
-
{children}
|
|
55
|
-
</AnalyticsProvider>
|
|
56
|
+
<AnalyticsProvider config={analyticsConfig}>{children}</AnalyticsProvider>
|
|
56
57
|
);
|
|
57
58
|
}
|
|
58
59
|
```
|
|
@@ -60,8 +61,11 @@ export default function App({ children }) {
|
|
|
60
61
|
### 2. Use Analytics Hooks
|
|
61
62
|
|
|
62
63
|
```tsx
|
|
63
|
-
import React from
|
|
64
|
-
import {
|
|
64
|
+
import React from "react";
|
|
65
|
+
import {
|
|
66
|
+
useAnalytics,
|
|
67
|
+
LEAD_GENERATION_EVENTS,
|
|
68
|
+
} from "@akson/cortex-analytics-react";
|
|
65
69
|
|
|
66
70
|
export function ContactForm() {
|
|
67
71
|
const analytics = useAnalytics();
|
|
@@ -69,97 +73,99 @@ export function ContactForm() {
|
|
|
69
73
|
const handleSubmit = (formData: any) => {
|
|
70
74
|
// Track standardized lead event
|
|
71
75
|
analytics.track(LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED, {
|
|
72
|
-
form_type:
|
|
73
|
-
source:
|
|
76
|
+
form_type: "contact",
|
|
77
|
+
source: "header",
|
|
74
78
|
lead_score: 100,
|
|
75
79
|
});
|
|
76
80
|
};
|
|
77
81
|
|
|
78
|
-
return
|
|
79
|
-
<form onSubmit={handleSubmit}>
|
|
80
|
-
{/* Your form */}
|
|
81
|
-
</form>
|
|
82
|
-
);
|
|
82
|
+
return <form onSubmit={handleSubmit}>{/* Your form */}</form>;
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
## Available Hooks
|
|
87
87
|
|
|
88
88
|
### `useAnalytics()`
|
|
89
|
+
|
|
89
90
|
Core analytics hook with full tracking capabilities.
|
|
90
91
|
|
|
91
92
|
```tsx
|
|
92
|
-
import { useAnalytics } from
|
|
93
|
+
import { useAnalytics } from "@akson/cortex-analytics-react";
|
|
93
94
|
|
|
94
95
|
function Component() {
|
|
95
96
|
const analytics = useAnalytics();
|
|
96
|
-
|
|
97
|
+
|
|
97
98
|
// Basic tracking
|
|
98
|
-
analytics.track(
|
|
99
|
-
analytics.trackPageView(
|
|
100
|
-
analytics.trackInteraction(
|
|
101
|
-
|
|
99
|
+
analytics.track("custom_event", { property: "value" });
|
|
100
|
+
analytics.trackPageView("/page", "Page Title");
|
|
101
|
+
analytics.trackInteraction("button", "click", "header_cta");
|
|
102
|
+
|
|
102
103
|
// User identification
|
|
103
|
-
analytics.identify(
|
|
104
|
-
analytics.sendUserData({ email:
|
|
105
|
-
|
|
104
|
+
analytics.identify("user123", { email: "user@example.com" });
|
|
105
|
+
analytics.sendUserData({ email: "user@example.com", phone: "+1234567890" });
|
|
106
|
+
|
|
106
107
|
// Session utilities
|
|
107
108
|
const sessionId = analytics.getSessionId();
|
|
108
109
|
const funnelPath = analytics.getFunnelPath();
|
|
109
110
|
const timeInFunnel = analytics.getTimeInFunnel();
|
|
110
|
-
|
|
111
|
+
|
|
111
112
|
return <div>...</div>;
|
|
112
113
|
}
|
|
113
114
|
```
|
|
114
115
|
|
|
115
116
|
### `useFunnelTracking()`
|
|
117
|
+
|
|
116
118
|
Specialized hook for funnel analysis.
|
|
117
119
|
|
|
118
120
|
```tsx
|
|
119
|
-
import { useFunnelTracking } from
|
|
121
|
+
import { useFunnelTracking } from "@akson/cortex-analytics-react";
|
|
120
122
|
|
|
121
123
|
function OrderForm() {
|
|
122
124
|
const funnel = useFunnelTracking();
|
|
123
|
-
|
|
125
|
+
|
|
124
126
|
const handleStepComplete = (step: string) => {
|
|
125
127
|
funnel.trackStage(step, {
|
|
126
128
|
completion_time: 30,
|
|
127
|
-
source:
|
|
129
|
+
source: "organic",
|
|
128
130
|
});
|
|
129
131
|
};
|
|
130
|
-
|
|
132
|
+
|
|
131
133
|
const handleAbandonment = () => {
|
|
132
|
-
funnel.trackAbandonment(
|
|
134
|
+
funnel.trackAbandonment("step_2", "form_error");
|
|
133
135
|
};
|
|
134
|
-
|
|
136
|
+
|
|
135
137
|
const handleConversion = () => {
|
|
136
|
-
funnel.trackConversion(
|
|
137
|
-
product_type:
|
|
138
|
-
currency:
|
|
138
|
+
funnel.trackConversion("order", 149.9, {
|
|
139
|
+
product_type: "custom_badge",
|
|
140
|
+
currency: "CHF",
|
|
139
141
|
});
|
|
140
142
|
};
|
|
141
|
-
|
|
143
|
+
|
|
142
144
|
return <div>...</div>;
|
|
143
145
|
}
|
|
144
146
|
```
|
|
145
147
|
|
|
146
148
|
### `useLeadTracking()`
|
|
149
|
+
|
|
147
150
|
Hook for lead generation scenarios.
|
|
148
151
|
|
|
149
152
|
```tsx
|
|
150
|
-
import {
|
|
153
|
+
import {
|
|
154
|
+
useLeadTracking,
|
|
155
|
+
LEAD_GENERATION_EVENTS,
|
|
156
|
+
} from "@akson/cortex-analytics-react";
|
|
151
157
|
|
|
152
158
|
function LeadCapture() {
|
|
153
159
|
const lead = useLeadTracking();
|
|
154
|
-
|
|
160
|
+
|
|
155
161
|
const handleFormSubmit = (userData: any) => {
|
|
156
162
|
// Track the lead event
|
|
157
163
|
lead.trackLead(LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED, {
|
|
158
164
|
lead_score: 100,
|
|
159
|
-
source:
|
|
160
|
-
form_type:
|
|
165
|
+
source: "landing_page",
|
|
166
|
+
form_type: "quote_request",
|
|
161
167
|
});
|
|
162
|
-
|
|
168
|
+
|
|
163
169
|
// Send user data for enhanced conversions
|
|
164
170
|
lead.sendUserData({
|
|
165
171
|
email: userData.email,
|
|
@@ -167,33 +173,37 @@ function LeadCapture() {
|
|
|
167
173
|
firstName: userData.firstName,
|
|
168
174
|
});
|
|
169
175
|
};
|
|
170
|
-
|
|
176
|
+
|
|
171
177
|
return <div>...</div>;
|
|
172
178
|
}
|
|
173
179
|
```
|
|
174
180
|
|
|
175
181
|
### `useEcommerceTracking()`
|
|
182
|
+
|
|
176
183
|
Hook for e-commerce events.
|
|
177
184
|
|
|
178
185
|
```tsx
|
|
179
|
-
import {
|
|
186
|
+
import {
|
|
187
|
+
useEcommerceTracking,
|
|
188
|
+
ECOMMERCE_EVENTS,
|
|
189
|
+
} from "@akson/cortex-analytics-react";
|
|
180
190
|
|
|
181
191
|
function ProductPage() {
|
|
182
192
|
const ecommerce = useEcommerceTracking();
|
|
183
|
-
|
|
193
|
+
|
|
184
194
|
const handlePurchase = (orderData: any) => {
|
|
185
195
|
ecommerce.trackEcommerce(ECOMMERCE_EVENTS.PURCHASE, {
|
|
186
196
|
value: orderData.total,
|
|
187
|
-
currency:
|
|
197
|
+
currency: "CHF",
|
|
188
198
|
transaction_id: orderData.id,
|
|
189
|
-
items: orderData.items.map(item => ({
|
|
199
|
+
items: orderData.items.map((item) => ({
|
|
190
200
|
item_name: item.name,
|
|
191
201
|
price: item.price,
|
|
192
202
|
quantity: item.quantity,
|
|
193
203
|
})),
|
|
194
204
|
});
|
|
195
205
|
};
|
|
196
|
-
|
|
206
|
+
|
|
197
207
|
return <div>...</div>;
|
|
198
208
|
}
|
|
199
209
|
```
|
|
@@ -243,24 +253,27 @@ interface FunnelConfig {
|
|
|
243
253
|
|
|
244
254
|
## Standardized Events
|
|
245
255
|
|
|
246
|
-
The package uses standardized events from `@akson/cortex-
|
|
256
|
+
The package uses standardized events from `@akson/cortex-utilities`:
|
|
247
257
|
|
|
248
258
|
```typescript
|
|
249
|
-
import {
|
|
259
|
+
import {
|
|
260
|
+
LEAD_GENERATION_EVENTS,
|
|
261
|
+
ECOMMERCE_EVENTS,
|
|
262
|
+
} from "@akson/cortex-analytics-react";
|
|
250
263
|
|
|
251
264
|
// Lead generation events (scored 1-100)
|
|
252
|
-
LEAD_GENERATION_EVENTS.LEAD_PAGE_VIEW
|
|
253
|
-
LEAD_GENERATION_EVENTS.LEAD_CONTENT_VIEW
|
|
254
|
-
LEAD_GENERATION_EVENTS.LEAD_INQUIRY_STARTED
|
|
255
|
-
LEAD_GENERATION_EVENTS.LEAD_CONTACT_INFO
|
|
256
|
-
LEAD_GENERATION_EVENTS.LEAD_WHATSAPP_CONTACT
|
|
257
|
-
LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED
|
|
265
|
+
LEAD_GENERATION_EVENTS.LEAD_PAGE_VIEW; // Score: 5
|
|
266
|
+
LEAD_GENERATION_EVENTS.LEAD_CONTENT_VIEW; // Score: 15
|
|
267
|
+
LEAD_GENERATION_EVENTS.LEAD_INQUIRY_STARTED; // Score: 40
|
|
268
|
+
LEAD_GENERATION_EVENTS.LEAD_CONTACT_INFO; // Score: 60
|
|
269
|
+
LEAD_GENERATION_EVENTS.LEAD_WHATSAPP_CONTACT; // Score: 85
|
|
270
|
+
LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED; // Score: 100
|
|
258
271
|
|
|
259
272
|
// E-commerce events (with monetary values)
|
|
260
|
-
ECOMMERCE_EVENTS.VIEW_ITEM
|
|
261
|
-
ECOMMERCE_EVENTS.ADD_TO_CART
|
|
262
|
-
ECOMMERCE_EVENTS.BEGIN_CHECKOUT
|
|
263
|
-
ECOMMERCE_EVENTS.PURCHASE
|
|
273
|
+
ECOMMERCE_EVENTS.VIEW_ITEM; // Product views
|
|
274
|
+
ECOMMERCE_EVENTS.ADD_TO_CART; // Cart additions
|
|
275
|
+
ECOMMERCE_EVENTS.BEGIN_CHECKOUT; // Checkout started
|
|
276
|
+
ECOMMERCE_EVENTS.PURCHASE; // Completed transactions
|
|
264
277
|
```
|
|
265
278
|
|
|
266
279
|
## Migration from Landing Analytics
|
|
@@ -269,16 +282,19 @@ If migrating from the landing page analytics system:
|
|
|
269
282
|
|
|
270
283
|
```tsx
|
|
271
284
|
// OLD: Landing-specific analytics
|
|
272
|
-
import { Analytics, FUNNEL_STAGES } from
|
|
285
|
+
import { Analytics, FUNNEL_STAGES } from "@/app/lib/analytics";
|
|
273
286
|
|
|
274
287
|
// NEW: @akson/cortex-analytics-react
|
|
275
|
-
import {
|
|
288
|
+
import {
|
|
289
|
+
useAnalytics,
|
|
290
|
+
LEAD_GENERATION_EVENTS,
|
|
291
|
+
} from "@akson/cortex-analytics-react";
|
|
276
292
|
|
|
277
293
|
function Component() {
|
|
278
294
|
const analytics = useAnalytics();
|
|
279
|
-
|
|
295
|
+
|
|
280
296
|
// OLD: Analytics.trackStage(FUNNEL_STAGES.FORM_SUBMITTED)
|
|
281
|
-
// NEW:
|
|
297
|
+
// NEW:
|
|
282
298
|
analytics.track(LEAD_GENERATION_EVENTS.LEAD_FORM_SUBMITTED, {
|
|
283
299
|
lead_score: 100,
|
|
284
300
|
});
|
|
@@ -317,14 +333,16 @@ The package follows a layered architecture:
|
|
|
317
333
|
## Dependencies
|
|
318
334
|
|
|
319
335
|
### Peer Dependencies
|
|
336
|
+
|
|
320
337
|
- `react ^18.0.0`
|
|
321
338
|
- `react-dom ^18.0.0`
|
|
322
339
|
|
|
323
340
|
### Dependencies
|
|
324
|
-
|
|
325
|
-
- `@akson/cortex-
|
|
326
|
-
- `@akson/cortex-
|
|
341
|
+
|
|
342
|
+
- `@akson/cortex-utilities` - Standardized event definitions
|
|
343
|
+
- `@akson/cortex-gtm` - GTM API client
|
|
344
|
+
- `@akson/cortex-posthog` - PostHog API client
|
|
327
345
|
|
|
328
346
|
## License
|
|
329
347
|
|
|
330
|
-
MIT
|
|
348
|
+
MIT
|