@loamly/tracker 2.0.2 → 2.1.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 +27 -3
- package/dist/index.cjs +395 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.mjs +395 -145
- package/dist/index.mjs.map +1 -1
- package/dist/loamly.iife.global.js +412 -148
- package/dist/loamly.iife.global.js.map +1 -1
- package/dist/loamly.iife.min.global.js +1 -1
- package/dist/loamly.iife.min.global.js.map +1 -1
- package/package.json +1 -1
- package/src/behavioral/form-tracker.ts +5 -0
- package/src/browser.ts +25 -6
- package/src/config.ts +1 -1
- package/src/core.ts +400 -136
- package/src/index.ts +1 -1
- package/src/infrastructure/event-queue.ts +58 -32
- package/src/infrastructure/ping.ts +19 -3
- package/src/types.ts +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loamly/tracker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "See every AI bot that visits your website. ChatGPT, Claude, Perplexity, Gemini — know when they crawl or refer traffic.",
|
|
5
5
|
"author": "Loamly <hello@loamly.ai>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,6 +21,7 @@ export interface FormEvent {
|
|
|
21
21
|
field_type?: string
|
|
22
22
|
time_to_submit_ms?: number
|
|
23
23
|
is_conversion?: boolean
|
|
24
|
+
submit_source?: 'submit' | 'click' | 'thank_you'
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface FormTrackerConfig {
|
|
@@ -152,6 +153,7 @@ export class FormTracker {
|
|
|
152
153
|
form_type: this.detectFormType(form),
|
|
153
154
|
time_to_submit_ms: startTime ? Date.now() - startTime : undefined,
|
|
154
155
|
is_conversion: true,
|
|
156
|
+
submit_source: 'submit',
|
|
155
157
|
})
|
|
156
158
|
}
|
|
157
159
|
|
|
@@ -171,6 +173,7 @@ export class FormTracker {
|
|
|
171
173
|
form_type: 'hubspot',
|
|
172
174
|
time_to_submit_ms: startTime ? Date.now() - startTime : undefined,
|
|
173
175
|
is_conversion: true,
|
|
176
|
+
submit_source: 'click',
|
|
174
177
|
})
|
|
175
178
|
}
|
|
176
179
|
}
|
|
@@ -182,6 +185,7 @@ export class FormTracker {
|
|
|
182
185
|
form_id: 'typeform_embed',
|
|
183
186
|
form_type: 'typeform',
|
|
184
187
|
is_conversion: true,
|
|
188
|
+
submit_source: 'click',
|
|
185
189
|
})
|
|
186
190
|
}
|
|
187
191
|
}
|
|
@@ -269,6 +273,7 @@ export class FormTracker {
|
|
|
269
273
|
form_id: 'page_conversion',
|
|
270
274
|
form_type: 'unknown',
|
|
271
275
|
is_conversion: true,
|
|
276
|
+
submit_source: 'thank_you',
|
|
272
277
|
})
|
|
273
278
|
break
|
|
274
279
|
}
|
package/src/browser.ts
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* <script src="https://app.loamly.ai/t.js?d=your-domain.com"></script>
|
|
10
10
|
*
|
|
11
11
|
* 2. npm with data attributes:
|
|
12
|
-
* <script src="https://cdn.jsdelivr.net/npm/@loamly/tracker"
|
|
12
|
+
* <script src="https://cdn.jsdelivr.net/npm/@loamly/tracker"
|
|
13
|
+
* data-api-key="your-key"
|
|
14
|
+
* data-workspace-id="your-workspace-uuid"></script>
|
|
13
15
|
*
|
|
14
16
|
* 3. Self-hosted with manual init:
|
|
15
17
|
* <script src="/tracker.js"></script>
|
|
@@ -49,7 +51,7 @@ function extractDomainFromScriptUrl(): string | null {
|
|
|
49
51
|
*/
|
|
50
52
|
async function resolveWorkspaceConfig(domain: string): Promise<LoamlyConfig | null> {
|
|
51
53
|
try {
|
|
52
|
-
const response = await fetch(`${DEFAULT_CONFIG.apiHost}${DEFAULT_CONFIG.endpoints.resolve}?
|
|
54
|
+
const response = await fetch(`${DEFAULT_CONFIG.apiHost}${DEFAULT_CONFIG.endpoints.resolve}?d=${encodeURIComponent(domain)}`)
|
|
53
55
|
|
|
54
56
|
if (!response.ok) {
|
|
55
57
|
console.warn('[Loamly] Failed to resolve workspace for domain:', domain)
|
|
@@ -58,9 +60,10 @@ async function resolveWorkspaceConfig(domain: string): Promise<LoamlyConfig | nu
|
|
|
58
60
|
|
|
59
61
|
const data = await response.json()
|
|
60
62
|
|
|
61
|
-
if (data.workspace_id) {
|
|
63
|
+
if (data.workspace_id && data.public_key) {
|
|
62
64
|
return {
|
|
63
|
-
apiKey: data.
|
|
65
|
+
apiKey: data.public_key,
|
|
66
|
+
workspaceId: data.workspace_id,
|
|
64
67
|
apiHost: DEFAULT_CONFIG.apiHost,
|
|
65
68
|
}
|
|
66
69
|
}
|
|
@@ -85,6 +88,10 @@ function extractConfigFromDataAttributes(): LoamlyConfig | null {
|
|
|
85
88
|
if (script.dataset.apiKey) {
|
|
86
89
|
config.apiKey = script.dataset.apiKey
|
|
87
90
|
}
|
|
91
|
+
|
|
92
|
+
if (script.dataset.workspaceId) {
|
|
93
|
+
config.workspaceId = script.dataset.workspaceId
|
|
94
|
+
}
|
|
88
95
|
|
|
89
96
|
if (script.dataset.apiHost) {
|
|
90
97
|
config.apiHost = script.dataset.apiHost
|
|
@@ -102,7 +109,7 @@ function extractConfigFromDataAttributes(): LoamlyConfig | null {
|
|
|
102
109
|
config.disableBehavioral = true
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
if (config.apiKey) {
|
|
112
|
+
if (config.apiKey || config.workspaceId) {
|
|
106
113
|
return config
|
|
107
114
|
}
|
|
108
115
|
}
|
|
@@ -132,8 +139,20 @@ async function autoInit(): Promise<void> {
|
|
|
132
139
|
loamly.init(dataConfig)
|
|
133
140
|
return
|
|
134
141
|
}
|
|
142
|
+
|
|
143
|
+
// Priority 3: URL params (api_key + workspace_id)
|
|
144
|
+
const urlParams = new URLSearchParams(window.location.search)
|
|
145
|
+
const apiKeyParam = urlParams.get('api_key')
|
|
146
|
+
const workspaceIdParam = urlParams.get('workspace_id')
|
|
147
|
+
if (apiKeyParam || workspaceIdParam) {
|
|
148
|
+
loamly.init({
|
|
149
|
+
apiKey: apiKeyParam || undefined,
|
|
150
|
+
workspaceId: workspaceIdParam || undefined,
|
|
151
|
+
})
|
|
152
|
+
return
|
|
153
|
+
}
|
|
135
154
|
|
|
136
|
-
// Priority
|
|
155
|
+
// Priority 4: Current domain auto-detection (for app.loamly.ai hosted script)
|
|
137
156
|
const currentDomain = window.location.hostname
|
|
138
157
|
if (currentDomain && currentDomain !== 'localhost') {
|
|
139
158
|
const resolvedConfig = await resolveWorkspaceConfig(currentDomain)
|