@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,105 @@
1
+ "use client";
2
+ 'use client';
3
+
4
+ // src/next/index.tsx
5
+ import { Suspense } from "react";
6
+
7
+ // src/react/index.tsx
8
+ import { useEffect } from "react";
9
+
10
+ // src/client/queue.ts
11
+ var initQueue = () => {
12
+ if (typeof window !== "undefined") {
13
+ window._hy = window._hy || [];
14
+ }
15
+ };
16
+
17
+ // src/client/utils.ts
18
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
19
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
20
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
21
+ var getDefaultHost = () => DEFAULT_HOST;
22
+
23
+ // src/client/generic.ts
24
+ var inject = (props) => {
25
+ if (!isBrowser())
26
+ return;
27
+ const { websiteId, domains, autoTrack = true, src } = props;
28
+ const hostUrl = props.hostUrl || getDefaultHost();
29
+ const scriptSrc = src || `${hostUrl}/script.js`;
30
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
31
+ return;
32
+ initQueue();
33
+ const dataset = {
34
+ websiteId,
35
+ hostUrl
36
+ };
37
+ if (domains)
38
+ dataset.domains = domains;
39
+ if (!autoTrack)
40
+ dataset.autoTrack = "false";
41
+ const script = document.createElement("script");
42
+ script.src = scriptSrc;
43
+ script.defer = true;
44
+ for (const [key, value] of Object.entries(dataset)) {
45
+ script.dataset[key] = value;
46
+ }
47
+ script.onerror = () => {
48
+ 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.";
49
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
50
+ };
51
+ document.head.appendChild(script);
52
+ };
53
+ var track = (name, data) => {
54
+ if (!isBrowser())
55
+ return;
56
+ if (window.hy) {
57
+ window.hy.track(name, data);
58
+ } else {
59
+ initQueue();
60
+ window._hy = window._hy || [];
61
+ window._hy.push(["track", name, data]);
62
+ }
63
+ };
64
+ var identify = (id, data) => {
65
+ if (!isBrowser())
66
+ return;
67
+ if (window.hy) {
68
+ window.hy.identify(id, data);
69
+ } else {
70
+ initQueue();
71
+ window._hy = window._hy || [];
72
+ window._hy.push(["identify", id, data]);
73
+ }
74
+ };
75
+ var pageview = () => {
76
+ track();
77
+ };
78
+
79
+ // src/react/index.tsx
80
+
81
+ var Analytics = (props) => {
82
+ useEffect(() => {
83
+ inject(props);
84
+ }, []);
85
+ return null;
86
+ };
87
+
88
+ // src/next/index.tsx
89
+ import { jsx } from "react/jsx-runtime";
90
+
91
+ var AnalyticsInner = (props) => /* @__PURE__ */ jsx(Analytics, {
92
+ ...props
93
+ });
94
+ var Analytics2 = (props) => /* @__PURE__ */ jsx(Suspense, {
95
+ fallback: null,
96
+ children: /* @__PURE__ */ jsx(AnalyticsInner, {
97
+ ...props
98
+ })
99
+ });
100
+ export {
101
+ track,
102
+ pageview,
103
+ identify,
104
+ Analytics2 as Analytics
105
+ };
@@ -0,0 +1,140 @@
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/nuxt/index.ts
41
+ var exports_nuxt = {};
42
+ __export(exports_nuxt, {
43
+ track: () => track,
44
+ pageview: () => pageview,
45
+ injectAnalytics: () => injectAnalytics,
46
+ identify: () => identify,
47
+ Analytics: () => Analytics
48
+ });
49
+ module.exports = __toCommonJS(exports_nuxt);
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 import_vue = require("vue");
122
+ var Analytics = import_vue.defineComponent({
123
+ name: "Analytics",
124
+ props: {
125
+ websiteId: { type: String, required: true },
126
+ hostUrl: String,
127
+ domains: String,
128
+ autoTrack: { type: Boolean, default: true },
129
+ src: String
130
+ },
131
+ setup(props) {
132
+ import_vue.onMounted(() => {
133
+ inject(props);
134
+ });
135
+ },
136
+ render: () => null
137
+ });
138
+
139
+ // src/nuxt/index.ts
140
+ var injectAnalytics = (props) => inject(props);
@@ -0,0 +1,33 @@
1
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
2
+ type AnalyticsProps = {
3
+ /** Your x-ray website ID. */
4
+ websiteId: string;
5
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
6
+ hostUrl?: string;
7
+ /** Restrict tracking to this domain only. */
8
+ domains?: string;
9
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
10
+ autoTrack?: boolean;
11
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
12
+ src?: string;
13
+ };
14
+ /** Arbitrary event data passed to `track()`. */
15
+ type EventData = Record<string, string | number | boolean | null>;
16
+ import { DefineComponent } from "vue";
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
+ declare const injectAnalytics: (props: AnalyticsProps) => void;
33
+ export { track, pageview, injectAnalytics, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,33 @@
1
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
2
+ type AnalyticsProps = {
3
+ /** Your x-ray website ID. */
4
+ websiteId: string;
5
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
6
+ hostUrl?: string;
7
+ /** Restrict tracking to this domain only. */
8
+ domains?: string;
9
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
10
+ autoTrack?: boolean;
11
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
12
+ src?: string;
13
+ };
14
+ /** Arbitrary event data passed to `track()`. */
15
+ type EventData = Record<string, string | number | boolean | null>;
16
+ import { DefineComponent } from "vue";
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
+ declare const injectAnalytics: (props: AnalyticsProps) => void;
33
+ export { track, pageview, injectAnalytics, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,97 @@
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/vue/index.ts
71
+ import { defineComponent, onMounted } from "vue";
72
+ var Analytics = defineComponent({
73
+ name: "Analytics",
74
+ props: {
75
+ websiteId: { type: String, required: true },
76
+ hostUrl: String,
77
+ domains: String,
78
+ autoTrack: { type: Boolean, default: true },
79
+ src: String
80
+ },
81
+ setup(props) {
82
+ onMounted(() => {
83
+ inject(props);
84
+ });
85
+ },
86
+ render: () => null
87
+ });
88
+
89
+ // src/nuxt/index.ts
90
+ var injectAnalytics = (props) => inject(props);
91
+ export {
92
+ track,
93
+ pageview,
94
+ injectAnalytics,
95
+ identify,
96
+ Analytics
97
+ };
@@ -0,0 +1,129 @@
1
+ "use client";
2
+ 'use client';
3
+ var import_node_module = require("node:module");
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ function __accessProp(key) {
9
+ return this[key];
10
+ }
11
+ var __toCommonJS = (from) => {
12
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
13
+ if (entry)
14
+ return entry;
15
+ entry = __defProp({}, "__esModule", { value: true });
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (var key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(entry, key))
19
+ __defProp(entry, key, {
20
+ get: __accessProp.bind(from, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ __moduleCache.set(from, entry);
25
+ return entry;
26
+ };
27
+ var __moduleCache;
28
+ var __returnValue = (v) => v;
29
+ function __exportSetter(name, newValue) {
30
+ this[name] = __returnValue.bind(null, newValue);
31
+ }
32
+ var __export = (target, all) => {
33
+ for (var name in all)
34
+ __defProp(target, name, {
35
+ get: all[name],
36
+ enumerable: true,
37
+ configurable: true,
38
+ set: __exportSetter.bind(all, name)
39
+ });
40
+ };
41
+
42
+ // src/react/index.tsx
43
+ var exports_react = {};
44
+ __export(exports_react, {
45
+ track: () => track,
46
+ pageview: () => pageview,
47
+ identify: () => identify,
48
+ Analytics: () => Analytics
49
+ });
50
+ module.exports = __toCommonJS(exports_react);
51
+ var import_react = require("react");
52
+
53
+ // src/client/queue.ts
54
+ var initQueue = () => {
55
+ if (typeof window !== "undefined") {
56
+ window._hy = window._hy || [];
57
+ }
58
+ };
59
+
60
+ // src/client/utils.ts
61
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
62
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
63
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
64
+ var getDefaultHost = () => DEFAULT_HOST;
65
+
66
+ // src/client/generic.ts
67
+ var inject = (props) => {
68
+ if (!isBrowser())
69
+ return;
70
+ const { websiteId, domains, autoTrack = true, src } = props;
71
+ const hostUrl = props.hostUrl || getDefaultHost();
72
+ const scriptSrc = src || `${hostUrl}/script.js`;
73
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
74
+ return;
75
+ initQueue();
76
+ const dataset = {
77
+ websiteId,
78
+ hostUrl
79
+ };
80
+ if (domains)
81
+ dataset.domains = domains;
82
+ if (!autoTrack)
83
+ dataset.autoTrack = "false";
84
+ const script = document.createElement("script");
85
+ script.src = scriptSrc;
86
+ script.defer = true;
87
+ for (const [key, value] of Object.entries(dataset)) {
88
+ script.dataset[key] = value;
89
+ }
90
+ script.onerror = () => {
91
+ 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.";
92
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
93
+ };
94
+ document.head.appendChild(script);
95
+ };
96
+ var track = (name, data) => {
97
+ if (!isBrowser())
98
+ return;
99
+ if (window.hy) {
100
+ window.hy.track(name, data);
101
+ } else {
102
+ initQueue();
103
+ window._hy = window._hy || [];
104
+ window._hy.push(["track", name, data]);
105
+ }
106
+ };
107
+ var identify = (id, data) => {
108
+ if (!isBrowser())
109
+ return;
110
+ if (window.hy) {
111
+ window.hy.identify(id, data);
112
+ } else {
113
+ initQueue();
114
+ window._hy = window._hy || [];
115
+ window._hy.push(["identify", id, data]);
116
+ }
117
+ };
118
+ var pageview = () => {
119
+ track();
120
+ };
121
+
122
+ // src/react/index.tsx
123
+
124
+ var Analytics = (props) => {
125
+ import_react.useEffect(() => {
126
+ inject(props);
127
+ }, []);
128
+ return null;
129
+ };
@@ -0,0 +1,31 @@
1
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
2
+ type AnalyticsProps = {
3
+ /** Your x-ray website ID. */
4
+ websiteId: string;
5
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
6
+ hostUrl?: string;
7
+ /** Restrict tracking to this domain only. */
8
+ domains?: string;
9
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
10
+ autoTrack?: boolean;
11
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
12
+ src?: string;
13
+ };
14
+ /** Arbitrary event data passed to `track()`. */
15
+ type EventData = Record<string, string | number | boolean | null>;
16
+ /**
17
+ * Track a custom event. If the tracker script hasn't loaded yet, the call is
18
+ * buffered in `window._hy` and replayed once it initialises.
19
+ */
20
+ declare const track: (name?: string, data?: EventData) => void;
21
+ /**
22
+ * Identify the current user. Buffered if the tracker script hasn't loaded yet.
23
+ */
24
+ declare const identify: (id: string, data?: EventData) => void;
25
+ /**
26
+ * Record a pageview. Equivalent to calling `track()` with no arguments — the
27
+ * remote tracker interprets this as a pageview event.
28
+ */
29
+ declare const pageview: () => void;
30
+ declare const Analytics: (props: AnalyticsProps) => null;
31
+ export { track, pageview, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,31 @@
1
+ /** Props accepted by the `<Analytics />` component and `inject()`. */
2
+ type AnalyticsProps = {
3
+ /** Your x-ray website ID. */
4
+ websiteId: string;
5
+ /** Base URL of your x-ray server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
6
+ hostUrl?: string;
7
+ /** Restrict tracking to this domain only. */
8
+ domains?: string;
9
+ /** Auto-track events on `data-hy-event` elements. @defaultValue true */
10
+ autoTrack?: boolean;
11
+ /** Custom `src` for the tracker script (overrides the default `/script.js`). */
12
+ src?: string;
13
+ };
14
+ /** Arbitrary event data passed to `track()`. */
15
+ type EventData = Record<string, string | number | boolean | null>;
16
+ /**
17
+ * Track a custom event. If the tracker script hasn't loaded yet, the call is
18
+ * buffered in `window._hy` and replayed once it initialises.
19
+ */
20
+ declare const track: (name?: string, data?: EventData) => void;
21
+ /**
22
+ * Identify the current user. Buffered if the tracker script hasn't loaded yet.
23
+ */
24
+ declare const identify: (id: string, data?: EventData) => void;
25
+ /**
26
+ * Record a pageview. Equivalent to calling `track()` with no arguments — the
27
+ * remote tracker interprets this as a pageview event.
28
+ */
29
+ declare const pageview: () => void;
30
+ declare const Analytics: (props: AnalyticsProps) => null;
31
+ export { track, pageview, identify, AnalyticsProps, Analytics };
@@ -0,0 +1,89 @@
1
+ "use client";
2
+ 'use client';
3
+
4
+ // src/react/index.tsx
5
+ import { useEffect } from "react";
6
+
7
+ // src/client/queue.ts
8
+ var initQueue = () => {
9
+ if (typeof window !== "undefined") {
10
+ window._hy = window._hy || [];
11
+ }
12
+ };
13
+
14
+ // src/client/utils.ts
15
+ var DEFAULT_HOST = "https://xray-staging.hellyeahai.com";
16
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
17
+ var isDevelopment = () => typeof process !== "undefined" && process.env?.NODE_ENV === "development";
18
+ var getDefaultHost = () => DEFAULT_HOST;
19
+
20
+ // src/client/generic.ts
21
+ var inject = (props) => {
22
+ if (!isBrowser())
23
+ return;
24
+ const { websiteId, domains, autoTrack = true, src } = props;
25
+ const hostUrl = props.hostUrl || getDefaultHost();
26
+ const scriptSrc = src || `${hostUrl}/script.js`;
27
+ if (document.head.querySelector(`script[src*="${scriptSrc}"]`))
28
+ return;
29
+ initQueue();
30
+ const dataset = {
31
+ websiteId,
32
+ hostUrl
33
+ };
34
+ if (domains)
35
+ dataset.domains = domains;
36
+ if (!autoTrack)
37
+ dataset.autoTrack = "false";
38
+ const script = document.createElement("script");
39
+ script.src = scriptSrc;
40
+ script.defer = true;
41
+ for (const [key, value] of Object.entries(dataset)) {
42
+ script.dataset[key] = value;
43
+ }
44
+ script.onerror = () => {
45
+ 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.";
46
+ console.log(`[x-ray] Failed to load script from ${scriptSrc}. ${msg}`);
47
+ };
48
+ document.head.appendChild(script);
49
+ };
50
+ var track = (name, data) => {
51
+ if (!isBrowser())
52
+ return;
53
+ if (window.hy) {
54
+ window.hy.track(name, data);
55
+ } else {
56
+ initQueue();
57
+ window._hy = window._hy || [];
58
+ window._hy.push(["track", name, data]);
59
+ }
60
+ };
61
+ var identify = (id, data) => {
62
+ if (!isBrowser())
63
+ return;
64
+ if (window.hy) {
65
+ window.hy.identify(id, data);
66
+ } else {
67
+ initQueue();
68
+ window._hy = window._hy || [];
69
+ window._hy.push(["identify", id, data]);
70
+ }
71
+ };
72
+ var pageview = () => {
73
+ track();
74
+ };
75
+
76
+ // src/react/index.tsx
77
+
78
+ var Analytics = (props) => {
79
+ useEffect(() => {
80
+ inject(props);
81
+ }, []);
82
+ return null;
83
+ };
84
+ export {
85
+ track,
86
+ pageview,
87
+ identify,
88
+ Analytics
89
+ };