@entrolytics/vue-sdk 2.2.0 → 3.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 +18 -55
- package/dist/composables/useEntrolytics.d.ts +18 -0
- package/dist/composables/useEntrolytics.d.ts.map +1 -0
- package/dist/composables/useIdentify.d.ts +27 -0
- package/dist/composables/useIdentify.d.ts.map +1 -0
- package/dist/composables/useTrackEvent.d.ts +20 -0
- package/dist/composables/useTrackEvent.d.ts.map +1 -0
- package/dist/composables/useTrackOutboundLink.d.ts +19 -0
- package/dist/composables/useTrackOutboundLink.d.ts.map +1 -0
- package/dist/composables/useTrackPageView.d.ts +30 -0
- package/dist/composables/useTrackPageView.d.ts.map +1 -0
- package/dist/composables/useTrackRevenue.d.ts +23 -0
- package/dist/composables/useTrackRevenue.d.ts.map +1 -0
- package/dist/index.cjs +302 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -230
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +301 -196
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +69 -0
- package/dist/plugin.d.ts.map +1 -0
- package/package.json +30 -29
- package/dist/index.d.cts +0 -230
package/dist/index.js
CHANGED
|
@@ -1,223 +1,328 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { inject, ref, watch } from "vue";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
//#region src/plugin.ts
|
|
4
|
+
const DEFAULT_HOST = "https://api.entrolytics.click";
|
|
5
|
+
const SCRIPT_ID = "entrolytics-script";
|
|
6
|
+
const EntrolyticsKey = Symbol("entrolytics");
|
|
7
7
|
function injectScript(options, onLoad) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
script.src = `${host.replace(/\/$/, "")}${scriptPath}`;
|
|
28
|
-
script.defer = true;
|
|
29
|
-
script.dataset.websiteId = websiteId;
|
|
30
|
-
if (!autoTrack) {
|
|
31
|
-
script.dataset.autoTrack = "false";
|
|
32
|
-
}
|
|
33
|
-
if (respectDnt) {
|
|
34
|
-
script.dataset.doNotTrack = "true";
|
|
35
|
-
}
|
|
36
|
-
if (domains && domains.length > 0) {
|
|
37
|
-
script.dataset.domains = domains.join(",");
|
|
38
|
-
}
|
|
39
|
-
if (tag) {
|
|
40
|
-
script.dataset.tag = tag;
|
|
41
|
-
}
|
|
42
|
-
if (excludeSearch) {
|
|
43
|
-
script.dataset.excludeSearch = "true";
|
|
44
|
-
}
|
|
45
|
-
if (excludeHash) {
|
|
46
|
-
script.dataset.excludeHash = "true";
|
|
47
|
-
}
|
|
48
|
-
script.onload = () => onLoad?.();
|
|
49
|
-
document.head.appendChild(script);
|
|
8
|
+
if (typeof window === "undefined") return;
|
|
9
|
+
if (document.getElementById(SCRIPT_ID)) {
|
|
10
|
+
onLoad?.();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { websiteId, host = DEFAULT_HOST, autoTrack = true, respectDnt = false, domains, tag, excludeSearch = false, excludeHash = false } = options;
|
|
14
|
+
const script = document.createElement("script");
|
|
15
|
+
script.id = SCRIPT_ID;
|
|
16
|
+
script.src = `${host.replace(/\/$/, "")}/script.js`;
|
|
17
|
+
script.defer = true;
|
|
18
|
+
script.dataset.websiteId = websiteId;
|
|
19
|
+
if (!autoTrack) script.dataset.autoTrack = "false";
|
|
20
|
+
if (respectDnt) script.dataset.doNotTrack = "true";
|
|
21
|
+
if (domains && domains.length > 0) script.dataset.domains = domains.join(",");
|
|
22
|
+
if (tag) script.dataset.tag = tag;
|
|
23
|
+
if (excludeSearch) script.dataset.excludeSearch = "true";
|
|
24
|
+
if (excludeHash) script.dataset.excludeHash = "true";
|
|
25
|
+
script.onload = () => onLoad?.();
|
|
26
|
+
document.head.appendChild(script);
|
|
50
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Create Entrolytics Vue plugin
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* Zero-config (reads from import.meta.env):
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { createApp } from 'vue';
|
|
35
|
+
* import { createEntrolytics } from '@entrolytics/vue';
|
|
36
|
+
*
|
|
37
|
+
* const app = createApp(App);
|
|
38
|
+
* app.use(createEntrolytics());
|
|
39
|
+
* app.mount('#app');
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* Explicit config:
|
|
44
|
+
* ```ts
|
|
45
|
+
* const app = createApp(App);
|
|
46
|
+
* app.use(createEntrolytics({ websiteId: 'your-website-id' }));
|
|
47
|
+
* app.mount('#app');
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
51
50
|
function createEntrolytics(options = {}) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
isLoaded.value = true;
|
|
154
|
-
isReady.value = true;
|
|
155
|
-
});
|
|
156
|
-
app.provide(EntrolyticsKey, instance);
|
|
157
|
-
app.config.globalProperties.$entrolytics = instance;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
51
|
+
const env = import.meta.env ?? {};
|
|
52
|
+
const websiteId = options.websiteId || env.VITE_ENTROLYTICS_WEBSITE_ID || env.VITE_PUBLIC_ENTROLYTICS_WEBSITE_ID;
|
|
53
|
+
const host = options.host || env.VITE_ENTROLYTICS_HOST || env.VITE_PUBLIC_ENTROLYTICS_HOST;
|
|
54
|
+
if (!websiteId) {
|
|
55
|
+
if (env.DEV) console.warn("[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option.");
|
|
56
|
+
throw new Error("[@entrolytics/vue] websiteId is required");
|
|
57
|
+
}
|
|
58
|
+
const finalOptions = {
|
|
59
|
+
...options,
|
|
60
|
+
websiteId,
|
|
61
|
+
host: host || options.host
|
|
62
|
+
};
|
|
63
|
+
const isLoaded = ref(false);
|
|
64
|
+
const isReady = ref(false);
|
|
65
|
+
let currentTag = finalOptions.tag;
|
|
66
|
+
const waitForTracker = (callback) => {
|
|
67
|
+
if (typeof window === "undefined") return;
|
|
68
|
+
const tryExecute = () => {
|
|
69
|
+
if (window.entrolytics) callback();
|
|
70
|
+
else setTimeout(tryExecute, 100);
|
|
71
|
+
};
|
|
72
|
+
tryExecute();
|
|
73
|
+
};
|
|
74
|
+
const track = (eventName, eventData) => {
|
|
75
|
+
waitForTracker(() => {
|
|
76
|
+
let payload = {
|
|
77
|
+
name: eventName,
|
|
78
|
+
data: eventData
|
|
79
|
+
};
|
|
80
|
+
if (options.beforeSend) {
|
|
81
|
+
payload = options.beforeSend("event", payload);
|
|
82
|
+
if (payload === null) return;
|
|
83
|
+
}
|
|
84
|
+
if (currentTag) payload.tag = currentTag;
|
|
85
|
+
window.entrolytics?.track(eventName, eventData);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const trackPageView = (url, referrer) => {
|
|
89
|
+
waitForTracker(() => {
|
|
90
|
+
const payload = {};
|
|
91
|
+
if (url) payload.url = url;
|
|
92
|
+
if (referrer) payload.referrer = referrer;
|
|
93
|
+
if (currentTag) payload.tag = currentTag;
|
|
94
|
+
window.entrolytics?.track(payload);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const trackRevenue = (eventName, revenue, currency = "USD", data) => {
|
|
98
|
+
waitForTracker(() => {
|
|
99
|
+
const eventData = {
|
|
100
|
+
...data,
|
|
101
|
+
revenue,
|
|
102
|
+
currency
|
|
103
|
+
};
|
|
104
|
+
if (currentTag) eventData.tag = currentTag;
|
|
105
|
+
window.entrolytics?.track(eventName, eventData);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const trackOutboundLink = (url, data) => {
|
|
109
|
+
waitForTracker(() => {
|
|
110
|
+
window.entrolytics?.track("outbound-link-click", {
|
|
111
|
+
...data,
|
|
112
|
+
url
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const identify = (data) => {
|
|
117
|
+
waitForTracker(() => {
|
|
118
|
+
window.entrolytics?.identify(data);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
const identifyUser = (userId, traits) => {
|
|
122
|
+
waitForTracker(() => {
|
|
123
|
+
window.entrolytics?.identify({
|
|
124
|
+
id: userId,
|
|
125
|
+
...traits
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const setTag = (tag) => {
|
|
130
|
+
currentTag = tag;
|
|
131
|
+
};
|
|
132
|
+
const instance = {
|
|
133
|
+
track,
|
|
134
|
+
trackPageView,
|
|
135
|
+
trackRevenue,
|
|
136
|
+
trackOutboundLink,
|
|
137
|
+
identify,
|
|
138
|
+
identifyUser,
|
|
139
|
+
setTag,
|
|
140
|
+
config: finalOptions,
|
|
141
|
+
isLoaded,
|
|
142
|
+
isReady
|
|
143
|
+
};
|
|
144
|
+
return { install(app) {
|
|
145
|
+
injectScript(finalOptions, () => {
|
|
146
|
+
isLoaded.value = true;
|
|
147
|
+
isReady.value = true;
|
|
148
|
+
});
|
|
149
|
+
app.provide(EntrolyticsKey, instance);
|
|
150
|
+
app.config.globalProperties.$entrolytics = instance;
|
|
151
|
+
} };
|
|
160
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Use Entrolytics instance in composition API
|
|
155
|
+
*/
|
|
161
156
|
function useEntrolyticsInstance() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return instance;
|
|
157
|
+
const instance = inject(EntrolyticsKey);
|
|
158
|
+
if (!instance) throw new Error("[@entrolytics/vue] Entrolytics plugin not installed");
|
|
159
|
+
return instance;
|
|
167
160
|
}
|
|
168
161
|
|
|
169
|
-
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/composables/useEntrolytics.ts
|
|
164
|
+
/**
|
|
165
|
+
* Main composable for accessing Entrolytics functionality
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```vue
|
|
169
|
+
* <script setup>
|
|
170
|
+
* import { useEntrolytics } from '@entrolytics/vue';
|
|
171
|
+
*
|
|
172
|
+
* const { track, identify, isLoaded } = useEntrolytics();
|
|
173
|
+
*
|
|
174
|
+
* function handleClick() {
|
|
175
|
+
* track('button_click', { variant: 'primary' });
|
|
176
|
+
* }
|
|
177
|
+
* <\/script>
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
170
180
|
function useEntrolytics() {
|
|
171
|
-
|
|
181
|
+
return useEntrolyticsInstance();
|
|
172
182
|
}
|
|
173
183
|
|
|
174
|
-
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/composables/useIdentify.ts
|
|
186
|
+
/**
|
|
187
|
+
* Composable for identifying users
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```vue
|
|
191
|
+
* <script setup>
|
|
192
|
+
* import { watch } from 'vue';
|
|
193
|
+
* import { useIdentify } from '@entrolytics/vue';
|
|
194
|
+
*
|
|
195
|
+
* const { identify } = useIdentify();
|
|
196
|
+
* const user = useUser(); // Your auth composable
|
|
197
|
+
*
|
|
198
|
+
* watch(user, (newUser) => {
|
|
199
|
+
* if (newUser) {
|
|
200
|
+
* identify(newUser.id, {
|
|
201
|
+
* email: newUser.email,
|
|
202
|
+
* plan: newUser.subscription
|
|
203
|
+
* });
|
|
204
|
+
* }
|
|
205
|
+
* });
|
|
206
|
+
* <\/script>
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
175
209
|
function useIdentify() {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
identify
|
|
179
|
-
};
|
|
210
|
+
const { identify } = useEntrolyticsInstance();
|
|
211
|
+
return { identify };
|
|
180
212
|
}
|
|
181
213
|
|
|
182
|
-
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/composables/useTrackEvent.ts
|
|
216
|
+
/**
|
|
217
|
+
* Composable for tracking custom events
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```vue
|
|
221
|
+
* <script setup>
|
|
222
|
+
* import { useTrackEvent } from '@entrolytics/vue';
|
|
223
|
+
*
|
|
224
|
+
* const { track } = useTrackEvent();
|
|
225
|
+
*
|
|
226
|
+
* function handlePurchase() {
|
|
227
|
+
* track('purchase', { revenue: 99.99, currency: 'USD' });
|
|
228
|
+
* }
|
|
229
|
+
* <\/script>
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
183
232
|
function useTrackEvent() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
track
|
|
187
|
-
};
|
|
233
|
+
const { track } = useEntrolyticsInstance();
|
|
234
|
+
return { track };
|
|
188
235
|
}
|
|
189
236
|
|
|
190
|
-
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/composables/useTrackOutboundLink.ts
|
|
239
|
+
/**
|
|
240
|
+
* Composable for tracking outbound link clicks
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```vue
|
|
244
|
+
* <script setup>
|
|
245
|
+
* import { useTrackOutboundLink } from '@entrolytics/vue';
|
|
246
|
+
*
|
|
247
|
+
* const trackOutboundLink = useTrackOutboundLink();
|
|
248
|
+
*
|
|
249
|
+
* const handleExternalClick = (url: string) => {
|
|
250
|
+
* trackOutboundLink(url, { placement: 'footer' });
|
|
251
|
+
* };
|
|
252
|
+
* <\/script>
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
191
255
|
function useTrackOutboundLink() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
256
|
+
const { trackOutboundLink } = useEntrolyticsInstance();
|
|
257
|
+
return (url, data) => {
|
|
258
|
+
trackOutboundLink(url, data);
|
|
259
|
+
};
|
|
196
260
|
}
|
|
261
|
+
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/composables/useTrackPageView.ts
|
|
264
|
+
/**
|
|
265
|
+
* Composable for tracking page views with vue-router
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```vue
|
|
269
|
+
* <script setup>
|
|
270
|
+
* import { useRoute } from 'vue-router';
|
|
271
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
272
|
+
*
|
|
273
|
+
* const route = useRoute();
|
|
274
|
+
* useTrackPageView(() => route.path);
|
|
275
|
+
* <\/script>
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```vue
|
|
280
|
+
* <script setup>
|
|
281
|
+
* import { ref } from 'vue';
|
|
282
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
283
|
+
*
|
|
284
|
+
* const currentPath = ref('/');
|
|
285
|
+
* useTrackPageView(currentPath);
|
|
286
|
+
* <\/script>
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
197
289
|
function useTrackPageView(pathSource, options) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (newPath !== oldPath) {
|
|
204
|
-
track("pageview", {
|
|
205
|
-
url: newPath
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
{ immediate }
|
|
210
|
-
);
|
|
290
|
+
const { track } = useEntrolyticsInstance();
|
|
291
|
+
const { immediate = true } = options || {};
|
|
292
|
+
watch(pathSource, (newPath, oldPath) => {
|
|
293
|
+
if (newPath !== oldPath) track("pageview", { url: newPath });
|
|
294
|
+
}, { immediate });
|
|
211
295
|
}
|
|
212
296
|
|
|
213
|
-
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/composables/useTrackRevenue.ts
|
|
299
|
+
/**
|
|
300
|
+
* Composable for tracking revenue events
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```vue
|
|
304
|
+
* <script setup>
|
|
305
|
+
* import { useTrackRevenue } from '@entrolytics/vue';
|
|
306
|
+
*
|
|
307
|
+
* const trackRevenue = useTrackRevenue();
|
|
308
|
+
*
|
|
309
|
+
* const handlePurchase = async (product) => {
|
|
310
|
+
* await processPayment();
|
|
311
|
+
* trackRevenue('purchase', product.price, 'USD', {
|
|
312
|
+
* productId: product.id,
|
|
313
|
+
* productName: product.name
|
|
314
|
+
* });
|
|
315
|
+
* };
|
|
316
|
+
* <\/script>
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
214
319
|
function useTrackRevenue() {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
320
|
+
const { trackRevenue } = useEntrolyticsInstance();
|
|
321
|
+
return (eventName, revenue, currency = "USD", data) => {
|
|
322
|
+
trackRevenue(eventName, revenue, currency, data);
|
|
323
|
+
};
|
|
219
324
|
}
|
|
220
325
|
|
|
326
|
+
//#endregion
|
|
221
327
|
export { EntrolyticsKey, createEntrolytics, useEntrolytics, useEntrolyticsInstance, useIdentify, useTrackEvent, useTrackOutboundLink, useTrackPageView, useTrackRevenue };
|
|
222
|
-
//# sourceMappingURL=index.js.map
|
|
223
328
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts","../src/composables/useEntrolytics.ts","../src/composables/useIdentify.ts","../src/composables/useTrackEvent.ts","../src/composables/useTrackOutboundLink.ts","../src/composables/useTrackPageView.ts","../src/composables/useTrackRevenue.ts"],"names":[],"mappings":";;;AAEA,IAAM,YAAA,GAAe,2BAAA;AACrB,IAAM,SAAA,GAAY,oBAAA;AAqEX,IAAM,cAAA,0BAA2D,aAAa;AAErF,SAAS,YAAA,CAAa,SAA6B,MAAA,EAA2B;AAC5E,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACnC,EAAA,IAAI,QAAA,CAAS,cAAA,CAAe,SAAS,CAAA,EAAG;AACtC,IAAA,MAAA,IAAS;AACT,IAAA;AAAA,EACF;AAEA,EAAA,MAAM;AAAA,IACJ,SA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AA,IACA,EAAE,SAAA;AAAU,GACd;AACF;;;ACvBO,SAAS,eAAA,GAAkB;AAChC,EAAA,MAAM,EAAE,YAAA,EAAa,GAAI,sBAAA,EAAuB;AAChD,EAAA,OAAO,CAAC,SAAA,EAAmB,OAAA,EAAiB,QAAA,GAAW,OAAO,IAAA,KAAqB;AACjF,IAAA,YAAA,CAAa,SAAA,EAAW,OAAA,EAAS,QAAA,EAAU,IAAI,CAAA;AAAA,EACjD,CAAA;AACF","file":"index.js","sourcesContent":["import { type App, type InjectionKey, inject, type Ref, ref } from 'vue';\n\nconst DEFAULT_HOST = 'https://entrolytics.click';\nconst SCRIPT_ID = 'entrolytics-script';\n\n/**\n * Event payload type - mirrors @entrolytics/shared EventPayload\n * TODO: Import from @entrolytics/shared once published with EventPayload export\n */\ninterface EventPayload {\n websiteId: string;\n sessionId: string;\n visitorId: string;\n url: string;\n referrer?: string;\n eventType: string;\n eventName?: string;\n properties?: Record<string, unknown>;\n screenWidth?: number;\n screenHeight?: number;\n loadTime?: number;\n domInteractive?: number;\n domComplete?: number;\n utmSource?: string;\n utmMedium?: string;\n utmCampaign?: string;\n utmTerm?: string;\n utmContent?: string;\n}\n\nexport type EventData = NonNullable<EventPayload['properties']>;\n\nexport interface EntrolyticsOptions {\n websiteId: string;\n host?: string;\n autoTrack?: boolean;\n respectDnt?: boolean;\n domains?: string[];\n /** Use edge runtime endpoints for faster response times (default: true) */\n useEdgeRuntime?: boolean;\n /** Custom tag for A/B testing */\n tag?: string;\n /** Strip query parameters from URLs */\n excludeSearch?: boolean;\n /** Strip hash from URLs */\n excludeHash?: boolean;\n /** Callback before sending data */\n beforeSend?: (type: string, payload: unknown) => unknown | null;\n}\n\nexport interface EntrolyticsInstance {\n track: (eventName: string, eventData?: EventData) => void;\n trackPageView: (url?: string, referrer?: string) => void;\n trackRevenue: (eventName: string, revenue: number, currency?: string, data?: EventData) => void;\n trackOutboundLink: (url: string, data?: EventData) => void;\n identify: (data: EventData) => void;\n identifyUser: (userId: string, traits?: EventData) => void;\n setTag: (tag: string) => void;\n config: EntrolyticsOptions;\n isLoaded: Ref<boolean>;\n isReady: Ref<boolean>;\n}\n\ndeclare global {\n interface Window {\n entrolytics?: {\n track: (eventName?: string | object, eventData?: Record<string, unknown>) => void;\n identify: (data: Record<string, unknown>) => void;\n };\n }\n}\n\nexport const EntrolyticsKey: InjectionKey<EntrolyticsInstance> = Symbol('entrolytics');\n\nfunction injectScript(options: EntrolyticsOptions, onLoad?: () => void): void {\n if (typeof window === 'undefined') return;\n if (document.getElementById(SCRIPT_ID)) {\n onLoad?.();\n return;\n }\n\n const {\n websiteId,\n host = DEFAULT_HOST,\n autoTrack = true,\n respectDnt = false,\n domains,\n useEdgeRuntime = true,\n tag,\n excludeSearch = false,\n excludeHash = false,\n } = options;\n\n const script = document.createElement('script');\n script.id = SCRIPT_ID;\n\n // Use edge runtime script if enabled\n const scriptPath = useEdgeRuntime ? '/script-edge.js' : '/script.js';\n script.src = `${host.replace(/\\/$/, '')}${scriptPath}`;\n script.defer = true;\n script.dataset.websiteId = websiteId;\n\n if (!autoTrack) {\n script.dataset.autoTrack = 'false';\n }\n if (respectDnt) {\n script.dataset.doNotTrack = 'true';\n }\n if (domains && domains.length > 0) {\n script.dataset.domains = domains.join(',');\n }\n if (tag) {\n script.dataset.tag = tag;\n }\n if (excludeSearch) {\n script.dataset.excludeSearch = 'true';\n }\n if (excludeHash) {\n script.dataset.excludeHash = 'true';\n }\n\n script.onload = () => onLoad?.();\n document.head.appendChild(script);\n}\n\n/**\n * Create Entrolytics Vue plugin\n *\n * @example\n * Zero-config (reads from import.meta.env):\n * ```ts\n * import { createApp } from 'vue';\n * import { createEntrolytics } from '@entrolytics/vue';\n *\n * const app = createApp(App);\n * app.use(createEntrolytics());\n * app.mount('#app');\n * ```\n *\n * @example\n * Explicit config:\n * ```ts\n * const app = createApp(App);\n * app.use(createEntrolytics({ websiteId: 'your-website-id' }));\n * app.mount('#app');\n * ```\n */\nexport function createEntrolytics(options: Partial<EntrolyticsOptions> = {}) {\n // Auto-read from environment variables (Vite)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const env = (import.meta as any).env || {};\n const websiteId =\n options.websiteId ||\n env.VITE_ENTROLYTICS_WEBSITE_ID ||\n env.VITE_PUBLIC_ENTROLYTICS_WEBSITE_ID;\n\n const host = options.host || env.VITE_ENTROLYTICS_HOST || env.VITE_PUBLIC_ENTROLYTICS_HOST;\n\n if (!websiteId) {\n if (env.DEV) {\n console.warn(\n '[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option.',\n );\n }\n throw new Error('[@entrolytics/vue] websiteId is required');\n }\n\n const finalOptions: EntrolyticsOptions = {\n ...options,\n websiteId,\n host: host || options.host,\n } as EntrolyticsOptions;\n\n const isLoaded = ref(false);\n const isReady = ref(false);\n let currentTag = finalOptions.tag;\n\n const waitForTracker = (callback: () => void) => {\n if (typeof window === 'undefined') return;\n\n const tryExecute = () => {\n if (window.entrolytics) {\n callback();\n } else {\n setTimeout(tryExecute, 100);\n }\n };\n\n tryExecute();\n };\n\n const track = (eventName: string, eventData?: EventData) => {\n waitForTracker(() => {\n let payload: unknown = { name: eventName, data: eventData };\n\n if (options.beforeSend) {\n payload = options.beforeSend('event', payload);\n if (payload === null) return;\n }\n\n if (currentTag) {\n (payload as Record<string, unknown>).tag = currentTag;\n }\n\n window.entrolytics?.track(eventName, eventData as Record<string, any>);\n });\n };\n\n const trackPageView = (url?: string, referrer?: string) => {\n waitForTracker(() => {\n const payload: Record<string, unknown> = {};\n if (url) payload.url = url;\n if (referrer) payload.referrer = referrer;\n if (currentTag) payload.tag = currentTag;\n\n window.entrolytics?.track(payload);\n });\n };\n\n const trackRevenue = (eventName: string, revenue: number, currency = 'USD', data?: EventData) => {\n waitForTracker(() => {\n const eventData: EventData = {\n ...data,\n revenue,\n currency,\n };\n\n if (currentTag) {\n eventData.tag = currentTag;\n }\n\n window.entrolytics?.track(eventName, eventData);\n });\n };\n\n const trackOutboundLink = (url: string, data?: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.track('outbound-link-click', {\n ...data,\n url,\n });\n });\n };\n\n const identify = (data: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.identify(data);\n });\n };\n\n const identifyUser = (userId: string, traits?: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.identify({ id: userId, ...traits });\n });\n };\n\n const setTag = (tag: string) => {\n currentTag = tag;\n };\n\n const instance: EntrolyticsInstance = {\n track,\n trackPageView,\n trackRevenue,\n trackOutboundLink,\n identify,\n identifyUser,\n setTag,\n config: finalOptions,\n isLoaded,\n isReady,\n };\n\n return {\n install(app: App) {\n // Inject script on mount\n injectScript(finalOptions, () => {\n isLoaded.value = true;\n isReady.value = true;\n });\n\n // Provide instance\n app.provide(EntrolyticsKey, instance);\n\n // Add global property\n app.config.globalProperties.$entrolytics = instance;\n },\n };\n}\n\n/**\n * Use Entrolytics instance in composition API\n */\nexport function useEntrolyticsInstance(): EntrolyticsInstance {\n const instance = inject(EntrolyticsKey);\n if (!instance) {\n throw new Error('[@entrolytics/vue] Entrolytics plugin not installed');\n }\n return instance;\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Main composable for accessing Entrolytics functionality\n *\n * @example\n * ```vue\n * <script setup>\n * import { useEntrolytics } from '@entrolytics/vue';\n *\n * const { track, identify, isLoaded } = useEntrolytics();\n *\n * function handleClick() {\n * track('button_click', { variant: 'primary' });\n * }\n * </script>\n * ```\n */\nexport function useEntrolytics() {\n return useEntrolyticsInstance();\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for identifying users\n *\n * @example\n * ```vue\n * <script setup>\n * import { watch } from 'vue';\n * import { useIdentify } from '@entrolytics/vue';\n *\n * const { identify } = useIdentify();\n * const user = useUser(); // Your auth composable\n *\n * watch(user, (newUser) => {\n * if (newUser) {\n * identify(newUser.id, {\n * email: newUser.email,\n * plan: newUser.subscription\n * });\n * }\n * });\n * </script>\n * ```\n */\nexport function useIdentify() {\n const { identify } = useEntrolyticsInstance();\n\n return {\n identify,\n };\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking custom events\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackEvent } from '@entrolytics/vue';\n *\n * const { track } = useTrackEvent();\n *\n * function handlePurchase() {\n * track('purchase', { revenue: 99.99, currency: 'USD' });\n * }\n * </script>\n * ```\n */\nexport function useTrackEvent() {\n const { track } = useEntrolyticsInstance();\n\n return {\n track,\n };\n}\n","import type { EventData } from '../plugin.js';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking outbound link clicks\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackOutboundLink } from '@entrolytics/vue';\n *\n * const trackOutboundLink = useTrackOutboundLink();\n *\n * const handleExternalClick = (url: string) => {\n * trackOutboundLink(url, { placement: 'footer' });\n * };\n * </script>\n * ```\n */\nexport function useTrackOutboundLink() {\n const { trackOutboundLink } = useEntrolyticsInstance();\n return (url: string, data?: EventData) => {\n trackOutboundLink(url, data);\n };\n}\n","import { type Ref, watch } from 'vue';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking page views with vue-router\n *\n * @example\n * ```vue\n * <script setup>\n * import { useRoute } from 'vue-router';\n * import { useTrackPageView } from '@entrolytics/vue';\n *\n * const route = useRoute();\n * useTrackPageView(() => route.path);\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue';\n * import { useTrackPageView } from '@entrolytics/vue';\n *\n * const currentPath = ref('/');\n * useTrackPageView(currentPath);\n * </script>\n * ```\n */\nexport function useTrackPageView(\n pathSource: Ref<string> | (() => string),\n options?: { immediate?: boolean },\n) {\n const { track } = useEntrolyticsInstance();\n const { immediate = true } = options || {};\n\n watch(\n pathSource,\n (newPath, oldPath) => {\n if (newPath !== oldPath) {\n track('pageview', {\n url: newPath,\n });\n }\n },\n { immediate },\n );\n}\n","import type { EventData } from '../plugin.js';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking revenue events\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackRevenue } from '@entrolytics/vue';\n *\n * const trackRevenue = useTrackRevenue();\n *\n * const handlePurchase = async (product) => {\n * await processPayment();\n * trackRevenue('purchase', product.price, 'USD', {\n * productId: product.id,\n * productName: product.name\n * });\n * };\n * </script>\n * ```\n */\nexport function useTrackRevenue() {\n const { trackRevenue } = useEntrolyticsInstance();\n return (eventName: string, revenue: number, currency = 'USD', data?: EventData) => {\n trackRevenue(eventName, revenue, currency, data);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts","../src/composables/useEntrolytics.ts","../src/composables/useIdentify.ts","../src/composables/useTrackEvent.ts","../src/composables/useTrackOutboundLink.ts","../src/composables/useTrackPageView.ts","../src/composables/useTrackRevenue.ts"],"sourcesContent":["import type { EventPayload } from '@entrolytics/shared';\nimport { type App, type InjectionKey, inject, type Ref, ref } from 'vue';\n\nconst DEFAULT_HOST = 'https://api.entrolytics.click';\nconst SCRIPT_ID = 'entrolytics-script';\n\nexport type EventData = NonNullable<EventPayload['properties']>;\n\nexport interface EntrolyticsOptions {\n websiteId: string;\n host?: string;\n autoTrack?: boolean;\n respectDnt?: boolean;\n domains?: string[];\n /** Custom tag for A/B testing */\n tag?: string;\n /** Strip query parameters from URLs */\n excludeSearch?: boolean;\n /** Strip hash from URLs */\n excludeHash?: boolean;\n /** Callback before sending data */\n beforeSend?: (type: string, payload: unknown) => unknown | null;\n}\n\nexport interface EntrolyticsInstance {\n track: (eventName: string, eventData?: EventData) => void;\n trackPageView: (url?: string, referrer?: string) => void;\n trackRevenue: (eventName: string, revenue: number, currency?: string, data?: EventData) => void;\n trackOutboundLink: (url: string, data?: EventData) => void;\n identify: (data: EventData) => void;\n identifyUser: (userId: string, traits?: EventData) => void;\n setTag: (tag: string) => void;\n config: EntrolyticsOptions;\n isLoaded: Ref<boolean>;\n isReady: Ref<boolean>;\n}\n\ndeclare global {\n interface Window {\n entrolytics?: {\n track: (eventName?: string | object, eventData?: Record<string, unknown>) => void;\n identify: (data: Record<string, unknown>) => void;\n };\n }\n}\n\nexport const EntrolyticsKey: InjectionKey<EntrolyticsInstance> = Symbol('entrolytics');\n\nfunction injectScript(options: EntrolyticsOptions, onLoad?: () => void): void {\n if (typeof window === 'undefined') return;\n if (document.getElementById(SCRIPT_ID)) {\n onLoad?.();\n return;\n }\n\n const {\n websiteId,\n host = DEFAULT_HOST,\n autoTrack = true,\n respectDnt = false,\n domains,\n tag,\n excludeSearch = false,\n excludeHash = false,\n } = options;\n\n const script = document.createElement('script');\n script.id = SCRIPT_ID;\n\n script.src = `${host.replace(/\\/$/, '')}/script.js`;\n script.defer = true;\n script.dataset.websiteId = websiteId;\n\n if (!autoTrack) {\n script.dataset.autoTrack = 'false';\n }\n if (respectDnt) {\n script.dataset.doNotTrack = 'true';\n }\n if (domains && domains.length > 0) {\n script.dataset.domains = domains.join(',');\n }\n if (tag) {\n script.dataset.tag = tag;\n }\n if (excludeSearch) {\n script.dataset.excludeSearch = 'true';\n }\n if (excludeHash) {\n script.dataset.excludeHash = 'true';\n }\n\n script.onload = () => onLoad?.();\n document.head.appendChild(script);\n}\n\n/**\n * Create Entrolytics Vue plugin\n *\n * @example\n * Zero-config (reads from import.meta.env):\n * ```ts\n * import { createApp } from 'vue';\n * import { createEntrolytics } from '@entrolytics/vue';\n *\n * const app = createApp(App);\n * app.use(createEntrolytics());\n * app.mount('#app');\n * ```\n *\n * @example\n * Explicit config:\n * ```ts\n * const app = createApp(App);\n * app.use(createEntrolytics({ websiteId: 'your-website-id' }));\n * app.mount('#app');\n * ```\n */\nexport function createEntrolytics(options: Partial<EntrolyticsOptions> = {}) {\n // Auto-read from environment variables (Vite)\n const env =\n (\n import.meta as ImportMeta & {\n env?: Record<string, string | boolean | undefined>;\n }\n ).env ?? {};\n const websiteId =\n options.websiteId || env.VITE_ENTROLYTICS_WEBSITE_ID || env.VITE_PUBLIC_ENTROLYTICS_WEBSITE_ID;\n\n const host = options.host || env.VITE_ENTROLYTICS_HOST || env.VITE_PUBLIC_ENTROLYTICS_HOST;\n\n if (!websiteId) {\n if (env.DEV) {\n console.warn(\n '[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option.',\n );\n }\n throw new Error('[@entrolytics/vue] websiteId is required');\n }\n\n const finalOptions: EntrolyticsOptions = {\n ...options,\n websiteId,\n host: host || options.host,\n } as EntrolyticsOptions;\n\n const isLoaded = ref(false);\n const isReady = ref(false);\n let currentTag = finalOptions.tag;\n\n const waitForTracker = (callback: () => void) => {\n if (typeof window === 'undefined') return;\n\n const tryExecute = () => {\n if (window.entrolytics) {\n callback();\n } else {\n setTimeout(tryExecute, 100);\n }\n };\n\n tryExecute();\n };\n\n const track = (eventName: string, eventData?: EventData) => {\n waitForTracker(() => {\n let payload: unknown = { name: eventName, data: eventData };\n\n if (options.beforeSend) {\n payload = options.beforeSend('event', payload);\n if (payload === null) return;\n }\n\n if (currentTag) {\n (payload as Record<string, unknown>).tag = currentTag;\n }\n\n window.entrolytics?.track(eventName, eventData);\n });\n };\n\n const trackPageView = (url?: string, referrer?: string) => {\n waitForTracker(() => {\n const payload: Record<string, unknown> = {};\n if (url) payload.url = url;\n if (referrer) payload.referrer = referrer;\n if (currentTag) payload.tag = currentTag;\n\n window.entrolytics?.track(payload);\n });\n };\n\n const trackRevenue = (eventName: string, revenue: number, currency = 'USD', data?: EventData) => {\n waitForTracker(() => {\n const eventData: EventData = {\n ...data,\n revenue,\n currency,\n };\n\n if (currentTag) {\n eventData.tag = currentTag;\n }\n\n window.entrolytics?.track(eventName, eventData);\n });\n };\n\n const trackOutboundLink = (url: string, data?: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.track('outbound-link-click', {\n ...data,\n url,\n });\n });\n };\n\n const identify = (data: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.identify(data);\n });\n };\n\n const identifyUser = (userId: string, traits?: EventData) => {\n waitForTracker(() => {\n window.entrolytics?.identify({ id: userId, ...traits });\n });\n };\n\n const setTag = (tag: string) => {\n currentTag = tag;\n };\n\n const instance: EntrolyticsInstance = {\n track,\n trackPageView,\n trackRevenue,\n trackOutboundLink,\n identify,\n identifyUser,\n setTag,\n config: finalOptions,\n isLoaded,\n isReady,\n };\n\n return {\n install(app: App) {\n // Inject script on mount\n injectScript(finalOptions, () => {\n isLoaded.value = true;\n isReady.value = true;\n });\n\n // Provide instance\n app.provide(EntrolyticsKey, instance);\n\n // Add global property\n app.config.globalProperties.$entrolytics = instance;\n },\n };\n}\n\n/**\n * Use Entrolytics instance in composition API\n */\nexport function useEntrolyticsInstance(): EntrolyticsInstance {\n const instance = inject(EntrolyticsKey);\n if (!instance) {\n throw new Error('[@entrolytics/vue] Entrolytics plugin not installed');\n }\n return instance;\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Main composable for accessing Entrolytics functionality\n *\n * @example\n * ```vue\n * <script setup>\n * import { useEntrolytics } from '@entrolytics/vue';\n *\n * const { track, identify, isLoaded } = useEntrolytics();\n *\n * function handleClick() {\n * track('button_click', { variant: 'primary' });\n * }\n * </script>\n * ```\n */\nexport function useEntrolytics() {\n return useEntrolyticsInstance();\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for identifying users\n *\n * @example\n * ```vue\n * <script setup>\n * import { watch } from 'vue';\n * import { useIdentify } from '@entrolytics/vue';\n *\n * const { identify } = useIdentify();\n * const user = useUser(); // Your auth composable\n *\n * watch(user, (newUser) => {\n * if (newUser) {\n * identify(newUser.id, {\n * email: newUser.email,\n * plan: newUser.subscription\n * });\n * }\n * });\n * </script>\n * ```\n */\nexport function useIdentify() {\n const { identify } = useEntrolyticsInstance();\n\n return {\n identify,\n };\n}\n","import { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking custom events\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackEvent } from '@entrolytics/vue';\n *\n * const { track } = useTrackEvent();\n *\n * function handlePurchase() {\n * track('purchase', { revenue: 99.99, currency: 'USD' });\n * }\n * </script>\n * ```\n */\nexport function useTrackEvent() {\n const { track } = useEntrolyticsInstance();\n\n return {\n track,\n };\n}\n","import type { EventData } from '../plugin.js';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking outbound link clicks\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackOutboundLink } from '@entrolytics/vue';\n *\n * const trackOutboundLink = useTrackOutboundLink();\n *\n * const handleExternalClick = (url: string) => {\n * trackOutboundLink(url, { placement: 'footer' });\n * };\n * </script>\n * ```\n */\nexport function useTrackOutboundLink() {\n const { trackOutboundLink } = useEntrolyticsInstance();\n return (url: string, data?: EventData) => {\n trackOutboundLink(url, data);\n };\n}\n","import { type Ref, watch } from 'vue';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking page views with vue-router\n *\n * @example\n * ```vue\n * <script setup>\n * import { useRoute } from 'vue-router';\n * import { useTrackPageView } from '@entrolytics/vue';\n *\n * const route = useRoute();\n * useTrackPageView(() => route.path);\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue';\n * import { useTrackPageView } from '@entrolytics/vue';\n *\n * const currentPath = ref('/');\n * useTrackPageView(currentPath);\n * </script>\n * ```\n */\nexport function useTrackPageView(\n pathSource: Ref<string> | (() => string),\n options?: { immediate?: boolean },\n) {\n const { track } = useEntrolyticsInstance();\n const { immediate = true } = options || {};\n\n watch(\n pathSource,\n (newPath, oldPath) => {\n if (newPath !== oldPath) {\n track('pageview', {\n url: newPath,\n });\n }\n },\n { immediate },\n );\n}\n","import type { EventData } from '../plugin.js';\nimport { useEntrolyticsInstance } from '../plugin.js';\n\n/**\n * Composable for tracking revenue events\n *\n * @example\n * ```vue\n * <script setup>\n * import { useTrackRevenue } from '@entrolytics/vue';\n *\n * const trackRevenue = useTrackRevenue();\n *\n * const handlePurchase = async (product) => {\n * await processPayment();\n * trackRevenue('purchase', product.price, 'USD', {\n * productId: product.id,\n * productName: product.name\n * });\n * };\n * </script>\n * ```\n */\nexport function useTrackRevenue() {\n const { trackRevenue } = useEntrolyticsInstance();\n return (eventName: string, revenue: number, currency = 'USD', data?: EventData) => {\n trackRevenue(eventName, revenue, currency, data);\n };\n}\n"],"mappings":";;;AAGA,MAAM,eAAe;AACrB,MAAM,YAAY;AA0ClB,MAAa,iBAAoD,OAAO,aAAa;AAErF,SAAS,aAAa,SAA6B,QAA2B;CAC5E,IAAI,OAAO,WAAW,aAAa;CACnC,IAAI,SAAS,eAAe,SAAS,GAAG;EACtC,SAAS;EACT;CACF;CAEA,MAAM,EACJ,WACA,OAAO,cACP,YAAY,MACZ,aAAa,OACb,SACA,KACA,gBAAgB,OAChB,cAAc,UACZ;CAEJ,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,OAAO,KAAK;CAEZ,OAAO,MAAM,GAAG,KAAK,QAAQ,OAAO,EAAE,EAAE;CACxC,OAAO,QAAQ;CACf,OAAO,QAAQ,YAAY;CAE3B,IAAI,CAAC,WACH,OAAO,QAAQ,YAAY;CAE7B,IAAI,YACF,OAAO,QAAQ,aAAa;CAE9B,IAAI,WAAW,QAAQ,SAAS,GAC9B,OAAO,QAAQ,UAAU,QAAQ,KAAK,GAAG;CAE3C,IAAI,KACF,OAAO,QAAQ,MAAM;CAEvB,IAAI,eACF,OAAO,QAAQ,gBAAgB;CAEjC,IAAI,aACF,OAAO,QAAQ,cAAc;CAG/B,OAAO,eAAe,SAAS;CAC/B,SAAS,KAAK,YAAY,MAAM;AAClC;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,kBAAkB,UAAuC,CAAC,GAAG;CAE3E,MAAM,MAEF,YAGA,OAAO,CAAC;CACZ,MAAM,YACJ,QAAQ,aAAa,IAAI,+BAA+B,IAAI;CAE9D,MAAM,O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