@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.cjs
CHANGED
|
@@ -1,225 +1,330 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let vue = require("vue");
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var SCRIPT_ID = "entrolytics-script";
|
|
8
|
-
var EntrolyticsKey = /* @__PURE__ */ Symbol("entrolytics");
|
|
4
|
+
//#region src/plugin.ts
|
|
5
|
+
const DEFAULT_HOST = "https://api.entrolytics.click";
|
|
6
|
+
const SCRIPT_ID = "entrolytics-script";
|
|
7
|
+
const EntrolyticsKey = Symbol("entrolytics");
|
|
9
8
|
function injectScript(options, onLoad) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
script.src = `${host.replace(/\/$/, "")}${scriptPath}`;
|
|
30
|
-
script.defer = true;
|
|
31
|
-
script.dataset.websiteId = websiteId;
|
|
32
|
-
if (!autoTrack) {
|
|
33
|
-
script.dataset.autoTrack = "false";
|
|
34
|
-
}
|
|
35
|
-
if (respectDnt) {
|
|
36
|
-
script.dataset.doNotTrack = "true";
|
|
37
|
-
}
|
|
38
|
-
if (domains && domains.length > 0) {
|
|
39
|
-
script.dataset.domains = domains.join(",");
|
|
40
|
-
}
|
|
41
|
-
if (tag) {
|
|
42
|
-
script.dataset.tag = tag;
|
|
43
|
-
}
|
|
44
|
-
if (excludeSearch) {
|
|
45
|
-
script.dataset.excludeSearch = "true";
|
|
46
|
-
}
|
|
47
|
-
if (excludeHash) {
|
|
48
|
-
script.dataset.excludeHash = "true";
|
|
49
|
-
}
|
|
50
|
-
script.onload = () => onLoad?.();
|
|
51
|
-
document.head.appendChild(script);
|
|
9
|
+
if (typeof window === "undefined") return;
|
|
10
|
+
if (document.getElementById(SCRIPT_ID)) {
|
|
11
|
+
onLoad?.();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { websiteId, host = DEFAULT_HOST, autoTrack = true, respectDnt = false, domains, tag, excludeSearch = false, excludeHash = false } = options;
|
|
15
|
+
const script = document.createElement("script");
|
|
16
|
+
script.id = SCRIPT_ID;
|
|
17
|
+
script.src = `${host.replace(/\/$/, "")}/script.js`;
|
|
18
|
+
script.defer = true;
|
|
19
|
+
script.dataset.websiteId = websiteId;
|
|
20
|
+
if (!autoTrack) script.dataset.autoTrack = "false";
|
|
21
|
+
if (respectDnt) script.dataset.doNotTrack = "true";
|
|
22
|
+
if (domains && domains.length > 0) script.dataset.domains = domains.join(",");
|
|
23
|
+
if (tag) script.dataset.tag = tag;
|
|
24
|
+
if (excludeSearch) script.dataset.excludeSearch = "true";
|
|
25
|
+
if (excludeHash) script.dataset.excludeHash = "true";
|
|
26
|
+
script.onload = () => onLoad?.();
|
|
27
|
+
document.head.appendChild(script);
|
|
52
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Create Entrolytics Vue plugin
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* Zero-config (reads from import.meta.env):
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createApp } from 'vue';
|
|
36
|
+
* import { createEntrolytics } from '@entrolytics/vue';
|
|
37
|
+
*
|
|
38
|
+
* const app = createApp(App);
|
|
39
|
+
* app.use(createEntrolytics());
|
|
40
|
+
* app.mount('#app');
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Explicit config:
|
|
45
|
+
* ```ts
|
|
46
|
+
* const app = createApp(App);
|
|
47
|
+
* app.use(createEntrolytics({ websiteId: 'your-website-id' }));
|
|
48
|
+
* app.mount('#app');
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
53
51
|
function createEntrolytics(options = {}) {
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
isLoaded.value = true;
|
|
156
|
-
isReady.value = true;
|
|
157
|
-
});
|
|
158
|
-
app.provide(EntrolyticsKey, instance);
|
|
159
|
-
app.config.globalProperties.$entrolytics = instance;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
52
|
+
const env = {}.env ?? {};
|
|
53
|
+
const websiteId = options.websiteId || env.VITE_ENTROLYTICS_WEBSITE_ID || env.VITE_PUBLIC_ENTROLYTICS_WEBSITE_ID;
|
|
54
|
+
const host = options.host || env.VITE_ENTROLYTICS_HOST || env.VITE_PUBLIC_ENTROLYTICS_HOST;
|
|
55
|
+
if (!websiteId) {
|
|
56
|
+
if (env.DEV) console.warn("[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option.");
|
|
57
|
+
throw new Error("[@entrolytics/vue] websiteId is required");
|
|
58
|
+
}
|
|
59
|
+
const finalOptions = {
|
|
60
|
+
...options,
|
|
61
|
+
websiteId,
|
|
62
|
+
host: host || options.host
|
|
63
|
+
};
|
|
64
|
+
const isLoaded = (0, vue.ref)(false);
|
|
65
|
+
const isReady = (0, vue.ref)(false);
|
|
66
|
+
let currentTag = finalOptions.tag;
|
|
67
|
+
const waitForTracker = (callback) => {
|
|
68
|
+
if (typeof window === "undefined") return;
|
|
69
|
+
const tryExecute = () => {
|
|
70
|
+
if (window.entrolytics) callback();
|
|
71
|
+
else setTimeout(tryExecute, 100);
|
|
72
|
+
};
|
|
73
|
+
tryExecute();
|
|
74
|
+
};
|
|
75
|
+
const track = (eventName, eventData) => {
|
|
76
|
+
waitForTracker(() => {
|
|
77
|
+
let payload = {
|
|
78
|
+
name: eventName,
|
|
79
|
+
data: eventData
|
|
80
|
+
};
|
|
81
|
+
if (options.beforeSend) {
|
|
82
|
+
payload = options.beforeSend("event", payload);
|
|
83
|
+
if (payload === null) return;
|
|
84
|
+
}
|
|
85
|
+
if (currentTag) payload.tag = currentTag;
|
|
86
|
+
window.entrolytics?.track(eventName, eventData);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const trackPageView = (url, referrer) => {
|
|
90
|
+
waitForTracker(() => {
|
|
91
|
+
const payload = {};
|
|
92
|
+
if (url) payload.url = url;
|
|
93
|
+
if (referrer) payload.referrer = referrer;
|
|
94
|
+
if (currentTag) payload.tag = currentTag;
|
|
95
|
+
window.entrolytics?.track(payload);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const trackRevenue = (eventName, revenue, currency = "USD", data) => {
|
|
99
|
+
waitForTracker(() => {
|
|
100
|
+
const eventData = {
|
|
101
|
+
...data,
|
|
102
|
+
revenue,
|
|
103
|
+
currency
|
|
104
|
+
};
|
|
105
|
+
if (currentTag) eventData.tag = currentTag;
|
|
106
|
+
window.entrolytics?.track(eventName, eventData);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const trackOutboundLink = (url, data) => {
|
|
110
|
+
waitForTracker(() => {
|
|
111
|
+
window.entrolytics?.track("outbound-link-click", {
|
|
112
|
+
...data,
|
|
113
|
+
url
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const identify = (data) => {
|
|
118
|
+
waitForTracker(() => {
|
|
119
|
+
window.entrolytics?.identify(data);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const identifyUser = (userId, traits) => {
|
|
123
|
+
waitForTracker(() => {
|
|
124
|
+
window.entrolytics?.identify({
|
|
125
|
+
id: userId,
|
|
126
|
+
...traits
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const setTag = (tag) => {
|
|
131
|
+
currentTag = tag;
|
|
132
|
+
};
|
|
133
|
+
const instance = {
|
|
134
|
+
track,
|
|
135
|
+
trackPageView,
|
|
136
|
+
trackRevenue,
|
|
137
|
+
trackOutboundLink,
|
|
138
|
+
identify,
|
|
139
|
+
identifyUser,
|
|
140
|
+
setTag,
|
|
141
|
+
config: finalOptions,
|
|
142
|
+
isLoaded,
|
|
143
|
+
isReady
|
|
144
|
+
};
|
|
145
|
+
return { install(app) {
|
|
146
|
+
injectScript(finalOptions, () => {
|
|
147
|
+
isLoaded.value = true;
|
|
148
|
+
isReady.value = true;
|
|
149
|
+
});
|
|
150
|
+
app.provide(EntrolyticsKey, instance);
|
|
151
|
+
app.config.globalProperties.$entrolytics = instance;
|
|
152
|
+
} };
|
|
162
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Use Entrolytics instance in composition API
|
|
156
|
+
*/
|
|
163
157
|
function useEntrolyticsInstance() {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
return instance;
|
|
158
|
+
const instance = (0, vue.inject)(EntrolyticsKey);
|
|
159
|
+
if (!instance) throw new Error("[@entrolytics/vue] Entrolytics plugin not installed");
|
|
160
|
+
return instance;
|
|
169
161
|
}
|
|
170
162
|
|
|
171
|
-
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/composables/useEntrolytics.ts
|
|
165
|
+
/**
|
|
166
|
+
* Main composable for accessing Entrolytics functionality
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```vue
|
|
170
|
+
* <script setup>
|
|
171
|
+
* import { useEntrolytics } from '@entrolytics/vue';
|
|
172
|
+
*
|
|
173
|
+
* const { track, identify, isLoaded } = useEntrolytics();
|
|
174
|
+
*
|
|
175
|
+
* function handleClick() {
|
|
176
|
+
* track('button_click', { variant: 'primary' });
|
|
177
|
+
* }
|
|
178
|
+
* <\/script>
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
172
181
|
function useEntrolytics() {
|
|
173
|
-
|
|
182
|
+
return useEntrolyticsInstance();
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/composables/useIdentify.ts
|
|
187
|
+
/**
|
|
188
|
+
* Composable for identifying users
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```vue
|
|
192
|
+
* <script setup>
|
|
193
|
+
* import { watch } from 'vue';
|
|
194
|
+
* import { useIdentify } from '@entrolytics/vue';
|
|
195
|
+
*
|
|
196
|
+
* const { identify } = useIdentify();
|
|
197
|
+
* const user = useUser(); // Your auth composable
|
|
198
|
+
*
|
|
199
|
+
* watch(user, (newUser) => {
|
|
200
|
+
* if (newUser) {
|
|
201
|
+
* identify(newUser.id, {
|
|
202
|
+
* email: newUser.email,
|
|
203
|
+
* plan: newUser.subscription
|
|
204
|
+
* });
|
|
205
|
+
* }
|
|
206
|
+
* });
|
|
207
|
+
* <\/script>
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
177
210
|
function useIdentify() {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
identify
|
|
181
|
-
};
|
|
211
|
+
const { identify } = useEntrolyticsInstance();
|
|
212
|
+
return { identify };
|
|
182
213
|
}
|
|
183
214
|
|
|
184
|
-
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/composables/useTrackEvent.ts
|
|
217
|
+
/**
|
|
218
|
+
* Composable for tracking custom events
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```vue
|
|
222
|
+
* <script setup>
|
|
223
|
+
* import { useTrackEvent } from '@entrolytics/vue';
|
|
224
|
+
*
|
|
225
|
+
* const { track } = useTrackEvent();
|
|
226
|
+
*
|
|
227
|
+
* function handlePurchase() {
|
|
228
|
+
* track('purchase', { revenue: 99.99, currency: 'USD' });
|
|
229
|
+
* }
|
|
230
|
+
* <\/script>
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
185
233
|
function useTrackEvent() {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
track
|
|
189
|
-
};
|
|
234
|
+
const { track } = useEntrolyticsInstance();
|
|
235
|
+
return { track };
|
|
190
236
|
}
|
|
191
237
|
|
|
192
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/composables/useTrackOutboundLink.ts
|
|
240
|
+
/**
|
|
241
|
+
* Composable for tracking outbound link clicks
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```vue
|
|
245
|
+
* <script setup>
|
|
246
|
+
* import { useTrackOutboundLink } from '@entrolytics/vue';
|
|
247
|
+
*
|
|
248
|
+
* const trackOutboundLink = useTrackOutboundLink();
|
|
249
|
+
*
|
|
250
|
+
* const handleExternalClick = (url: string) => {
|
|
251
|
+
* trackOutboundLink(url, { placement: 'footer' });
|
|
252
|
+
* };
|
|
253
|
+
* <\/script>
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
193
256
|
function useTrackOutboundLink() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
257
|
+
const { trackOutboundLink } = useEntrolyticsInstance();
|
|
258
|
+
return (url, data) => {
|
|
259
|
+
trackOutboundLink(url, data);
|
|
260
|
+
};
|
|
198
261
|
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/composables/useTrackPageView.ts
|
|
265
|
+
/**
|
|
266
|
+
* Composable for tracking page views with vue-router
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```vue
|
|
270
|
+
* <script setup>
|
|
271
|
+
* import { useRoute } from 'vue-router';
|
|
272
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
273
|
+
*
|
|
274
|
+
* const route = useRoute();
|
|
275
|
+
* useTrackPageView(() => route.path);
|
|
276
|
+
* <\/script>
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```vue
|
|
281
|
+
* <script setup>
|
|
282
|
+
* import { ref } from 'vue';
|
|
283
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
284
|
+
*
|
|
285
|
+
* const currentPath = ref('/');
|
|
286
|
+
* useTrackPageView(currentPath);
|
|
287
|
+
* <\/script>
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
199
290
|
function useTrackPageView(pathSource, options) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (newPath !== oldPath) {
|
|
206
|
-
track("pageview", {
|
|
207
|
-
url: newPath
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
{ immediate }
|
|
212
|
-
);
|
|
291
|
+
const { track } = useEntrolyticsInstance();
|
|
292
|
+
const { immediate = true } = options || {};
|
|
293
|
+
(0, vue.watch)(pathSource, (newPath, oldPath) => {
|
|
294
|
+
if (newPath !== oldPath) track("pageview", { url: newPath });
|
|
295
|
+
}, { immediate });
|
|
213
296
|
}
|
|
214
297
|
|
|
215
|
-
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/composables/useTrackRevenue.ts
|
|
300
|
+
/**
|
|
301
|
+
* Composable for tracking revenue events
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```vue
|
|
305
|
+
* <script setup>
|
|
306
|
+
* import { useTrackRevenue } from '@entrolytics/vue';
|
|
307
|
+
*
|
|
308
|
+
* const trackRevenue = useTrackRevenue();
|
|
309
|
+
*
|
|
310
|
+
* const handlePurchase = async (product) => {
|
|
311
|
+
* await processPayment();
|
|
312
|
+
* trackRevenue('purchase', product.price, 'USD', {
|
|
313
|
+
* productId: product.id,
|
|
314
|
+
* productName: product.name
|
|
315
|
+
* });
|
|
316
|
+
* };
|
|
317
|
+
* <\/script>
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
216
320
|
function useTrackRevenue() {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
321
|
+
const { trackRevenue } = useEntrolyticsInstance();
|
|
322
|
+
return (eventName, revenue, currency = "USD", data) => {
|
|
323
|
+
trackRevenue(eventName, revenue, currency, data);
|
|
324
|
+
};
|
|
221
325
|
}
|
|
222
326
|
|
|
327
|
+
//#endregion
|
|
223
328
|
exports.EntrolyticsKey = EntrolyticsKey;
|
|
224
329
|
exports.createEntrolytics = createEntrolytics;
|
|
225
330
|
exports.useEntrolytics = useEntrolytics;
|
|
@@ -229,5 +334,4 @@ exports.useTrackEvent = useTrackEvent;
|
|
|
229
334
|
exports.useTrackOutboundLink = useTrackOutboundLink;
|
|
230
335
|
exports.useTrackPageView = useTrackPageView;
|
|
231
336
|
exports.useTrackRevenue = useTrackRevenue;
|
|
232
|
-
//# sourceMappingURL=index.cjs.map
|
|
233
337
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.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.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AACA,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,sBAAA,EAAuB;AACzC,EAAA,MAAM,EAAE,SAAA,GAAY,IAAA,EAAK,GAAI,WAAW,EAAC;AAEzC,EAAAC,SAAA;AAAA,IACE,UAAA;AAAA,IACA,CAAC,SAAS,OAAA,KAAY;AACpB,MAAA,IAAI,YAAY,OAAA,EAAS;AACvB,QAAA,KAAA,CAAM,UAAA,EAAY;AAAA,UAChB,GAAA,EAAK;AAAA,SACN,CAAA;AAAA,MACH;AAAA,IACF,CAAA;AAAA,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.cjs","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.cjs","names":["ref","inject"],"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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