@entrolytics/vue-sdk 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +285 -0
- package/dist/index.cjs +233 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.js +223 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Entrolytics <hey@entrolytics.click>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/entrolytics/.github/main/media/entrov2.png" alt="Entrolytics" width="64" height="64">
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/@entrolytics/vue-sdk)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://vuejs.org/)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
**@entrolytics/vue-sdk** is the official Vue SDK for Entrolytics - first-party growth analytics for the edge. Add powerful analytics to your Vue 3 applications with zero configuration.
|
|
16
|
+
|
|
17
|
+
**Why use this SDK?**
|
|
18
|
+
- Zero-config setup with automatic environment detection
|
|
19
|
+
- Full Vue 3 Composition API support with composables
|
|
20
|
+
- TypeScript-first with complete type definitions
|
|
21
|
+
- Edge-optimized with sub-50ms response times globally
|
|
22
|
+
|
|
23
|
+
## Key Features
|
|
24
|
+
|
|
25
|
+
<table>
|
|
26
|
+
<tr>
|
|
27
|
+
<td width="50%">
|
|
28
|
+
|
|
29
|
+
### Analytics
|
|
30
|
+
- Automatic page view tracking
|
|
31
|
+
- Custom event tracking
|
|
32
|
+
- User identification
|
|
33
|
+
- Cross-domain tracking
|
|
34
|
+
|
|
35
|
+
</td>
|
|
36
|
+
<td width="50%">
|
|
37
|
+
|
|
38
|
+
### Developer Experience
|
|
39
|
+
- Vue plugin architecture
|
|
40
|
+
- Composables API (`useTrackEvent`, `useIdentify`)
|
|
41
|
+
- Global `$entrolytics` property
|
|
42
|
+
- Full TypeScript support
|
|
43
|
+
|
|
44
|
+
</td>
|
|
45
|
+
</tr>
|
|
46
|
+
</table>
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
<table>
|
|
51
|
+
<tr>
|
|
52
|
+
<td align="center" width="25%">
|
|
53
|
+
<img src="https://api.iconify.design/lucide:download.svg?color=%236366f1" width="48"><br>
|
|
54
|
+
<strong>1. Install</strong><br>
|
|
55
|
+
<code>npm i @entrolytics/vue-sdk</code>
|
|
56
|
+
</td>
|
|
57
|
+
<td align="center" width="25%">
|
|
58
|
+
<img src="https://api.iconify.design/lucide:code.svg?color=%236366f1" width="48"><br>
|
|
59
|
+
<strong>2. Add Plugin</strong><br>
|
|
60
|
+
<code>app.use(createEntrolytics())</code>
|
|
61
|
+
</td>
|
|
62
|
+
<td align="center" width="25%">
|
|
63
|
+
<img src="https://api.iconify.design/lucide:settings.svg?color=%236366f1" width="48"><br>
|
|
64
|
+
<strong>3. Configure</strong><br>
|
|
65
|
+
Set Website ID in <code>.env</code>
|
|
66
|
+
</td>
|
|
67
|
+
<td align="center" width="25%">
|
|
68
|
+
<img src="https://api.iconify.design/lucide:bar-chart-3.svg?color=%236366f1" width="48"><br>
|
|
69
|
+
<strong>4. Track</strong><br>
|
|
70
|
+
View analytics in dashboard
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
</table>
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @entrolytics/vue-sdk
|
|
79
|
+
# or
|
|
80
|
+
pnpm add @entrolytics/vue-sdk
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Quick Start
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// main.ts
|
|
87
|
+
import { createApp } from 'vue';
|
|
88
|
+
import { createEntrolytics } from '@entrolytics/vue';
|
|
89
|
+
import App from './App.vue';
|
|
90
|
+
|
|
91
|
+
const app = createApp(App);
|
|
92
|
+
|
|
93
|
+
// Zero-config: automatically reads from .env
|
|
94
|
+
app.use(createEntrolytics());
|
|
95
|
+
|
|
96
|
+
app.mount('#app');
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Add to your `.env` file:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
VITE_ENTROLYTICS_WEBSITE_ID=your-website-id
|
|
103
|
+
VITE_ENTROLYTICS_HOST=https://entrolytics.click
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration Options
|
|
107
|
+
|
|
108
|
+
### Zero-Config (Recommended)
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// Reads from VITE_ENTROLYTICS_WEBSITE_ID and VITE_ENTROLYTICS_HOST
|
|
112
|
+
app.use(createEntrolytics());
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Explicit Configuration
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
createEntrolytics({
|
|
119
|
+
// Required: Your Entrolytics website ID
|
|
120
|
+
websiteId: 'your-website-id',
|
|
121
|
+
|
|
122
|
+
// Optional: Custom host (for self-hosted)
|
|
123
|
+
host: 'https://entrolytics.click',
|
|
124
|
+
|
|
125
|
+
// Optional: Auto-track page views (default: true)
|
|
126
|
+
autoTrack: true,
|
|
127
|
+
|
|
128
|
+
// Optional: Use edge-optimized endpoints (default: true)
|
|
129
|
+
useEdgeRuntime: true,
|
|
130
|
+
|
|
131
|
+
// Optional: Respect Do Not Track (default: false)
|
|
132
|
+
respectDnt: false,
|
|
133
|
+
|
|
134
|
+
// Optional: Cross-domain tracking
|
|
135
|
+
domains: ['example.com', 'blog.example.com'],
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Runtime Configuration
|
|
140
|
+
|
|
141
|
+
The `useEdgeRuntime` option controls which collection endpoint is used:
|
|
142
|
+
|
|
143
|
+
**Edge Runtime (default)** - Optimized for speed and global distribution:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
createEntrolytics({
|
|
147
|
+
websiteId: 'your-website-id',
|
|
148
|
+
useEdgeRuntime: true // or omit (default)
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- **Latency**: Sub-50ms response times globally
|
|
153
|
+
- **Best for**: Production Vue applications, globally distributed users
|
|
154
|
+
- **Endpoint**: Uses `/api/send-native` for edge-to-edge communication
|
|
155
|
+
- **Limitations**: No ClickHouse export, basic geo data
|
|
156
|
+
|
|
157
|
+
**Node.js Runtime** - Full-featured with advanced capabilities:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
createEntrolytics({
|
|
161
|
+
websiteId: 'your-website-id',
|
|
162
|
+
useEdgeRuntime: false
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- **Features**: ClickHouse export, MaxMind GeoIP (city-level accuracy)
|
|
167
|
+
- **Best for**: Self-hosted deployments, advanced analytics requirements
|
|
168
|
+
- **Endpoint**: Uses `/api/send` for Node.js runtime
|
|
169
|
+
- **Latency**: 50-150ms (regional)
|
|
170
|
+
|
|
171
|
+
**When to use Node.js runtime**:
|
|
172
|
+
- Self-hosted Vue deployments without edge runtime support
|
|
173
|
+
- Applications requiring ClickHouse data export
|
|
174
|
+
- Need for advanced geo-targeting with MaxMind
|
|
175
|
+
- Custom server-side analytics workflows
|
|
176
|
+
|
|
177
|
+
## Composables
|
|
178
|
+
|
|
179
|
+
### useEntrolytics
|
|
180
|
+
|
|
181
|
+
Main composable for accessing all functionality.
|
|
182
|
+
|
|
183
|
+
```vue
|
|
184
|
+
<script setup>
|
|
185
|
+
import { useEntrolytics } from '@entrolytics/vue';
|
|
186
|
+
|
|
187
|
+
const { track, identify, isLoaded, config } = useEntrolytics();
|
|
188
|
+
|
|
189
|
+
function handleClick() {
|
|
190
|
+
track('button_click', { variant: 'primary' });
|
|
191
|
+
}
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
<template>
|
|
195
|
+
<button @click="handleClick">Click me</button>
|
|
196
|
+
</template>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### useTrackEvent
|
|
200
|
+
|
|
201
|
+
Track custom events.
|
|
202
|
+
|
|
203
|
+
```vue
|
|
204
|
+
<script setup>
|
|
205
|
+
import { useTrackEvent } from '@entrolytics/vue';
|
|
206
|
+
|
|
207
|
+
const { track } = useTrackEvent();
|
|
208
|
+
|
|
209
|
+
function handlePurchase() {
|
|
210
|
+
track('purchase', {
|
|
211
|
+
revenue: 99.99,
|
|
212
|
+
currency: 'USD',
|
|
213
|
+
product_id: 'pro-plan'
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### useTrackPageView
|
|
220
|
+
|
|
221
|
+
Track page views with vue-router.
|
|
222
|
+
|
|
223
|
+
```vue
|
|
224
|
+
<script setup>
|
|
225
|
+
import { useRoute } from 'vue-router';
|
|
226
|
+
import { useTrackPageView } from '@entrolytics/vue';
|
|
227
|
+
|
|
228
|
+
const route = useRoute();
|
|
229
|
+
useTrackPageView(() => route.path);
|
|
230
|
+
</script>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### useIdentify
|
|
234
|
+
|
|
235
|
+
Identify users for logged-in tracking.
|
|
236
|
+
|
|
237
|
+
```vue
|
|
238
|
+
<script setup>
|
|
239
|
+
import { watch } from 'vue';
|
|
240
|
+
import { useIdentify } from '@entrolytics/vue';
|
|
241
|
+
|
|
242
|
+
const { identify } = useIdentify();
|
|
243
|
+
|
|
244
|
+
// When user logs in
|
|
245
|
+
watch(user, (newUser) => {
|
|
246
|
+
if (newUser) {
|
|
247
|
+
identify(newUser.id, {
|
|
248
|
+
email: newUser.email,
|
|
249
|
+
plan: newUser.subscription
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
</script>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Global Property
|
|
257
|
+
|
|
258
|
+
The plugin also adds a global property accessible in templates and options API:
|
|
259
|
+
|
|
260
|
+
```vue
|
|
261
|
+
<script>
|
|
262
|
+
export default {
|
|
263
|
+
methods: {
|
|
264
|
+
trackClick() {
|
|
265
|
+
this.$entrolytics.track('button_click');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
</script>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## TypeScript Support
|
|
273
|
+
|
|
274
|
+
Full TypeScript support with exported types:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import type {
|
|
278
|
+
EntrolyticsOptions,
|
|
279
|
+
EntrolyticsInstance
|
|
280
|
+
} from '@entrolytics/vue';
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
|
|
5
|
+
// src/plugin.ts
|
|
6
|
+
var DEFAULT_HOST = "https://entrolytics.click";
|
|
7
|
+
var SCRIPT_ID = "entrolytics-script";
|
|
8
|
+
var EntrolyticsKey = /* @__PURE__ */ Symbol("entrolytics");
|
|
9
|
+
function injectScript(options, onLoad) {
|
|
10
|
+
if (typeof window === "undefined") return;
|
|
11
|
+
if (document.getElementById(SCRIPT_ID)) {
|
|
12
|
+
onLoad?.();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const {
|
|
16
|
+
websiteId,
|
|
17
|
+
host = DEFAULT_HOST,
|
|
18
|
+
autoTrack = true,
|
|
19
|
+
respectDnt = false,
|
|
20
|
+
domains,
|
|
21
|
+
useEdgeRuntime = true,
|
|
22
|
+
tag,
|
|
23
|
+
excludeSearch = false,
|
|
24
|
+
excludeHash = false
|
|
25
|
+
} = options;
|
|
26
|
+
const script = document.createElement("script");
|
|
27
|
+
script.id = SCRIPT_ID;
|
|
28
|
+
const scriptPath = useEdgeRuntime ? "/script-edge.js" : "/script.js";
|
|
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);
|
|
52
|
+
}
|
|
53
|
+
function createEntrolytics(options = {}) {
|
|
54
|
+
const env = undefined || {};
|
|
55
|
+
const websiteId = options.websiteId || env.VITE_ENTROLYTICS_WEBSITE_ID || env.VITE_PUBLIC_ENTROLYTICS_WEBSITE_ID;
|
|
56
|
+
const host = options.host || env.VITE_ENTROLYTICS_HOST || env.VITE_PUBLIC_ENTROLYTICS_HOST;
|
|
57
|
+
if (!websiteId) {
|
|
58
|
+
if (env.DEV) {
|
|
59
|
+
console.warn(
|
|
60
|
+
"[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
throw new Error("[@entrolytics/vue] websiteId is required");
|
|
64
|
+
}
|
|
65
|
+
const finalOptions = {
|
|
66
|
+
...options,
|
|
67
|
+
websiteId,
|
|
68
|
+
host: host || options.host
|
|
69
|
+
};
|
|
70
|
+
const isLoaded = vue.ref(false);
|
|
71
|
+
const isReady = vue.ref(false);
|
|
72
|
+
let currentTag = finalOptions.tag;
|
|
73
|
+
const waitForTracker = (callback) => {
|
|
74
|
+
if (typeof window === "undefined") return;
|
|
75
|
+
const tryExecute = () => {
|
|
76
|
+
if (window.entrolytics) {
|
|
77
|
+
callback();
|
|
78
|
+
} else {
|
|
79
|
+
setTimeout(tryExecute, 100);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
tryExecute();
|
|
83
|
+
};
|
|
84
|
+
const track = (eventName, eventData) => {
|
|
85
|
+
waitForTracker(() => {
|
|
86
|
+
let payload = { name: eventName, data: eventData };
|
|
87
|
+
if (options.beforeSend) {
|
|
88
|
+
payload = options.beforeSend("event", payload);
|
|
89
|
+
if (payload === null) return;
|
|
90
|
+
}
|
|
91
|
+
if (currentTag) {
|
|
92
|
+
payload.tag = currentTag;
|
|
93
|
+
}
|
|
94
|
+
window.entrolytics?.track(eventName, eventData);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const trackPageView = (url, referrer) => {
|
|
98
|
+
waitForTracker(() => {
|
|
99
|
+
const payload = {};
|
|
100
|
+
if (url) payload.url = url;
|
|
101
|
+
if (referrer) payload.referrer = referrer;
|
|
102
|
+
if (currentTag) payload.tag = currentTag;
|
|
103
|
+
window.entrolytics?.track(payload);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const trackRevenue = (eventName, revenue, currency = "USD", data) => {
|
|
107
|
+
waitForTracker(() => {
|
|
108
|
+
const eventData = {
|
|
109
|
+
...data,
|
|
110
|
+
revenue,
|
|
111
|
+
currency
|
|
112
|
+
};
|
|
113
|
+
if (currentTag) {
|
|
114
|
+
eventData.tag = currentTag;
|
|
115
|
+
}
|
|
116
|
+
window.entrolytics?.track(eventName, eventData);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const trackOutboundLink = (url, data) => {
|
|
120
|
+
waitForTracker(() => {
|
|
121
|
+
window.entrolytics?.track("outbound-link-click", {
|
|
122
|
+
...data,
|
|
123
|
+
url
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const identify = (data) => {
|
|
128
|
+
waitForTracker(() => {
|
|
129
|
+
window.entrolytics?.identify(data);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const identifyUser = (userId, traits) => {
|
|
133
|
+
waitForTracker(() => {
|
|
134
|
+
window.entrolytics?.identify({ id: userId, ...traits });
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
const setTag = (tag) => {
|
|
138
|
+
currentTag = tag;
|
|
139
|
+
};
|
|
140
|
+
const instance = {
|
|
141
|
+
track,
|
|
142
|
+
trackPageView,
|
|
143
|
+
trackRevenue,
|
|
144
|
+
trackOutboundLink,
|
|
145
|
+
identify,
|
|
146
|
+
identifyUser,
|
|
147
|
+
setTag,
|
|
148
|
+
config: finalOptions,
|
|
149
|
+
isLoaded,
|
|
150
|
+
isReady
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
install(app) {
|
|
154
|
+
injectScript(finalOptions, () => {
|
|
155
|
+
isLoaded.value = true;
|
|
156
|
+
isReady.value = true;
|
|
157
|
+
});
|
|
158
|
+
app.provide(EntrolyticsKey, instance);
|
|
159
|
+
app.config.globalProperties.$entrolytics = instance;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function useEntrolyticsInstance() {
|
|
164
|
+
const instance = vue.inject(EntrolyticsKey);
|
|
165
|
+
if (!instance) {
|
|
166
|
+
throw new Error("[@entrolytics/vue] Entrolytics plugin not installed");
|
|
167
|
+
}
|
|
168
|
+
return instance;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/composables/useEntrolytics.ts
|
|
172
|
+
function useEntrolytics() {
|
|
173
|
+
return useEntrolyticsInstance();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/composables/useIdentify.ts
|
|
177
|
+
function useIdentify() {
|
|
178
|
+
const { identify } = useEntrolyticsInstance();
|
|
179
|
+
return {
|
|
180
|
+
identify
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/composables/useTrackEvent.ts
|
|
185
|
+
function useTrackEvent() {
|
|
186
|
+
const { track } = useEntrolyticsInstance();
|
|
187
|
+
return {
|
|
188
|
+
track
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/composables/useTrackOutboundLink.ts
|
|
193
|
+
function useTrackOutboundLink() {
|
|
194
|
+
const { trackOutboundLink } = useEntrolyticsInstance();
|
|
195
|
+
return (url, data) => {
|
|
196
|
+
trackOutboundLink(url, data);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function useTrackPageView(pathSource, options) {
|
|
200
|
+
const { track } = useEntrolyticsInstance();
|
|
201
|
+
const { immediate = true } = options || {};
|
|
202
|
+
vue.watch(
|
|
203
|
+
pathSource,
|
|
204
|
+
(newPath, oldPath) => {
|
|
205
|
+
if (newPath !== oldPath) {
|
|
206
|
+
track("pageview", {
|
|
207
|
+
url: newPath
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
{ immediate }
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/composables/useTrackRevenue.ts
|
|
216
|
+
function useTrackRevenue() {
|
|
217
|
+
const { trackRevenue } = useEntrolyticsInstance();
|
|
218
|
+
return (eventName, revenue, currency = "USD", data) => {
|
|
219
|
+
trackRevenue(eventName, revenue, currency, data);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
exports.EntrolyticsKey = EntrolyticsKey;
|
|
224
|
+
exports.createEntrolytics = createEntrolytics;
|
|
225
|
+
exports.useEntrolytics = useEntrolytics;
|
|
226
|
+
exports.useEntrolyticsInstance = useEntrolyticsInstance;
|
|
227
|
+
exports.useIdentify = useIdentify;
|
|
228
|
+
exports.useTrackEvent = useTrackEvent;
|
|
229
|
+
exports.useTrackOutboundLink = useTrackOutboundLink;
|
|
230
|
+
exports.useTrackPageView = useTrackPageView;
|
|
231
|
+
exports.useTrackRevenue = useTrackRevenue;
|
|
232
|
+
//# sourceMappingURL=index.cjs.map
|
|
233
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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":["ref","inject","watch"],"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,SAAA;AAAA,IACA,IAAA,GAAO,YAAA;AAAA,IACP,SAAA,GAAY,IAAA;AAAA,IACZ,UAAA,GAAa,KAAA;AAAA,IACb,OAAA;AAAA,IACA,cAAA,GAAiB,IAAA;AAAA,IACjB,GAAA;AAAA,IACA,aAAA,GAAgB,KAAA;AAAA,IAChB,WAAA,GAAc;AAAA,GAChB,GAAI,OAAA;AAEJ,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC9C,EAAA,MAAA,CAAO,EAAA,GAAK,SAAA;AAGZ,EAAA,MAAM,UAAA,GAAa,iBAAiB,iBAAA,GAAoB,YAAA;AACxD,EAAA,MAAA,CAAO,GAAA,GAAM,GAAG,IAAA,CAAK,OAAA,CAAQ,OAAO,EAAE,CAAC,GAAG,UAAU,CAAA,CAAA;AACpD,EAAA,MAAA,CAAO,KAAA,GAAQ,IAAA;AACf,EAAA,MAAA,CAAO,QAAQ,SAAA,GAAY,SAAA;AAE3B,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAA,CAAO,QAAQ,SAAA,GAAY,OAA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BAAA,EAAkB,GAAI,sBAAA,EAAuB;AACrD,EAAA,OAAO,CAAC,KAAa,IAAA,KAAqB;AACxC,IAAA,iBAAA,CAAkB,KAAK,IAAI,CAAA;AAAA,EAC7B,CAAA;AACF;ACIO,SAAS,gBAAA,CACd,YACA,OAAA,EACA;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"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Ref, InjectionKey, App } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Event payload type - mirrors @entrolytics/shared EventPayload
|
|
5
|
+
* TODO: Import from @entrolytics/shared once published with EventPayload export
|
|
6
|
+
*/
|
|
7
|
+
interface EventPayload {
|
|
8
|
+
websiteId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
visitorId: string;
|
|
11
|
+
url: string;
|
|
12
|
+
referrer?: string;
|
|
13
|
+
eventType: string;
|
|
14
|
+
eventName?: string;
|
|
15
|
+
properties?: Record<string, unknown>;
|
|
16
|
+
screenWidth?: number;
|
|
17
|
+
screenHeight?: number;
|
|
18
|
+
loadTime?: number;
|
|
19
|
+
domInteractive?: number;
|
|
20
|
+
domComplete?: number;
|
|
21
|
+
utmSource?: string;
|
|
22
|
+
utmMedium?: string;
|
|
23
|
+
utmCampaign?: string;
|
|
24
|
+
utmTerm?: string;
|
|
25
|
+
utmContent?: string;
|
|
26
|
+
}
|
|
27
|
+
type EventData = NonNullable<EventPayload['properties']>;
|
|
28
|
+
interface EntrolyticsOptions {
|
|
29
|
+
websiteId: string;
|
|
30
|
+
host?: string;
|
|
31
|
+
autoTrack?: boolean;
|
|
32
|
+
respectDnt?: boolean;
|
|
33
|
+
domains?: string[];
|
|
34
|
+
/** Use edge runtime endpoints for faster response times (default: true) */
|
|
35
|
+
useEdgeRuntime?: boolean;
|
|
36
|
+
/** Custom tag for A/B testing */
|
|
37
|
+
tag?: string;
|
|
38
|
+
/** Strip query parameters from URLs */
|
|
39
|
+
excludeSearch?: boolean;
|
|
40
|
+
/** Strip hash from URLs */
|
|
41
|
+
excludeHash?: boolean;
|
|
42
|
+
/** Callback before sending data */
|
|
43
|
+
beforeSend?: (type: string, payload: unknown) => unknown | null;
|
|
44
|
+
}
|
|
45
|
+
interface EntrolyticsInstance {
|
|
46
|
+
track: (eventName: string, eventData?: EventData) => void;
|
|
47
|
+
trackPageView: (url?: string, referrer?: string) => void;
|
|
48
|
+
trackRevenue: (eventName: string, revenue: number, currency?: string, data?: EventData) => void;
|
|
49
|
+
trackOutboundLink: (url: string, data?: EventData) => void;
|
|
50
|
+
identify: (data: EventData) => void;
|
|
51
|
+
identifyUser: (userId: string, traits?: EventData) => void;
|
|
52
|
+
setTag: (tag: string) => void;
|
|
53
|
+
config: EntrolyticsOptions;
|
|
54
|
+
isLoaded: Ref<boolean>;
|
|
55
|
+
isReady: Ref<boolean>;
|
|
56
|
+
}
|
|
57
|
+
declare global {
|
|
58
|
+
interface Window {
|
|
59
|
+
entrolytics?: {
|
|
60
|
+
track: (eventName?: string | object, eventData?: Record<string, unknown>) => void;
|
|
61
|
+
identify: (data: Record<string, unknown>) => void;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declare const EntrolyticsKey: InjectionKey<EntrolyticsInstance>;
|
|
66
|
+
/**
|
|
67
|
+
* Create Entrolytics Vue plugin
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Zero-config (reads from import.meta.env):
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { createApp } from 'vue';
|
|
73
|
+
* import { createEntrolytics } from '@entrolytics/vue';
|
|
74
|
+
*
|
|
75
|
+
* const app = createApp(App);
|
|
76
|
+
* app.use(createEntrolytics());
|
|
77
|
+
* app.mount('#app');
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* Explicit config:
|
|
82
|
+
* ```ts
|
|
83
|
+
* const app = createApp(App);
|
|
84
|
+
* app.use(createEntrolytics({ websiteId: 'your-website-id' }));
|
|
85
|
+
* app.mount('#app');
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function createEntrolytics(options?: Partial<EntrolyticsOptions>): {
|
|
89
|
+
install(app: App): void;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Use Entrolytics instance in composition API
|
|
93
|
+
*/
|
|
94
|
+
declare function useEntrolyticsInstance(): EntrolyticsInstance;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Main composable for accessing Entrolytics functionality
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```vue
|
|
101
|
+
* <script setup>
|
|
102
|
+
* import { useEntrolytics } from '@entrolytics/vue';
|
|
103
|
+
*
|
|
104
|
+
* const { track, identify, isLoaded } = useEntrolytics();
|
|
105
|
+
*
|
|
106
|
+
* function handleClick() {
|
|
107
|
+
* track('button_click', { variant: 'primary' });
|
|
108
|
+
* }
|
|
109
|
+
* </script>
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function useEntrolytics(): EntrolyticsInstance;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Composable for identifying users
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```vue
|
|
119
|
+
* <script setup>
|
|
120
|
+
* import { watch } from 'vue';
|
|
121
|
+
* import { useIdentify } from '@entrolytics/vue';
|
|
122
|
+
*
|
|
123
|
+
* const { identify } = useIdentify();
|
|
124
|
+
* const user = useUser(); // Your auth composable
|
|
125
|
+
*
|
|
126
|
+
* watch(user, (newUser) => {
|
|
127
|
+
* if (newUser) {
|
|
128
|
+
* identify(newUser.id, {
|
|
129
|
+
* email: newUser.email,
|
|
130
|
+
* plan: newUser.subscription
|
|
131
|
+
* });
|
|
132
|
+
* }
|
|
133
|
+
* });
|
|
134
|
+
* </script>
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function useIdentify(): {
|
|
138
|
+
identify: (data: EventData) => void;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Composable for tracking custom events
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```vue
|
|
146
|
+
* <script setup>
|
|
147
|
+
* import { useTrackEvent } from '@entrolytics/vue';
|
|
148
|
+
*
|
|
149
|
+
* const { track } = useTrackEvent();
|
|
150
|
+
*
|
|
151
|
+
* function handlePurchase() {
|
|
152
|
+
* track('purchase', { revenue: 99.99, currency: 'USD' });
|
|
153
|
+
* }
|
|
154
|
+
* </script>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function useTrackEvent(): {
|
|
158
|
+
track: (eventName: string, eventData?: EventData) => void;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Composable for tracking outbound link clicks
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```vue
|
|
166
|
+
* <script setup>
|
|
167
|
+
* import { useTrackOutboundLink } from '@entrolytics/vue';
|
|
168
|
+
*
|
|
169
|
+
* const trackOutboundLink = useTrackOutboundLink();
|
|
170
|
+
*
|
|
171
|
+
* const handleExternalClick = (url: string) => {
|
|
172
|
+
* trackOutboundLink(url, { placement: 'footer' });
|
|
173
|
+
* };
|
|
174
|
+
* </script>
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function useTrackOutboundLink(): (url: string, data?: EventData) => void;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Composable for tracking page views with vue-router
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```vue
|
|
184
|
+
* <script setup>
|
|
185
|
+
* import { useRoute } from 'vue-router';
|
|
186
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
187
|
+
*
|
|
188
|
+
* const route = useRoute();
|
|
189
|
+
* useTrackPageView(() => route.path);
|
|
190
|
+
* </script>
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```vue
|
|
195
|
+
* <script setup>
|
|
196
|
+
* import { ref } from 'vue';
|
|
197
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
198
|
+
*
|
|
199
|
+
* const currentPath = ref('/');
|
|
200
|
+
* useTrackPageView(currentPath);
|
|
201
|
+
* </script>
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare function useTrackPageView(pathSource: Ref<string> | (() => string), options?: {
|
|
205
|
+
immediate?: boolean;
|
|
206
|
+
}): void;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Composable for tracking revenue events
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```vue
|
|
213
|
+
* <script setup>
|
|
214
|
+
* import { useTrackRevenue } from '@entrolytics/vue';
|
|
215
|
+
*
|
|
216
|
+
* const trackRevenue = useTrackRevenue();
|
|
217
|
+
*
|
|
218
|
+
* const handlePurchase = async (product) => {
|
|
219
|
+
* await processPayment();
|
|
220
|
+
* trackRevenue('purchase', product.price, 'USD', {
|
|
221
|
+
* productId: product.id,
|
|
222
|
+
* productName: product.name
|
|
223
|
+
* });
|
|
224
|
+
* };
|
|
225
|
+
* </script>
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function useTrackRevenue(): (eventName: string, revenue: number, currency?: string, data?: EventData) => void;
|
|
229
|
+
|
|
230
|
+
export { type EntrolyticsInstance, EntrolyticsKey, type EntrolyticsOptions, type EventData, createEntrolytics, useEntrolytics, useEntrolyticsInstance, useIdentify, useTrackEvent, useTrackOutboundLink, useTrackPageView, useTrackRevenue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Ref, InjectionKey, App } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Event payload type - mirrors @entrolytics/shared EventPayload
|
|
5
|
+
* TODO: Import from @entrolytics/shared once published with EventPayload export
|
|
6
|
+
*/
|
|
7
|
+
interface EventPayload {
|
|
8
|
+
websiteId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
visitorId: string;
|
|
11
|
+
url: string;
|
|
12
|
+
referrer?: string;
|
|
13
|
+
eventType: string;
|
|
14
|
+
eventName?: string;
|
|
15
|
+
properties?: Record<string, unknown>;
|
|
16
|
+
screenWidth?: number;
|
|
17
|
+
screenHeight?: number;
|
|
18
|
+
loadTime?: number;
|
|
19
|
+
domInteractive?: number;
|
|
20
|
+
domComplete?: number;
|
|
21
|
+
utmSource?: string;
|
|
22
|
+
utmMedium?: string;
|
|
23
|
+
utmCampaign?: string;
|
|
24
|
+
utmTerm?: string;
|
|
25
|
+
utmContent?: string;
|
|
26
|
+
}
|
|
27
|
+
type EventData = NonNullable<EventPayload['properties']>;
|
|
28
|
+
interface EntrolyticsOptions {
|
|
29
|
+
websiteId: string;
|
|
30
|
+
host?: string;
|
|
31
|
+
autoTrack?: boolean;
|
|
32
|
+
respectDnt?: boolean;
|
|
33
|
+
domains?: string[];
|
|
34
|
+
/** Use edge runtime endpoints for faster response times (default: true) */
|
|
35
|
+
useEdgeRuntime?: boolean;
|
|
36
|
+
/** Custom tag for A/B testing */
|
|
37
|
+
tag?: string;
|
|
38
|
+
/** Strip query parameters from URLs */
|
|
39
|
+
excludeSearch?: boolean;
|
|
40
|
+
/** Strip hash from URLs */
|
|
41
|
+
excludeHash?: boolean;
|
|
42
|
+
/** Callback before sending data */
|
|
43
|
+
beforeSend?: (type: string, payload: unknown) => unknown | null;
|
|
44
|
+
}
|
|
45
|
+
interface EntrolyticsInstance {
|
|
46
|
+
track: (eventName: string, eventData?: EventData) => void;
|
|
47
|
+
trackPageView: (url?: string, referrer?: string) => void;
|
|
48
|
+
trackRevenue: (eventName: string, revenue: number, currency?: string, data?: EventData) => void;
|
|
49
|
+
trackOutboundLink: (url: string, data?: EventData) => void;
|
|
50
|
+
identify: (data: EventData) => void;
|
|
51
|
+
identifyUser: (userId: string, traits?: EventData) => void;
|
|
52
|
+
setTag: (tag: string) => void;
|
|
53
|
+
config: EntrolyticsOptions;
|
|
54
|
+
isLoaded: Ref<boolean>;
|
|
55
|
+
isReady: Ref<boolean>;
|
|
56
|
+
}
|
|
57
|
+
declare global {
|
|
58
|
+
interface Window {
|
|
59
|
+
entrolytics?: {
|
|
60
|
+
track: (eventName?: string | object, eventData?: Record<string, unknown>) => void;
|
|
61
|
+
identify: (data: Record<string, unknown>) => void;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declare const EntrolyticsKey: InjectionKey<EntrolyticsInstance>;
|
|
66
|
+
/**
|
|
67
|
+
* Create Entrolytics Vue plugin
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Zero-config (reads from import.meta.env):
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { createApp } from 'vue';
|
|
73
|
+
* import { createEntrolytics } from '@entrolytics/vue';
|
|
74
|
+
*
|
|
75
|
+
* const app = createApp(App);
|
|
76
|
+
* app.use(createEntrolytics());
|
|
77
|
+
* app.mount('#app');
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* Explicit config:
|
|
82
|
+
* ```ts
|
|
83
|
+
* const app = createApp(App);
|
|
84
|
+
* app.use(createEntrolytics({ websiteId: 'your-website-id' }));
|
|
85
|
+
* app.mount('#app');
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function createEntrolytics(options?: Partial<EntrolyticsOptions>): {
|
|
89
|
+
install(app: App): void;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Use Entrolytics instance in composition API
|
|
93
|
+
*/
|
|
94
|
+
declare function useEntrolyticsInstance(): EntrolyticsInstance;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Main composable for accessing Entrolytics functionality
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```vue
|
|
101
|
+
* <script setup>
|
|
102
|
+
* import { useEntrolytics } from '@entrolytics/vue';
|
|
103
|
+
*
|
|
104
|
+
* const { track, identify, isLoaded } = useEntrolytics();
|
|
105
|
+
*
|
|
106
|
+
* function handleClick() {
|
|
107
|
+
* track('button_click', { variant: 'primary' });
|
|
108
|
+
* }
|
|
109
|
+
* </script>
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function useEntrolytics(): EntrolyticsInstance;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Composable for identifying users
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```vue
|
|
119
|
+
* <script setup>
|
|
120
|
+
* import { watch } from 'vue';
|
|
121
|
+
* import { useIdentify } from '@entrolytics/vue';
|
|
122
|
+
*
|
|
123
|
+
* const { identify } = useIdentify();
|
|
124
|
+
* const user = useUser(); // Your auth composable
|
|
125
|
+
*
|
|
126
|
+
* watch(user, (newUser) => {
|
|
127
|
+
* if (newUser) {
|
|
128
|
+
* identify(newUser.id, {
|
|
129
|
+
* email: newUser.email,
|
|
130
|
+
* plan: newUser.subscription
|
|
131
|
+
* });
|
|
132
|
+
* }
|
|
133
|
+
* });
|
|
134
|
+
* </script>
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function useIdentify(): {
|
|
138
|
+
identify: (data: EventData) => void;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Composable for tracking custom events
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```vue
|
|
146
|
+
* <script setup>
|
|
147
|
+
* import { useTrackEvent } from '@entrolytics/vue';
|
|
148
|
+
*
|
|
149
|
+
* const { track } = useTrackEvent();
|
|
150
|
+
*
|
|
151
|
+
* function handlePurchase() {
|
|
152
|
+
* track('purchase', { revenue: 99.99, currency: 'USD' });
|
|
153
|
+
* }
|
|
154
|
+
* </script>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function useTrackEvent(): {
|
|
158
|
+
track: (eventName: string, eventData?: EventData) => void;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Composable for tracking outbound link clicks
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```vue
|
|
166
|
+
* <script setup>
|
|
167
|
+
* import { useTrackOutboundLink } from '@entrolytics/vue';
|
|
168
|
+
*
|
|
169
|
+
* const trackOutboundLink = useTrackOutboundLink();
|
|
170
|
+
*
|
|
171
|
+
* const handleExternalClick = (url: string) => {
|
|
172
|
+
* trackOutboundLink(url, { placement: 'footer' });
|
|
173
|
+
* };
|
|
174
|
+
* </script>
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function useTrackOutboundLink(): (url: string, data?: EventData) => void;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Composable for tracking page views with vue-router
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```vue
|
|
184
|
+
* <script setup>
|
|
185
|
+
* import { useRoute } from 'vue-router';
|
|
186
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
187
|
+
*
|
|
188
|
+
* const route = useRoute();
|
|
189
|
+
* useTrackPageView(() => route.path);
|
|
190
|
+
* </script>
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```vue
|
|
195
|
+
* <script setup>
|
|
196
|
+
* import { ref } from 'vue';
|
|
197
|
+
* import { useTrackPageView } from '@entrolytics/vue';
|
|
198
|
+
*
|
|
199
|
+
* const currentPath = ref('/');
|
|
200
|
+
* useTrackPageView(currentPath);
|
|
201
|
+
* </script>
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare function useTrackPageView(pathSource: Ref<string> | (() => string), options?: {
|
|
205
|
+
immediate?: boolean;
|
|
206
|
+
}): void;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Composable for tracking revenue events
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```vue
|
|
213
|
+
* <script setup>
|
|
214
|
+
* import { useTrackRevenue } from '@entrolytics/vue';
|
|
215
|
+
*
|
|
216
|
+
* const trackRevenue = useTrackRevenue();
|
|
217
|
+
*
|
|
218
|
+
* const handlePurchase = async (product) => {
|
|
219
|
+
* await processPayment();
|
|
220
|
+
* trackRevenue('purchase', product.price, 'USD', {
|
|
221
|
+
* productId: product.id,
|
|
222
|
+
* productName: product.name
|
|
223
|
+
* });
|
|
224
|
+
* };
|
|
225
|
+
* </script>
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function useTrackRevenue(): (eventName: string, revenue: number, currency?: string, data?: EventData) => void;
|
|
229
|
+
|
|
230
|
+
export { type EntrolyticsInstance, EntrolyticsKey, type EntrolyticsOptions, type EventData, createEntrolytics, useEntrolytics, useEntrolyticsInstance, useIdentify, useTrackEvent, useTrackOutboundLink, useTrackPageView, useTrackRevenue };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { ref, inject, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
// src/plugin.ts
|
|
4
|
+
var DEFAULT_HOST = "https://entrolytics.click";
|
|
5
|
+
var SCRIPT_ID = "entrolytics-script";
|
|
6
|
+
var EntrolyticsKey = /* @__PURE__ */ Symbol("entrolytics");
|
|
7
|
+
function injectScript(options, onLoad) {
|
|
8
|
+
if (typeof window === "undefined") return;
|
|
9
|
+
if (document.getElementById(SCRIPT_ID)) {
|
|
10
|
+
onLoad?.();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const {
|
|
14
|
+
websiteId,
|
|
15
|
+
host = DEFAULT_HOST,
|
|
16
|
+
autoTrack = true,
|
|
17
|
+
respectDnt = false,
|
|
18
|
+
domains,
|
|
19
|
+
useEdgeRuntime = true,
|
|
20
|
+
tag,
|
|
21
|
+
excludeSearch = false,
|
|
22
|
+
excludeHash = false
|
|
23
|
+
} = options;
|
|
24
|
+
const script = document.createElement("script");
|
|
25
|
+
script.id = SCRIPT_ID;
|
|
26
|
+
const scriptPath = useEdgeRuntime ? "/script-edge.js" : "/script.js";
|
|
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);
|
|
50
|
+
}
|
|
51
|
+
function createEntrolytics(options = {}) {
|
|
52
|
+
const env = import.meta.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) {
|
|
57
|
+
console.warn(
|
|
58
|
+
"[@entrolytics/vue] Missing websiteId. Add VITE_ENTROLYTICS_WEBSITE_ID to your .env file or pass as option."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
throw new Error("[@entrolytics/vue] websiteId is required");
|
|
62
|
+
}
|
|
63
|
+
const finalOptions = {
|
|
64
|
+
...options,
|
|
65
|
+
websiteId,
|
|
66
|
+
host: host || options.host
|
|
67
|
+
};
|
|
68
|
+
const isLoaded = ref(false);
|
|
69
|
+
const isReady = ref(false);
|
|
70
|
+
let currentTag = finalOptions.tag;
|
|
71
|
+
const waitForTracker = (callback) => {
|
|
72
|
+
if (typeof window === "undefined") return;
|
|
73
|
+
const tryExecute = () => {
|
|
74
|
+
if (window.entrolytics) {
|
|
75
|
+
callback();
|
|
76
|
+
} else {
|
|
77
|
+
setTimeout(tryExecute, 100);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
tryExecute();
|
|
81
|
+
};
|
|
82
|
+
const track = (eventName, eventData) => {
|
|
83
|
+
waitForTracker(() => {
|
|
84
|
+
let payload = { name: eventName, data: eventData };
|
|
85
|
+
if (options.beforeSend) {
|
|
86
|
+
payload = options.beforeSend("event", payload);
|
|
87
|
+
if (payload === null) return;
|
|
88
|
+
}
|
|
89
|
+
if (currentTag) {
|
|
90
|
+
payload.tag = currentTag;
|
|
91
|
+
}
|
|
92
|
+
window.entrolytics?.track(eventName, eventData);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const trackPageView = (url, referrer) => {
|
|
96
|
+
waitForTracker(() => {
|
|
97
|
+
const payload = {};
|
|
98
|
+
if (url) payload.url = url;
|
|
99
|
+
if (referrer) payload.referrer = referrer;
|
|
100
|
+
if (currentTag) payload.tag = currentTag;
|
|
101
|
+
window.entrolytics?.track(payload);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const trackRevenue = (eventName, revenue, currency = "USD", data) => {
|
|
105
|
+
waitForTracker(() => {
|
|
106
|
+
const eventData = {
|
|
107
|
+
...data,
|
|
108
|
+
revenue,
|
|
109
|
+
currency
|
|
110
|
+
};
|
|
111
|
+
if (currentTag) {
|
|
112
|
+
eventData.tag = currentTag;
|
|
113
|
+
}
|
|
114
|
+
window.entrolytics?.track(eventName, eventData);
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const trackOutboundLink = (url, data) => {
|
|
118
|
+
waitForTracker(() => {
|
|
119
|
+
window.entrolytics?.track("outbound-link-click", {
|
|
120
|
+
...data,
|
|
121
|
+
url
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const identify = (data) => {
|
|
126
|
+
waitForTracker(() => {
|
|
127
|
+
window.entrolytics?.identify(data);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const identifyUser = (userId, traits) => {
|
|
131
|
+
waitForTracker(() => {
|
|
132
|
+
window.entrolytics?.identify({ id: userId, ...traits });
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const setTag = (tag) => {
|
|
136
|
+
currentTag = tag;
|
|
137
|
+
};
|
|
138
|
+
const instance = {
|
|
139
|
+
track,
|
|
140
|
+
trackPageView,
|
|
141
|
+
trackRevenue,
|
|
142
|
+
trackOutboundLink,
|
|
143
|
+
identify,
|
|
144
|
+
identifyUser,
|
|
145
|
+
setTag,
|
|
146
|
+
config: finalOptions,
|
|
147
|
+
isLoaded,
|
|
148
|
+
isReady
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
install(app) {
|
|
152
|
+
injectScript(finalOptions, () => {
|
|
153
|
+
isLoaded.value = true;
|
|
154
|
+
isReady.value = true;
|
|
155
|
+
});
|
|
156
|
+
app.provide(EntrolyticsKey, instance);
|
|
157
|
+
app.config.globalProperties.$entrolytics = instance;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function useEntrolyticsInstance() {
|
|
162
|
+
const instance = inject(EntrolyticsKey);
|
|
163
|
+
if (!instance) {
|
|
164
|
+
throw new Error("[@entrolytics/vue] Entrolytics plugin not installed");
|
|
165
|
+
}
|
|
166
|
+
return instance;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/composables/useEntrolytics.ts
|
|
170
|
+
function useEntrolytics() {
|
|
171
|
+
return useEntrolyticsInstance();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/composables/useIdentify.ts
|
|
175
|
+
function useIdentify() {
|
|
176
|
+
const { identify } = useEntrolyticsInstance();
|
|
177
|
+
return {
|
|
178
|
+
identify
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/composables/useTrackEvent.ts
|
|
183
|
+
function useTrackEvent() {
|
|
184
|
+
const { track } = useEntrolyticsInstance();
|
|
185
|
+
return {
|
|
186
|
+
track
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/composables/useTrackOutboundLink.ts
|
|
191
|
+
function useTrackOutboundLink() {
|
|
192
|
+
const { trackOutboundLink } = useEntrolyticsInstance();
|
|
193
|
+
return (url, data) => {
|
|
194
|
+
trackOutboundLink(url, data);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function useTrackPageView(pathSource, options) {
|
|
198
|
+
const { track } = useEntrolyticsInstance();
|
|
199
|
+
const { immediate = true } = options || {};
|
|
200
|
+
watch(
|
|
201
|
+
pathSource,
|
|
202
|
+
(newPath, oldPath) => {
|
|
203
|
+
if (newPath !== oldPath) {
|
|
204
|
+
track("pageview", {
|
|
205
|
+
url: newPath
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{ immediate }
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/composables/useTrackRevenue.ts
|
|
214
|
+
function useTrackRevenue() {
|
|
215
|
+
const { trackRevenue } = useEntrolyticsInstance();
|
|
216
|
+
return (eventName, revenue, currency = "USD", data) => {
|
|
217
|
+
trackRevenue(eventName, revenue, currency, data);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { EntrolyticsKey, createEntrolytics, useEntrolytics, useEntrolyticsInstance, useIdentify, useTrackEvent, useTrackOutboundLink, useTrackPageView, useTrackRevenue };
|
|
222
|
+
//# sourceMappingURL=index.js.map
|
|
223
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,SAAA;AAAA,IACA,IAAA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;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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@entrolytics/vue-sdk",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "Vue SDK for Entrolytics - First-party growth analytics for the edge",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"entrolytics",
|
|
7
|
+
"analytics",
|
|
8
|
+
"vue",
|
|
9
|
+
"vue3",
|
|
10
|
+
"web-analytics",
|
|
11
|
+
"tracking"
|
|
12
|
+
],
|
|
13
|
+
"author": "Entrolytics <hey@entrolytics.click>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://entrolytics.click",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/entrolytics/vue-sdk",
|
|
19
|
+
"directory": "entro-vue"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/entrolytics/vue-sdk/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"vue": "./dist/index.js",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.x"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@biomejs/biome": "2.3.13",
|
|
50
|
+
"tsup": "^8.5.1",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vue": "^3.5.27"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"vue": ">=3.5.27",
|
|
56
|
+
"vue-router": ">=4.6.4"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"vue-router": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@entrolytics/shared": "^2.2.1"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"dev": "tsup --watch",
|
|
68
|
+
"build": "tsup",
|
|
69
|
+
"lint": "biome check --write .",
|
|
70
|
+
"typecheck": "tsc --noEmit"
|
|
71
|
+
}
|
|
72
|
+
}
|