@hellyeah/x-ray 0.1.0-beta.5

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.
@@ -0,0 +1,77 @@
1
+ // src/client/queue.ts
2
+ var initQueue = () => {
3
+ if (typeof window !== "undefined") {
4
+ window._hy = window._hy || [];
5
+ }
6
+ };
7
+
8
+ // src/client/utils.ts
9
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
10
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
11
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
12
+ var getDefaultHost = () => DEFAULT_HOST;
13
+
14
+ // src/client/generic.ts
15
+ var inject = (props) => {
16
+ if (!isBrowser())
17
+ return;
18
+ const { websiteId, domains, autoTrack = true, src } = props;
19
+ const hostUrl = props.hostUrl || getDefaultHost();
20
+ const scriptSrc = src || `${hostUrl}/script.js`;
21
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
22
+ return;
23
+ initQueue();
24
+ const dataset = {
25
+ websiteId,
26
+ hostUrl
27
+ };
28
+ if (domains)
29
+ dataset.domains = domains;
30
+ if (!autoTrack)
31
+ dataset.autoTrack = "false";
32
+ const script = document.createElement("script");
33
+ script.src = scriptSrc;
34
+ script.defer = true;
35
+ for (const [key, value] of Object.entries(dataset)) {
36
+ script.dataset[key] = value;
37
+ }
38
+ script.onerror = () => {
39
+ const msg = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Check that the hostUrl is correct and the script is accessible.";
40
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
41
+ };
42
+ document.head.appendChild(script);
43
+ };
44
+ var track = (name, data) => {
45
+ if (!isBrowser())
46
+ return;
47
+ if (window.hy) {
48
+ window.hy.track(name, data);
49
+ } else {
50
+ initQueue();
51
+ window._hy = window._hy || [];
52
+ window._hy.push(["track", name, data]);
53
+ }
54
+ };
55
+ var identify = (id, data) => {
56
+ if (!isBrowser())
57
+ return;
58
+ if (window.hy) {
59
+ window.hy.identify(id, data);
60
+ } else {
61
+ initQueue();
62
+ window._hy = window._hy || [];
63
+ window._hy.push(["identify", id, data]);
64
+ }
65
+ };
66
+ var pageview = () => {
67
+ track();
68
+ };
69
+
70
+ // src/svelte/index.ts
71
+ var injectAnalytics = (props) => inject(props);
72
+ export {
73
+ track,
74
+ pageview,
75
+ injectAnalytics,
76
+ identify
77
+ };
@@ -0,0 +1,136 @@
1
+ var import_node_module = require("node:module");
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/vue/index.ts
41
+ var exports_vue = {};
42
+ __export(exports_vue, {
43
+ track: () => track,
44
+ pageview: () => pageview,
45
+ identify: () => identify,
46
+ Analytics: () => Analytics
47
+ });
48
+ module.exports = __toCommonJS(exports_vue);
49
+ var import_vue = require("vue");
50
+
51
+ // src/client/queue.ts
52
+ var initQueue = () => {
53
+ if (typeof window !== "undefined") {
54
+ window._hy = window._hy || [];
55
+ }
56
+ };
57
+
58
+ // src/client/utils.ts
59
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
60
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
61
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
62
+ var getDefaultHost = () => DEFAULT_HOST;
63
+
64
+ // src/client/generic.ts
65
+ var inject = (props) => {
66
+ if (!isBrowser())
67
+ return;
68
+ const { websiteId, domains, autoTrack = true, src } = props;
69
+ const hostUrl = props.hostUrl || getDefaultHost();
70
+ const scriptSrc = src || `${hostUrl}/script.js`;
71
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
72
+ return;
73
+ initQueue();
74
+ const dataset = {
75
+ websiteId,
76
+ hostUrl
77
+ };
78
+ if (domains)
79
+ dataset.domains = domains;
80
+ if (!autoTrack)
81
+ dataset.autoTrack = "false";
82
+ const script = document.createElement("script");
83
+ script.src = scriptSrc;
84
+ script.defer = true;
85
+ for (const [key, value] of Object.entries(dataset)) {
86
+ script.dataset[key] = value;
87
+ }
88
+ script.onerror = () => {
89
+ const msg = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Check that the hostUrl is correct and the script is accessible.";
90
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
91
+ };
92
+ document.head.appendChild(script);
93
+ };
94
+ var track = (name, data) => {
95
+ if (!isBrowser())
96
+ return;
97
+ if (window.hy) {
98
+ window.hy.track(name, data);
99
+ } else {
100
+ initQueue();
101
+ window._hy = window._hy || [];
102
+ window._hy.push(["track", name, data]);
103
+ }
104
+ };
105
+ var identify = (id, data) => {
106
+ if (!isBrowser())
107
+ return;
108
+ if (window.hy) {
109
+ window.hy.identify(id, data);
110
+ } else {
111
+ initQueue();
112
+ window._hy = window._hy || [];
113
+ window._hy.push(["identify", id, data]);
114
+ }
115
+ };
116
+ var pageview = () => {
117
+ track();
118
+ };
119
+
120
+ // src/vue/index.ts
121
+ var Analytics = import_vue.defineComponent({
122
+ name: "Analytics",
123
+ props: {
124
+ websiteId: { type: String, required: true },
125
+ hostUrl: String,
126
+ domains: String,
127
+ autoTrack: { type: Boolean, default: true },
128
+ src: String
129
+ },
130
+ setup(props) {
131
+ import_vue.onMounted(() => {
132
+ inject(props);
133
+ });
134
+ },
135
+ render: () => null
136
+ });
@@ -0,0 +1,32 @@
1
+ import { DefineComponent } from "vue";
2
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
3
+ type AnalyticsProps = {
4
+ /** Your x-ray website ID. */
5
+ websiteId: string;
6
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
7
+ hostUrl?: string;
8
+ /** Restrict tracking to this domain only. */
9
+ domains?: string;
10
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
11
+ autoTrack?: boolean;
12
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
13
+ src?: string;
14
+ };
15
+ /** Arbitrary event data passed to `track()`. */
16
+ type EventData = Record<string, string | number | boolean | null>;
17
+ /**
18
+ * Track a custom event. If the tracker script hasn't loaded yet, the call is
19
+ * buffered in `window._hy` and replayed once it initialises.
20
+ */
21
+ declare const track: (name?: string, data?: EventData) => void;
22
+ /**
23
+ * Identify the current user. Buffered if the tracker script hasn't loaded yet.
24
+ */
25
+ declare const identify: (id: string, data?: EventData) => void;
26
+ /**
27
+ * Record a pageview. Equivalent to calling `track()` with no arguments — the
28
+ * remote tracker interprets this as a pageview event.
29
+ */
30
+ declare const pageview: () => void;
31
+ declare const Analytics: DefineComponent<AnalyticsProps>;
32
+ export { track, pageview, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,32 @@
1
+ import { DefineComponent } from "vue";
2
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
3
+ type AnalyticsProps = {
4
+ /** Your x-ray website ID. */
5
+ websiteId: string;
6
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
7
+ hostUrl?: string;
8
+ /** Restrict tracking to this domain only. */
9
+ domains?: string;
10
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
11
+ autoTrack?: boolean;
12
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
13
+ src?: string;
14
+ };
15
+ /** Arbitrary event data passed to `track()`. */
16
+ type EventData = Record<string, string | number | boolean | null>;
17
+ /**
18
+ * Track a custom event. If the tracker script hasn't loaded yet, the call is
19
+ * buffered in `window._hy` and replayed once it initialises.
20
+ */
21
+ declare const track: (name?: string, data?: EventData) => void;
22
+ /**
23
+ * Identify the current user. Buffered if the tracker script hasn't loaded yet.
24
+ */
25
+ declare const identify: (id: string, data?: EventData) => void;
26
+ /**
27
+ * Record a pageview. Equivalent to calling `track()` with no arguments — the
28
+ * remote tracker interprets this as a pageview event.
29
+ */
30
+ declare const pageview: () => void;
31
+ declare const Analytics: DefineComponent<AnalyticsProps>;
32
+ export { track, pageview, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,95 @@
1
+ // src/vue/index.ts
2
+ import { defineComponent, onMounted } from "vue";
3
+
4
+ // src/client/queue.ts
5
+ var initQueue = () => {
6
+ if (typeof window !== "undefined") {
7
+ window._hy = window._hy || [];
8
+ }
9
+ };
10
+
11
+ // src/client/utils.ts
12
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
13
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
14
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
15
+ var getDefaultHost = () => DEFAULT_HOST;
16
+
17
+ // src/client/generic.ts
18
+ var inject = (props) => {
19
+ if (!isBrowser())
20
+ return;
21
+ const { websiteId, domains, autoTrack = true, src } = props;
22
+ const hostUrl = props.hostUrl || getDefaultHost();
23
+ const scriptSrc = src || `${hostUrl}/script.js`;
24
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
25
+ return;
26
+ initQueue();
27
+ const dataset = {
28
+ websiteId,
29
+ hostUrl
30
+ };
31
+ if (domains)
32
+ dataset.domains = domains;
33
+ if (!autoTrack)
34
+ dataset.autoTrack = "false";
35
+ const script = document.createElement("script");
36
+ script.src = scriptSrc;
37
+ script.defer = true;
38
+ for (const [key, value] of Object.entries(dataset)) {
39
+ script.dataset[key] = value;
40
+ }
41
+ script.onerror = () => {
42
+ const msg = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Check that the hostUrl is correct and the script is accessible.";
43
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
44
+ };
45
+ document.head.appendChild(script);
46
+ };
47
+ var track = (name, data) => {
48
+ if (!isBrowser())
49
+ return;
50
+ if (window.hy) {
51
+ window.hy.track(name, data);
52
+ } else {
53
+ initQueue();
54
+ window._hy = window._hy || [];
55
+ window._hy.push(["track", name, data]);
56
+ }
57
+ };
58
+ var identify = (id, data) => {
59
+ if (!isBrowser())
60
+ return;
61
+ if (window.hy) {
62
+ window.hy.identify(id, data);
63
+ } else {
64
+ initQueue();
65
+ window._hy = window._hy || [];
66
+ window._hy.push(["identify", id, data]);
67
+ }
68
+ };
69
+ var pageview = () => {
70
+ track();
71
+ };
72
+
73
+ // src/vue/index.ts
74
+ var Analytics = defineComponent({
75
+ name: "Analytics",
76
+ props: {
77
+ websiteId: { type: String, required: true },
78
+ hostUrl: String,
79
+ domains: String,
80
+ autoTrack: { type: Boolean, default: true },
81
+ src: String
82
+ },
83
+ setup(props) {
84
+ onMounted(() => {
85
+ inject(props);
86
+ });
87
+ },
88
+ render: () => null
89
+ });
90
+ export {
91
+ track,
92
+ pageview,
93
+ identify,
94
+ Analytics
95
+ };
package/package.json ADDED
@@ -0,0 +1,255 @@
1
+ {
2
+ "name": "@hellyeah/x-ray",
3
+ "version": "0.1.0-beta.5",
4
+ "description": "Multi-platform analytics SDK for browser, React, Next.js, Remix, Vue, Svelte, Nuxt, Astro, and server environments",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/finalroundai/xray-sdk.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "keywords": [
12
+ "analytics",
13
+ "tracking",
14
+ "react",
15
+ "nextjs",
16
+ "remix",
17
+ "vue",
18
+ "svelte",
19
+ "sveltekit",
20
+ "nuxt",
21
+ "astro",
22
+ "server",
23
+ "xray"
24
+ ],
25
+ "sideEffects": false,
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "module-sync": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "import": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/index.d.cts",
41
+ "default": "./dist/index.cjs"
42
+ }
43
+ },
44
+ "./react": {
45
+ "module-sync": {
46
+ "types": "./dist/react/index.d.ts",
47
+ "default": "./dist/react/index.js"
48
+ },
49
+ "import": {
50
+ "types": "./dist/react/index.d.ts",
51
+ "default": "./dist/react/index.js"
52
+ },
53
+ "require": {
54
+ "types": "./dist/react/index.d.cts",
55
+ "default": "./dist/react/index.cjs"
56
+ }
57
+ },
58
+ "./next": {
59
+ "module-sync": {
60
+ "types": "./dist/next/index.d.ts",
61
+ "default": "./dist/next/index.js"
62
+ },
63
+ "import": {
64
+ "types": "./dist/next/index.d.ts",
65
+ "default": "./dist/next/index.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/next/index.d.cts",
69
+ "default": "./dist/next/index.cjs"
70
+ }
71
+ },
72
+ "./server": {
73
+ "module-sync": {
74
+ "types": "./dist/server/index.d.ts",
75
+ "default": "./dist/server/index.js"
76
+ },
77
+ "import": {
78
+ "types": "./dist/server/index.d.ts",
79
+ "default": "./dist/server/index.js"
80
+ },
81
+ "require": {
82
+ "types": "./dist/server/index.d.cts",
83
+ "default": "./dist/server/index.cjs"
84
+ }
85
+ },
86
+ "./remix": {
87
+ "module-sync": {
88
+ "types": "./dist/remix/index.d.ts",
89
+ "default": "./dist/remix/index.js"
90
+ },
91
+ "import": {
92
+ "types": "./dist/remix/index.d.ts",
93
+ "default": "./dist/remix/index.js"
94
+ },
95
+ "require": {
96
+ "types": "./dist/remix/index.d.cts",
97
+ "default": "./dist/remix/index.cjs"
98
+ }
99
+ },
100
+ "./vue": {
101
+ "module-sync": {
102
+ "types": "./dist/vue/index.d.ts",
103
+ "default": "./dist/vue/index.js"
104
+ },
105
+ "import": {
106
+ "types": "./dist/vue/index.d.ts",
107
+ "default": "./dist/vue/index.js"
108
+ },
109
+ "require": {
110
+ "types": "./dist/vue/index.d.cts",
111
+ "default": "./dist/vue/index.cjs"
112
+ }
113
+ },
114
+ "./svelte": {
115
+ "module-sync": {
116
+ "types": "./dist/svelte/index.d.ts",
117
+ "default": "./dist/svelte/index.js"
118
+ },
119
+ "import": {
120
+ "types": "./dist/svelte/index.d.ts",
121
+ "default": "./dist/svelte/index.js"
122
+ },
123
+ "require": {
124
+ "types": "./dist/svelte/index.d.cts",
125
+ "default": "./dist/svelte/index.cjs"
126
+ }
127
+ },
128
+ "./nuxt": {
129
+ "module-sync": {
130
+ "types": "./dist/nuxt/index.d.ts",
131
+ "default": "./dist/nuxt/index.js"
132
+ },
133
+ "import": {
134
+ "types": "./dist/nuxt/index.d.ts",
135
+ "default": "./dist/nuxt/index.js"
136
+ },
137
+ "require": {
138
+ "types": "./dist/nuxt/index.d.cts",
139
+ "default": "./dist/nuxt/index.cjs"
140
+ }
141
+ },
142
+ "./astro": {
143
+ "module-sync": {
144
+ "types": "./dist/astro/index.d.ts",
145
+ "default": "./dist/astro/index.js"
146
+ },
147
+ "import": {
148
+ "types": "./dist/astro/index.d.ts",
149
+ "default": "./dist/astro/index.js"
150
+ },
151
+ "require": {
152
+ "types": "./dist/astro/index.d.cts",
153
+ "default": "./dist/astro/index.cjs"
154
+ }
155
+ },
156
+ "./package.json": "./package.json"
157
+ },
158
+ "typesVersions": {
159
+ "*": {
160
+ "*": [
161
+ "dist/index.d.ts"
162
+ ],
163
+ "react": [
164
+ "dist/react/index.d.ts"
165
+ ],
166
+ "next": [
167
+ "dist/next/index.d.ts"
168
+ ],
169
+ "server": [
170
+ "dist/server/index.d.ts"
171
+ ],
172
+ "remix": [
173
+ "dist/remix/index.d.ts"
174
+ ],
175
+ "vue": [
176
+ "dist/vue/index.d.ts"
177
+ ],
178
+ "svelte": [
179
+ "dist/svelte/index.d.ts"
180
+ ],
181
+ "nuxt": [
182
+ "dist/nuxt/index.d.ts"
183
+ ],
184
+ "astro": [
185
+ "dist/astro/index.d.ts"
186
+ ]
187
+ }
188
+ },
189
+ "files": [
190
+ "dist",
191
+ "README.md"
192
+ ],
193
+ "publishConfig": {
194
+ "access": "public"
195
+ },
196
+ "engines": {
197
+ "node": ">=20.19.0"
198
+ },
199
+ "devDependencies": {
200
+ "@remix-run/react": "^2",
201
+ "@types/bun": "latest",
202
+ "@types/react": "^19",
203
+ "@types/react-dom": "^19.2.3",
204
+ "bunup": "^0.16.31",
205
+ "happy-dom": "^20.8.4",
206
+ "next": "^15",
207
+ "react": "^19",
208
+ "react-dom": "^19.2.4",
209
+ "vue": "^3"
210
+ },
211
+ "peerDependencies": {
212
+ "typescript": "^5",
213
+ "react": "^18 || ^19",
214
+ "next": "^14 || ^15",
215
+ "@remix-run/react": "^2",
216
+ "vue": "^3",
217
+ "svelte": "^4 || ^5",
218
+ "nuxt": "^3",
219
+ "astro": "^4 || ^5"
220
+ },
221
+ "peerDependenciesMeta": {
222
+ "react": {
223
+ "optional": true
224
+ },
225
+ "next": {
226
+ "optional": true
227
+ },
228
+ "@remix-run/react": {
229
+ "optional": true
230
+ },
231
+ "vue": {
232
+ "optional": true
233
+ },
234
+ "svelte": {
235
+ "optional": true
236
+ },
237
+ "nuxt": {
238
+ "optional": true
239
+ },
240
+ "astro": {
241
+ "optional": true
242
+ },
243
+ "typescript": {
244
+ "optional": true
245
+ }
246
+ },
247
+ "scripts": {
248
+ "prepublishOnly": "bun run typecheck && bun run test && bun run build",
249
+ "build": "NODE_ENV=production bunup",
250
+ "typecheck": "tsc --noEmit",
251
+ "test": "bun test",
252
+ "test:local": "bun run build && npm pack",
253
+ "release": "bun run build && npm publish --provenance"
254
+ }
255
+ }