@aranova/tracking-react 0.5.0 → 0.6.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 ADDED
@@ -0,0 +1,114 @@
1
+ # @aranova/tracking-react
2
+
3
+ React tracking and consent utilities for Aranova client sites.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @aranova/tracking-react
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Create one shared tracking module and import the scoped `TrackingProvider` / `useTracking` from that module throughout your app.
14
+
15
+ ```ts
16
+ // src/lib/tracking.ts
17
+ import { createTracking } from '@aranova/tracking-react';
18
+
19
+ export const { TrackingProvider, useTracking } = createTracking({
20
+ apiKey: import.meta.env.VITE_ARANOVA_TRACKING_API_KEY,
21
+ endpoint: import.meta.env.VITE_ARANOVA_TRACKING_ENDPOINT,
22
+ triggers: {
23
+ automatic: {
24
+ page_view: {},
25
+ time_on_site: { thresholdSeconds: 60 },
26
+ specific_page_visit: {
27
+ pages: [{ name: 'contact_page', pathPattern: /^\/(contact|book|get-started)/ }],
28
+ },
29
+ },
30
+ manual: {
31
+ form_submit: {},
32
+ phone_click: {},
33
+ cta_click: {},
34
+ },
35
+ },
36
+ debug: import.meta.env.MODE !== 'production',
37
+ });
38
+ ```
39
+
40
+ Mount the provider at the root of your React tree.
41
+
42
+ ```tsx
43
+ // src/main.tsx
44
+ import { createRoot } from 'react-dom/client';
45
+ import { App } from './App';
46
+ import { TrackingProvider } from './lib/tracking';
47
+
48
+ createRoot(document.getElementById('root')!).render(
49
+ <TrackingProvider gtagId={import.meta.env.VITE_GTAG_ID}>
50
+ <App />
51
+ </TrackingProvider>,
52
+ );
53
+ ```
54
+
55
+ ## Manual Events
56
+
57
+ Manual events must be registered under `triggers.manual` before `trackEvent()` accepts them.
58
+
59
+ ```tsx
60
+ import { useTracking } from './lib/tracking';
61
+
62
+ export function LeadForm() {
63
+ const tracking = useTracking();
64
+
65
+ function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
66
+ const form = event.currentTarget;
67
+ const data = new FormData(form);
68
+
69
+ tracking.trackEvent('form_submit', {
70
+ form: {
71
+ id: form.id,
72
+ action: form.getAttribute('action'),
73
+ fields: [
74
+ {
75
+ name: 'service_interest',
76
+ type: 'select',
77
+ label: 'Service interest',
78
+ value: String(data.get('service_interest') ?? ''),
79
+ },
80
+ {
81
+ name: 'is_existing_patient',
82
+ type: 'checkbox',
83
+ label: 'Existing patient',
84
+ value: data.get('is_existing_patient') === 'on',
85
+ },
86
+ ],
87
+ },
88
+ page: { path: window.location.pathname },
89
+ });
90
+ }
91
+
92
+ return <form id="lead-form" action="/api/lead" onSubmit={handleSubmit}>{/* fields */}</form>;
93
+ }
94
+ ```
95
+
96
+ `fields[].value` can be any JSON value: string, number, boolean, null, array, or object. Values must be JSON-serializable because events are stored as JSONB. Only send reviewed, allowlisted, non-sensitive values; do not send names, emails, phone numbers entered by the visitor, addresses, payment data, medical details, passwords, file contents, or free-text messages.
97
+
98
+ ```tsx
99
+ tracking.trackEvent('phone_click', {
100
+ phone_number: '+14165550199',
101
+ page: { path: window.location.pathname },
102
+ section: 'header',
103
+ });
104
+ ```
105
+
106
+ ## Exports
107
+
108
+ - `createTracking()`
109
+ - `TrackingProvider` and scoped `useTracking`
110
+ - `GoogleAdsTracking`
111
+ - `ConsentBanner`
112
+ - `useTrackingParams()`, `useGclid()`, `useConsentState()`
113
+ - Event metadata/config types such as `FormSubmitMetadata`, `PhoneClickMetadata`, and `JsonValue`
114
+