@aacigroup/aaci_shared 1.0.6 → 2.0.1
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 +67 -207
- package/dist/Environment.d.ts +11 -0
- package/dist/Environment.d.ts.map +1 -0
- package/dist/Environment.js +29 -0
- package/dist/Environment.js.map +1 -0
- package/dist/GTM.d.ts +17 -0
- package/dist/GTM.d.ts.map +1 -0
- package/dist/GTM.js +45 -0
- package/dist/GTM.js.map +1 -0
- package/dist/{track/trackLead.d.ts → LeadTracker.d.ts} +24 -9
- package/dist/LeadTracker.d.ts.map +1 -0
- package/dist/LeadTracker.js +202 -0
- package/dist/LeadTracker.js.map +1 -0
- package/dist/PostHog.d.ts +33 -0
- package/dist/PostHog.d.ts.map +1 -0
- package/dist/PostHog.js +202 -0
- package/dist/PostHog.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/track/environment.d.ts +0 -10
- package/dist/track/environment.d.ts.map +0 -1
- package/dist/track/environment.js +0 -63
- package/dist/track/environment.js.map +0 -1
- package/dist/track/errorTracking.d.ts +0 -12
- package/dist/track/errorTracking.d.ts.map +0 -1
- package/dist/track/errorTracking.js +0 -120
- package/dist/track/errorTracking.js.map +0 -1
- package/dist/track/posthog.d.ts +0 -9
- package/dist/track/posthog.d.ts.map +0 -1
- package/dist/track/posthog.js +0 -91
- package/dist/track/posthog.js.map +0 -1
- package/dist/track/trackEventGTM.d.ts +0 -7
- package/dist/track/trackEventGTM.d.ts.map +0 -1
- package/dist/track/trackEventGTM.js +0 -18
- package/dist/track/trackEventGTM.js.map +0 -1
- package/dist/track/trackEventPostHog.d.ts +0 -2
- package/dist/track/trackEventPostHog.d.ts.map +0 -1
- package/dist/track/trackEventPostHog.js +0 -26
- package/dist/track/trackEventPostHog.js.map +0 -1
- package/dist/track/trackLead.d.ts.map +0 -1
- package/dist/track/trackLead.js +0 -190
- package/dist/track/trackLead.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# AACI Shared Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Simple TypeScript/JavaScript library for tracking and analytics in AACI Group projects.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/@aacigroup%2Faaci_shared)
|
|
6
|
-
[](https://github.com/AACI-Group/aaci_shared/actions)
|
|
7
6
|
|
|
8
7
|
## Installation
|
|
9
8
|
|
|
@@ -11,236 +10,97 @@ A shared TypeScript/JavaScript library for AACI Group projects containing tracki
|
|
|
11
10
|
npm install @aacigroup/aaci_shared
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
- **Environment Detection**: Cross-platform environment detection using NODE_ENV
|
|
17
|
-
- **PostHog Analytics**: Easy PostHog initialization and event tracking
|
|
18
|
-
- **Google Tag Manager**: GTM event tracking utilities
|
|
19
|
-
- **Error Tracking**: Comprehensive error monitoring and reporting
|
|
20
|
-
- **Lead Tracking**: Lead capture with session data collection
|
|
21
|
-
|
|
22
|
-
## Environment Variables
|
|
23
|
-
|
|
24
|
-
For proper functionality, you need to set these environment variables in your Vite-based application:
|
|
25
|
-
|
|
26
|
-
### Vite Environment Variables (Frontend)
|
|
27
|
-
```bash
|
|
28
|
-
# PostHog API key (required for analytics)
|
|
29
|
-
VITE_POSTHOG_KEY=phc_your_posthog_key_here
|
|
30
|
-
|
|
31
|
-
# PostHog API host URL (optional, defaults to https://us.i.posthog.com)
|
|
32
|
-
VITE_POSTHOG_API_HOST=https://us.i.posthog.com
|
|
33
|
-
|
|
34
|
-
# Project name (required)
|
|
35
|
-
VITE_PROJECT_NAME=your-project-name
|
|
36
|
-
|
|
37
|
-
# Lead capture API URL (required for lead tracking)
|
|
38
|
-
VITE_LEAD_CAPTURE_API_URL=https://your-api.com/leads
|
|
39
|
-
|
|
40
|
-
# Lead capture API key (required for lead tracking)
|
|
41
|
-
VITE_LEAD_CAPTURE_API_KEY=your_api_key_here
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Important:** All environment variables must be prefixed with `VITE_` to be available in the frontend. This is a Vite requirement for security.
|
|
45
|
-
|
|
46
|
-
### Troubleshooting Environment Variables
|
|
47
|
-
|
|
48
|
-
If you get errors like "Missing required environment variable: VITE_LEAD_CAPTURE_API_URL", try these steps:
|
|
49
|
-
|
|
50
|
-
1. **Verify your .env file:**
|
|
51
|
-
```bash
|
|
52
|
-
# Make sure your .env file contains:
|
|
53
|
-
VITE_LEAD_CAPTURE_API_URL=https://your-api.com/leads
|
|
54
|
-
VITE_LEAD_CAPTURE_API_KEY=your_secret_key
|
|
55
|
-
VITE_POSTHOG_KEY=phc_your_key
|
|
56
|
-
VITE_PROJECT_NAME=your_project
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
2. **For Vite apps, inject manually if needed:**
|
|
60
|
-
```javascript
|
|
61
|
-
// In your main.js or App.js, before importing AACI shared:
|
|
62
|
-
window.__ENV__ = {
|
|
63
|
-
VITE_POSTHOG_KEY: import.meta.env.VITE_POSTHOG_KEY,
|
|
64
|
-
VITE_PROJECT_NAME: import.meta.env.VITE_PROJECT_NAME,
|
|
65
|
-
VITE_LEAD_CAPTURE_API_URL: import.meta.env.VITE_LEAD_CAPTURE_API_URL,
|
|
66
|
-
VITE_LEAD_CAPTURE_API_KEY: import.meta.env.VITE_LEAD_CAPTURE_API_KEY,
|
|
67
|
-
};
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
3. **Check browser console for debug info:**
|
|
71
|
-
The library logs available environment variables to help debug issues.
|
|
72
|
-
|
|
73
|
-
## Usage
|
|
74
|
-
|
|
75
|
-
### Environment Configuration
|
|
76
|
-
|
|
77
|
-
The library works in both browser and Node.js environments and uses `NODE_ENV` for environment detection:
|
|
13
|
+
## Quick Start
|
|
78
14
|
|
|
15
|
+
### Lead Tracking
|
|
79
16
|
```javascript
|
|
80
|
-
import {
|
|
17
|
+
import { LeadTracker } from '@aacigroup/aaci_shared';
|
|
18
|
+
|
|
19
|
+
const leadTracker = new LeadTracker({
|
|
20
|
+
apiUrl: 'https://your-api.com/leads',
|
|
21
|
+
apiKey: 'your-api-key',
|
|
22
|
+
projectName: 'MyProject',
|
|
23
|
+
productionDomains: ['myproject.com']
|
|
24
|
+
});
|
|
81
25
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
26
|
+
await leadTracker.trackLead({
|
|
27
|
+
lead_type: 'signup',
|
|
28
|
+
email: 'user@example.com',
|
|
29
|
+
session_data: leadTracker.getSessionData()
|
|
30
|
+
});
|
|
85
31
|
```
|
|
86
32
|
|
|
87
33
|
### PostHog Analytics
|
|
88
|
-
|
|
89
34
|
```javascript
|
|
90
|
-
import {
|
|
35
|
+
import { PostHog } from '@aacigroup/aaci_shared';
|
|
91
36
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
projectName: 'your-project' // optional, overrides VITE_PROJECT_NAME
|
|
37
|
+
const analytics = new PostHog({
|
|
38
|
+
apiKey: 'phc_your_key',
|
|
39
|
+
projectName: 'MyProject',
|
|
40
|
+
productionDomains: ['myproject.com']
|
|
97
41
|
});
|
|
98
42
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
page: 'homepage'
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Identify user
|
|
106
|
-
identifyUser('user123', {
|
|
107
|
-
name: 'John Doe',
|
|
108
|
-
email: 'john@example.com'
|
|
109
|
-
});
|
|
43
|
+
await analytics.init();
|
|
44
|
+
analytics.trackEvent('user_signup', { plan: 'premium' });
|
|
45
|
+
analytics.trackError(error, 'context'); // Built-in error tracking
|
|
110
46
|
```
|
|
111
47
|
|
|
112
48
|
### Google Tag Manager
|
|
113
|
-
|
|
114
49
|
```javascript
|
|
115
|
-
import {
|
|
50
|
+
import { GTM } from '@aacigroup/aaci_shared';
|
|
116
51
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
page_location: window.location.href
|
|
52
|
+
const gtm = new GTM({
|
|
53
|
+
productionDomains: ['myproject.com']
|
|
120
54
|
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### Error Tracking
|
|
124
|
-
|
|
125
|
-
```javascript
|
|
126
|
-
import { initErrorTracking, trackError, trackAPIError } from '@aacigroup/aaci_shared';
|
|
127
55
|
|
|
128
|
-
|
|
129
|
-
initErrorTracking();
|
|
130
|
-
|
|
131
|
-
// Manual error tracking
|
|
132
|
-
try {
|
|
133
|
-
// Some code that might throw
|
|
134
|
-
} catch (error) {
|
|
135
|
-
trackError(error, 'user_action', { action: 'form_submit' });
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// API error tracking
|
|
139
|
-
trackAPIError('/api/users', 500, 'Internal Server Error', 'Error details...');
|
|
56
|
+
gtm.trackEvent('purchase', { value: 100, currency: 'USD' });
|
|
140
57
|
```
|
|
141
58
|
|
|
142
|
-
###
|
|
143
|
-
|
|
59
|
+
### Environment Detection
|
|
144
60
|
```javascript
|
|
145
|
-
import {
|
|
146
|
-
|
|
147
|
-
// Get browser session data
|
|
148
|
-
const sessionData = getSessionData();
|
|
149
|
-
|
|
150
|
-
// Track a lead using environment variables (VITE_LEAD_CAPTURE_API_URL and VITE_LEAD_CAPTURE_API_KEY)
|
|
151
|
-
try {
|
|
152
|
-
const result = await trackLead({
|
|
153
|
-
project_name: 'my-project',
|
|
154
|
-
lead_type: 'hero_newsletter_signup',
|
|
155
|
-
email: 'user@example.com',
|
|
156
|
-
first_name: 'John',
|
|
157
|
-
last_name: 'Doe',
|
|
158
|
-
session_data: sessionData
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (result.status === 'ok') {
|
|
162
|
-
console.log('Lead tracked successfully');
|
|
163
|
-
} else {
|
|
164
|
-
console.error('Lead tracking failed:', result.message);
|
|
165
|
-
}
|
|
166
|
-
} catch (error) {
|
|
167
|
-
// This will show detailed error messages like:
|
|
168
|
-
// "Missing required environment variable: VITE_LEAD_CAPTURE_API_URL"
|
|
169
|
-
console.error('Lead tracking failed:', error.message);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Or override with custom API URL and key
|
|
173
|
-
const result = await trackLead({
|
|
174
|
-
project_name: 'my-project',
|
|
175
|
-
lead_type: 'hero_newsletter_signup',
|
|
176
|
-
email: 'user@example.com',
|
|
177
|
-
first_name: 'John',
|
|
178
|
-
last_name: 'Doe',
|
|
179
|
-
session_data: sessionData,
|
|
180
|
-
api_url: 'https://custom-api.example.com/leads', // overrides VITE_LEAD_CAPTURE_API_URL
|
|
181
|
-
api_key: 'your-custom-api-key' // overrides VITE_LEAD_CAPTURE_API_KEY
|
|
182
|
-
});
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## Browser Environment Setup
|
|
61
|
+
import { Environment } from '@aacigroup/aaci_shared';
|
|
186
62
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// Set environment variables globally in browser (if not using Vite's built-in injection)
|
|
191
|
-
window.__ENV__ = {
|
|
192
|
-
VITE_POSTHOG_KEY: 'your-key',
|
|
193
|
-
VITE_POSTHOG_API_HOST: 'https://us.i.posthog.com', // optional
|
|
194
|
-
VITE_PROJECT_NAME: 'your-project',
|
|
195
|
-
VITE_LEAD_CAPTURE_API_URL: 'https://api.example.com/leads',
|
|
196
|
-
VITE_LEAD_CAPTURE_API_KEY: 'your-key'
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// Or set NODE_ENV
|
|
200
|
-
window.__NODE_ENV__ = 'production';
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
For Node.js environments (server-side), use standard environment variables:
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
NODE_ENV=production
|
|
207
|
-
# Note: VITE_ variables are not needed in Node.js server environments
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## TypeScript Support
|
|
211
|
-
|
|
212
|
-
The library is written in TypeScript and includes full type definitions:
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
import { TrackLeadParams, SessionData, Address } from '@aacigroup/aaci_shared';
|
|
63
|
+
const env = new Environment({
|
|
64
|
+
productionDomains: ['myproject.com']
|
|
65
|
+
});
|
|
216
66
|
|
|
217
|
-
|
|
218
|
-
project_name: 'my-project',
|
|
219
|
-
lead_type: 'waitlist_signup',
|
|
220
|
-
email: 'user@example.com'
|
|
221
|
-
};
|
|
67
|
+
console.log('Is production:', env.isProduction());
|
|
222
68
|
```
|
|
223
69
|
|
|
224
|
-
##
|
|
225
|
-
|
|
226
|
-
- Modern browsers with ES2015+ support
|
|
227
|
-
- Works with bundlers like Webpack, Vite, Rollup
|
|
228
|
-
- Compatible with React, Vue, Angular, and vanilla JavaScript
|
|
229
|
-
|
|
230
|
-
## Development & Deployment
|
|
231
|
-
|
|
232
|
-
This package uses **automated deployment** via GitHub Actions:
|
|
233
|
-
|
|
234
|
-
- ✅ **Automatic versioning** based on conventional commits
|
|
235
|
-
- ✅ **NPM publishing** on main branch updates
|
|
236
|
-
- ✅ **GitHub releases** with changelogs
|
|
237
|
-
|
|
238
|
-
### Version Bumping Rules:
|
|
239
|
-
- `feat:` → Minor release (1.0.0 → 1.1.0)
|
|
240
|
-
- `fix:`, `docs:`, `chore:` → Patch release (1.0.0 → 1.0.1)
|
|
241
|
-
- `BREAKING CHANGE` or `feat!:` → Major release (1.0.0 → 2.0.0)
|
|
70
|
+
## Features
|
|
242
71
|
|
|
243
|
-
|
|
72
|
+
- **No Environment Variables** - Configuration-based setup
|
|
73
|
+
- **Domain-Based Production Detection** - Automatic environment detection
|
|
74
|
+
- **Built-in Error Tracking** - Error tracking integrated with PostHog
|
|
75
|
+
- **TypeScript Support** - Full type definitions
|
|
76
|
+
- **Framework Agnostic** - Works with any JS framework
|
|
77
|
+
- **Lovable.dev Compatible** - Works perfectly in Lovable environment
|
|
78
|
+
|
|
79
|
+
## API Reference
|
|
80
|
+
|
|
81
|
+
### LeadTracker
|
|
82
|
+
- `new LeadTracker(config)` - Initialize with API URL, key, project name, and production domains
|
|
83
|
+
- `trackLead(params)` - Track a lead with email/phone and session data
|
|
84
|
+
- `getSessionData()` - Get browser session data
|
|
85
|
+
- `isProduction()` - Check if running in production
|
|
86
|
+
|
|
87
|
+
### PostHog
|
|
88
|
+
- `new PostHog(config)` - Initialize with API key, project name, and production domains
|
|
89
|
+
- `init()` - Initialize PostHog
|
|
90
|
+
- `trackEvent(name, properties)` - Track an event
|
|
91
|
+
- `identify(userId, properties)` - Identify a user
|
|
92
|
+
- `trackError(error, context)` - Track errors
|
|
93
|
+
- `trackAPIError(url, status, message)` - Track API errors
|
|
94
|
+
|
|
95
|
+
### GTM
|
|
96
|
+
- `new GTM(config)` - Initialize with production domains
|
|
97
|
+
- `trackEvent(name, data)` - Track event to Google Tag Manager
|
|
98
|
+
- `isAvailable()` - Check if GTM is loaded
|
|
99
|
+
|
|
100
|
+
### Environment
|
|
101
|
+
- `new Environment(config)` - Initialize with production domains
|
|
102
|
+
- `isProduction()` - Check if current domain is production
|
|
103
|
+
- `getCurrentDomain()` - Get current domain
|
|
244
104
|
|
|
245
105
|
## License
|
|
246
106
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface EnvironmentConfig {
|
|
2
|
+
productionDomains: string[];
|
|
3
|
+
}
|
|
4
|
+
export declare class Environment {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: EnvironmentConfig);
|
|
7
|
+
private validateConfig;
|
|
8
|
+
isProduction(): boolean;
|
|
9
|
+
getCurrentDomain(): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Environment.d.ts","sourceRoot":"","sources":["../src/Environment.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,EAAE,iBAAiB;IAKrC,OAAO,CAAC,cAAc;IASf,YAAY,IAAI,OAAO;IAavB,gBAAgB,IAAI,MAAM;CAMlC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Environment = void 0;
|
|
4
|
+
class Environment {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.validateConfig();
|
|
8
|
+
}
|
|
9
|
+
validateConfig() {
|
|
10
|
+
if (!Array.isArray(this.config.productionDomains)) {
|
|
11
|
+
throw new Error('Environment: productionDomains must be an array');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
isProduction() {
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const currentDomain = window.location.hostname;
|
|
19
|
+
return this.config.productionDomains.includes(currentDomain);
|
|
20
|
+
}
|
|
21
|
+
getCurrentDomain() {
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
return 'server';
|
|
24
|
+
}
|
|
25
|
+
return window.location.hostname;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Environment = Environment;
|
|
29
|
+
//# sourceMappingURL=Environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Environment.js","sourceRoot":"","sources":["../src/Environment.ts"],"names":[],"mappings":";;;AAIA,MAAa,WAAW;IAGtB,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAEO,cAAc;QACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAKM,YAAY;QACjB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAElC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC/D,CAAC;IAKM,gBAAgB;QACrB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAClC,CAAC;CACF;AApCD,kCAoCC"}
|
package/dist/GTM.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface GTMConfig {
|
|
2
|
+
productionDomains: string[];
|
|
3
|
+
}
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
dataLayer?: any[];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare class GTM {
|
|
10
|
+
private environment;
|
|
11
|
+
constructor(config: GTMConfig);
|
|
12
|
+
isProduction(): boolean;
|
|
13
|
+
trackEvent(eventName: string, data?: Record<string, any>): void;
|
|
14
|
+
isAvailable(): boolean;
|
|
15
|
+
initDataLayer(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=GTM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GTM.d.ts","sourceRoot":"","sources":["../src/GTM.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACxB,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;KACnB;CACF;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAc;gBAErB,MAAM,EAAE,SAAS;IAOtB,YAAY,IAAI,OAAO;IAOvB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IA4B/D,WAAW,IAAI,OAAO;IAOtB,aAAa,IAAI,IAAI;CAM7B"}
|
package/dist/GTM.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GTM = void 0;
|
|
4
|
+
const Environment_1 = require("./Environment");
|
|
5
|
+
class GTM {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.environment = new Environment_1.Environment({ productionDomains: config.productionDomains });
|
|
8
|
+
}
|
|
9
|
+
isProduction() {
|
|
10
|
+
return this.environment.isProduction();
|
|
11
|
+
}
|
|
12
|
+
trackEvent(eventName, data) {
|
|
13
|
+
if (typeof window !== 'undefined' && window.dataLayer) {
|
|
14
|
+
const eventData = {
|
|
15
|
+
event: eventName,
|
|
16
|
+
is_production: this.isProduction(),
|
|
17
|
+
current_domain: this.environment.getCurrentDomain(),
|
|
18
|
+
timestamp: new Date().toISOString(),
|
|
19
|
+
...data
|
|
20
|
+
};
|
|
21
|
+
window.dataLayer.push(eventData);
|
|
22
|
+
console.log(`[GTM] Event tracked: ${eventName}`, eventData);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.warn('[GTM] Google Tag Manager not available - dataLayer not found');
|
|
26
|
+
console.log('[GTM] Would track event:', {
|
|
27
|
+
event: eventName,
|
|
28
|
+
is_production: this.isProduction(),
|
|
29
|
+
current_domain: this.environment.getCurrentDomain(),
|
|
30
|
+
...data
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
isAvailable() {
|
|
35
|
+
return typeof window !== 'undefined' && Array.isArray(window.dataLayer);
|
|
36
|
+
}
|
|
37
|
+
initDataLayer() {
|
|
38
|
+
if (typeof window !== 'undefined' && !window.dataLayer) {
|
|
39
|
+
window.dataLayer = [];
|
|
40
|
+
console.log('[GTM] DataLayer initialized');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.GTM = GTM;
|
|
45
|
+
//# sourceMappingURL=GTM.js.map
|
package/dist/GTM.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GTM.js","sourceRoot":"","sources":["../src/GTM.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAY5C,MAAa,GAAG;IAGd,YAAY,MAAiB;QAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACtF,CAAC;IAKM,YAAY;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;IACzC,CAAC;IAKM,UAAU,CAAC,SAAiB,EAAE,IAA0B;QAC7D,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACtD,MAAM,SAAS,GAAG;gBAChB,KAAK,EAAE,SAAS;gBAChB,aAAa,EAAE,IAAI,CAAC,YAAY,EAAE;gBAClC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBACnD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,GAAG,IAAI;aACR,CAAC;YAEF,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,EAAE,EAAE,SAAS,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;YAG7E,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE;gBACtC,KAAK,EAAE,SAAS;gBAChB,aAAa,EAAE,IAAI,CAAC,YAAY,EAAE;gBAClC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBACnD,GAAG,IAAI;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAKM,WAAW;QAChB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1E,CAAC;IAKM,aAAa;QAClB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACvD,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AA1DD,kBA0DC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export interface LeadTrackerConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
projectName: string;
|
|
5
|
+
productionDomains: string[];
|
|
6
|
+
}
|
|
1
7
|
export interface Address {
|
|
2
8
|
full_address: string;
|
|
3
9
|
street_address?: string;
|
|
@@ -30,7 +36,6 @@ export interface SessionData {
|
|
|
30
36
|
fbp?: string;
|
|
31
37
|
}
|
|
32
38
|
export interface TrackLeadParams {
|
|
33
|
-
project_name: string;
|
|
34
39
|
lead_type: string;
|
|
35
40
|
first_name?: string;
|
|
36
41
|
last_name?: string;
|
|
@@ -39,12 +44,22 @@ export interface TrackLeadParams {
|
|
|
39
44
|
address?: Address;
|
|
40
45
|
extra_data?: Record<string, any>;
|
|
41
46
|
session_data?: SessionData;
|
|
42
|
-
api_url?: string;
|
|
43
|
-
api_key?: string;
|
|
44
47
|
}
|
|
45
|
-
export declare
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
export declare class LeadTracker {
|
|
49
|
+
private config;
|
|
50
|
+
private environment;
|
|
51
|
+
constructor(config: LeadTrackerConfig);
|
|
52
|
+
private validateConfig;
|
|
53
|
+
isProduction(): boolean;
|
|
54
|
+
trackLead(params: TrackLeadParams): Promise<{
|
|
55
|
+
status: 'ok' | 'error';
|
|
56
|
+
message?: string;
|
|
57
|
+
}>;
|
|
58
|
+
getSessionData(): SessionData;
|
|
59
|
+
private parseUserAgent;
|
|
60
|
+
private getUrlParam;
|
|
61
|
+
private getCookie;
|
|
62
|
+
private getOrCreateSessionId;
|
|
63
|
+
private getOrCreateDistinctId;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=LeadTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeadTracker.d.ts","sourceRoot":"","sources":["../src/LeadTracker.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,OAAO;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,WAAW,CAAc;gBAErB,MAAM,EAAE,iBAAiB;IAMrC,OAAO,CAAC,cAAc;IAef,YAAY,IAAI,OAAO;IAOjB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAsD/F,cAAc,IAAI,WAAW;IAkDpC,OAAO,CAAC,cAAc;IA6CtB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,oBAAoB;IAW5B,OAAO,CAAC,qBAAqB;CAU9B"}
|