@workleap/mixpanel 1.1.1 → 2.0.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +29 -5
  2. package/README.md +1 -1
  3. package/dist/js/HasExecutedGuard.d.ts +6 -0
  4. package/dist/js/HasExecutedGuard.js +21 -0
  5. package/dist/js/HasExecutedGuard.js.map +1 -0
  6. package/dist/{env.js → js/env.js} +1 -1
  7. package/dist/js/env.js.map +1 -0
  8. package/dist/js/getMixpanelTrackingFunction.d.ts +14 -0
  9. package/dist/js/getMixpanelTrackingFunction.js +21 -0
  10. package/dist/js/getMixpanelTrackingFunction.js.map +1 -0
  11. package/dist/js/index.d.ts +4 -0
  12. package/dist/js/index.js +14 -0
  13. package/dist/js/index.js.map +1 -0
  14. package/dist/js/initializeMixpanel.d.ts +46 -0
  15. package/dist/js/initializeMixpanel.js +112 -0
  16. package/dist/js/initializeMixpanel.js.map +1 -0
  17. package/dist/js/properties.d.ts +30 -0
  18. package/dist/js/properties.js +43 -0
  19. package/dist/js/properties.js.map +1 -0
  20. package/dist/{utils.js → js/utils.js} +1 -1
  21. package/dist/js/utils.js.map +1 -0
  22. package/dist/react/index.d.ts +1 -0
  23. package/dist/react/index.js +10 -0
  24. package/dist/react/index.js.map +1 -0
  25. package/dist/react/useMixpanelTracking.d.ts +11 -0
  26. package/dist/react/useMixpanelTracking.js +17 -0
  27. package/dist/react/useMixpanelTracking.js.map +1 -0
  28. package/package.json +33 -18
  29. package/src/js/HasExecutedGuard.ts +19 -0
  30. package/src/{env.ts → js/env.ts} +2 -0
  31. package/src/js/getMixpanelTrackingFunction.ts +31 -0
  32. package/src/js/index.ts +5 -0
  33. package/src/js/initializeMixpanel.ts +147 -0
  34. package/src/js/properties.ts +41 -0
  35. package/src/react/index.ts +2 -0
  36. package/src/react/useMixpanelTracking.ts +15 -0
  37. package/dist/createTrackingFunction.d.ts +0 -45
  38. package/dist/createTrackingFunction.js +0 -39
  39. package/dist/createTrackingFunction.js.map +0 -1
  40. package/dist/env.js.map +0 -1
  41. package/dist/index.d.ts +0 -3
  42. package/dist/index.js +0 -7
  43. package/dist/index.js.map +0 -1
  44. package/dist/properties.d.ts +0 -13
  45. package/dist/properties.js +0 -39
  46. package/dist/properties.js.map +0 -1
  47. package/dist/utils.js.map +0 -1
  48. package/src/createTrackingFunction.ts +0 -71
  49. package/src/index.ts +0 -4
  50. package/src/properties.ts +0 -36
  51. /package/dist/{env.d.ts → js/env.d.ts} +0 -0
  52. /package/dist/{utils.d.ts → js/utils.d.ts} +0 -0
  53. /package/src/{utils.ts → js/utils.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,29 +1,53 @@
1
1
  # @workleap/mixpanel
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#29](https://github.com/workleap/wl-telemetry/pull/29) [`812f691`](https://github.com/workleap/wl-telemetry/commit/812f691676c60a7748b0db87e38e3b86591e2a85) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Those new packages provides an integration experience for telemetry. By linking session data, performance traces, and user interactions through consistent identifiers. It becomes possible to trace a single application event across systems, from backend performance to frontend behavior to product impact. This integration streamlines will hopefully enables faster, and more informed decision-making.
8
+
9
+ For migration instruction, visit the [migrate](https://workleap.github.io/wl-telemetry/introduction/migrate/) page.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`812f691`](https://github.com/workleap/wl-telemetry/commit/812f691676c60a7748b0db87e38e3b86591e2a85)]:
14
+ - @workleap/telemetry@1.0.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [[`c46c378`](https://github.com/workleap/wl-telemetry/commit/c46c3783079835063d1969f547b0d4947d7bd573)]:
19
+ - @workleap/telemetry@1.0.0
20
+
21
+ ## 1.1.2
22
+
23
+ ### Patch Changes
24
+
25
+ - [#22](https://github.com/workleap/wl-telemetry/pull/22) [`0c437d0`](https://github.com/workleap/wl-telemetry/commit/0c437d055a2f0fcdfd5130a9a2239631d6cdfc4d) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated dependencies.
26
+
3
27
  ## 1.1.1
4
28
 
5
29
  ### Patch Changes
6
30
 
7
- - [#14](https://github.com/workleap/wl-tracking/pull/14) [`a639574`](https://github.com/workleap/wl-tracking/commit/a639574d5d9f1f3a4227db6e356e6a71fad6af1d) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Fixed an issue where the payload had the wrong name for productIdentifier and targetProductIdentifier
31
+ - [#14](https://github.com/workleap/wl-telemetry/pull/14) [`a639574`](https://github.com/workleap/wl-telemetry/commit/a639574d5d9f1f3a4227db6e356e6a71fad6af1d) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Fixed an issue where the payload had the wrong name for productIdentifier and targetProductIdentifier
8
32
 
9
33
  ## 1.1.0
10
34
 
11
35
  ### Minor Changes
12
36
 
13
- - [#8](https://github.com/workleap/wl-tracking/pull/8) [`5199dc1`](https://github.com/workleap/wl-tracking/commit/5199dc1cce5d9ab05c0cda84be2ac81cdf6a9456) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add the possibility to specify only the environment to use, and the tracking function will provide the correct URL
37
+ - [#8](https://github.com/workleap/wl-telemetry/pull/8) [`5199dc1`](https://github.com/workleap/wl-telemetry/commit/5199dc1cce5d9ab05c0cda84be2ac81cdf6a9456) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add the possibility to specify only the environment to use, and the tracking function will provide the correct URL
14
38
 
15
39
  ### Patch Changes
16
40
 
17
- - [#6](https://github.com/workleap/wl-tracking/pull/6) [`e26a764`](https://github.com/workleap/wl-tracking/commit/e26a764282f881b4ab50009db1f88879e8a02776) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Export types from the packages
41
+ - [#6](https://github.com/workleap/wl-telemetry/pull/6) [`e26a764`](https://github.com/workleap/wl-telemetry/commit/e26a764282f881b4ab50009db1f88879e8a02776) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Export types from the packages
18
42
 
19
43
  ## 1.0.2
20
44
 
21
45
  ### Patch Changes
22
46
 
23
- - [#4](https://github.com/workleap/wl-tracking/pull/4) [`3430c6d`](https://github.com/workleap/wl-tracking/commit/3430c6dc2ccf381a96f8d1d03e7f695670d9e9d2) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Added cjs entry point to our package
47
+ - [#4](https://github.com/workleap/wl-telemetry/pull/4) [`3430c6d`](https://github.com/workleap/wl-telemetry/commit/3430c6dc2ccf381a96f8d1d03e7f695670d9e9d2) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Added cjs entry point to our package
24
48
 
25
49
  ## 1.0.1
26
50
 
27
51
  ### Patch Changes
28
52
 
29
- - [#2](https://github.com/workleap/wl-tracking/pull/2) [`5e904ad`](https://github.com/workleap/wl-tracking/commit/5e904ad5117d86d0d7e7a727bfabe3f2db427f62) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add readme to package
53
+ - [#2](https://github.com/workleap/wl-telemetry/pull/2) [`5e904ad`](https://github.com/workleap/wl-telemetry/commit/5e904ad5117d86d0d7e7a727bfabe3f2db427f62) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add readme to package
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Usage
4
4
 
5
- View the [user's documentation](https://workleap.github.io/wl-tracking/).
5
+ View the [user's documentation](https://workleap.github.io/wl-telemetry/).
6
6
 
7
7
  ## 🤝 Contributing
8
8
 
@@ -0,0 +1,6 @@
1
+ export declare class HasExecutedGuard {
2
+ #private;
3
+ throw(message: string): void;
4
+ get hasExecuted(): boolean;
5
+ reset(): void;
6
+ }
@@ -0,0 +1,21 @@
1
+
2
+ ;// CONCATENATED MODULE: ./src/js/HasExecutedGuard.ts
3
+ class HasExecutedGuard {
4
+ #hasExecuted = false;
5
+ throw(message) {
6
+ if (this.#hasExecuted) {
7
+ throw new Error(message);
8
+ }
9
+ this.#hasExecuted = true;
10
+ }
11
+ get hasExecuted() {
12
+ return this.#hasExecuted;
13
+ }
14
+ reset() {
15
+ this.#hasExecuted = false;
16
+ }
17
+ }
18
+
19
+ export { HasExecutedGuard };
20
+
21
+ //# sourceMappingURL=HasExecutedGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/HasExecutedGuard.js","sources":["webpack://@workleap/mixpanel/./src/js/HasExecutedGuard.ts"],"sourcesContent":["export class HasExecutedGuard {\n #hasExecuted: boolean = false;\n\n throw(message: string) {\n if (this.#hasExecuted) {\n throw new Error(message);\n }\n\n this.#hasExecuted = true;\n }\n\n get hasExecuted() {\n return this.#hasExecuted;\n }\n\n reset() {\n this.#hasExecuted = false;\n }\n}\n"],"names":["HasExecutedGuard","message","Error"],"mappings":";;AAAO,MAAMA;IACT,YAAY,GAAY,MAAM;IAE9B,MAAMC,OAAe,EAAE;QACnB,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,MAAM,IAAIC,MAAMD;QACpB;QAEA,IAAI,CAAC,YAAY,GAAG;IACxB;IAEA,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,YAAY;IAC5B;IAEA,QAAQ;QACJ,IAAI,CAAC,YAAY,GAAG;IACxB;AACJ"}
@@ -1,5 +1,5 @@
1
1
 
2
- ;// CONCATENATED MODULE: ./src/env.ts?__rslib_entry__
2
+ ;// CONCATENATED MODULE: ./src/js/env.ts
3
3
  const EnvironmentList = [
4
4
  "development",
5
5
  "staging",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/env.js","sources":["webpack://@workleap/mixpanel/./src/js/env.ts"],"sourcesContent":["\nconst EnvironmentList = [\"development\", \"staging\", \"production\", \"local\", \"msw\"] as const;\n\nexport type Environment = typeof EnvironmentList[number];\n\nconst NavigationApiBaseUrl: Record<Environment, string> = {\n \"production\": \"https://api.platform.workleap.com/shell/navigation/\",\n \"staging\": \"https://api.platform.workleap-stg.com/shell/navigation/\",\n \"development\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"local\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"msw\": \"/api/shell/navigation/\"\n};\n\n// Cannot use URL() because it doesn't support relative base url: https://github.com/whatwg/url/issues/531.\nfunction resolveApiUrl(path: string, baseUrl: string | undefined) : string {\n return `${baseUrl}${baseUrl!.endsWith(\"/\") ? \"\" : \"/\"}${path.startsWith(\"/\") ? path.substring(1) : path}`;\n}\n\nexport function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {\n let baseUrl: string;\n\n if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {\n baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];\n } else {\n baseUrl = envOrTrackingApiBaseUrl;\n }\n\n return resolveApiUrl(\"tracking/track\", baseUrl);\n}\n"],"names":["EnvironmentList","NavigationApiBaseUrl","resolveApiUrl","path","baseUrl","getTrackingEndpoint","envOrTrackingApiBaseUrl"],"mappings":";;AACA,MAAMA,kBAAkB;IAAC;IAAe;IAAW;IAAc;IAAS;CAAM;AAIhF,MAAMC,uBAAoD;IACtD,cAAc;IACd,WAAW;IACX,eAAe;IACf,SAAS;IACT,OAAO;AACX;AAEA,2GAA2G;AAC3G,SAASC,cAAcC,IAAY,EAAEC,OAA2B;IAC5D,OAAO,GAAGA,UAAUA,QAAS,QAAQ,CAAC,OAAO,KAAK,MAAMD,KAAK,UAAU,CAAC,OAAOA,KAAK,SAAS,CAAC,KAAKA,MAAM;AAC7G;AAEO,SAASE,oBAAoBC,uBAAoD;IACpF,IAAIF;IAEJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAc,kBAAkBE;AAC3C"}
@@ -0,0 +1,14 @@
1
+ import type { MixpanelTrackingFunction } from "./initializeMixpanel.ts";
2
+ export declare const TrackingFunctionName = "__WLP_MIXPANEL_TRACKING_FUNCTION__";
3
+ /**
4
+ * @see https://workleap.github.io/wl-telemetry
5
+ */
6
+ export interface GetMixpanelTrackingFunctionOptions {
7
+ throwOnUndefined?: boolean;
8
+ }
9
+ /**
10
+ * Retrieve the track function.
11
+ * @returns A function that sends tracking events to the tracking API.
12
+ * @see https://workleap.github.io/wl-telemetry
13
+ */
14
+ export declare function getMixpanelTrackingFunction(options?: GetMixpanelTrackingFunctionOptions): MixpanelTrackingFunction;
@@ -0,0 +1,21 @@
1
+
2
+ ;// CONCATENATED MODULE: ./src/js/getMixpanelTrackingFunction.ts
3
+ const TrackingFunctionName = "__WLP_MIXPANEL_TRACKING_FUNCTION__";
4
+ /**
5
+ * Retrieve the track function.
6
+ * @returns A function that sends tracking events to the tracking API.
7
+ * @see https://workleap.github.io/wl-telemetry
8
+ */ function getMixpanelTrackingFunction(options = {}) {
9
+ const { throwOnUndefined = true } = options;
10
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
+ // @ts-ignore
12
+ const trackFunction = globalThis[TrackingFunctionName];
13
+ if (!trackFunction && throwOnUndefined) {
14
+ throw new Error("[mixpanel] The tracking function is undefined. Did you call the \"initializeMixpanel\" function?");
15
+ }
16
+ return trackFunction;
17
+ }
18
+
19
+ export { TrackingFunctionName, getMixpanelTrackingFunction };
20
+
21
+ //# sourceMappingURL=getMixpanelTrackingFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/getMixpanelTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/getMixpanelTrackingFunction.ts"],"sourcesContent":["import type { MixpanelTrackingFunction } from \"./initializeMixpanel.ts\";\n\nexport const TrackingFunctionName = \"__WLP_MIXPANEL_TRACKING_FUNCTION__\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface GetMixpanelTrackingFunctionOptions {\n throwOnUndefined?: boolean;\n}\n\n/**\n * Retrieve the track function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function getMixpanelTrackingFunction(options: GetMixpanelTrackingFunctionOptions = {}) {\n const {\n throwOnUndefined = true\n } = options;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const trackFunction = globalThis[TrackingFunctionName];\n\n if (!trackFunction && throwOnUndefined) {\n throw new Error(\"[mixpanel] The tracking function is undefined. Did you call the \\\"initializeMixpanel\\\" function?\");\n }\n\n return trackFunction as MixpanelTrackingFunction;\n}\n"],"names":["TrackingFunctionName","getMixpanelTrackingFunction","options","throwOnUndefined","trackFunction","globalThis","Error"],"mappings":";;AAEO,MAAMA,uBAAuB,qCAAqC;AASzE;;;;CAIC,GACM,SAASC,4BAA4BC,UAA8C,CAAC,CAAC;IACxF,MAAM,EACFC,mBAAmB,IAAI,EAC1B,GAAGD;IAEJ,6DAA6D;IAC7D,aAAa;IACb,MAAME,gBAAgBC,UAAU,CAACL,qBAAqB;IAEtD,IAAI,CAACI,iBAAiBD,kBAAkB;QACpC,MAAM,IAAIG,MAAM;IACpB;IAEA,OAAOF;AACX"}
@@ -0,0 +1,4 @@
1
+ export type { Environment } from "./env.ts";
2
+ export { getMixpanelTrackingFunction } from "./getMixpanelTrackingFunction.ts";
3
+ export { initializeMixpanel, type InitializeMixpanelOptions, type MixpanelTrackingFunction, type MixpanelTrackingOptions } from "./initializeMixpanel.ts";
4
+ export type { MixpanelTrackEventProperties } from "./properties.ts";
@@ -0,0 +1,14 @@
1
+ import { getMixpanelTrackingFunction } from "./getMixpanelTrackingFunction.js";
2
+ import { initializeMixpanel } from "./initializeMixpanel.js";
3
+
4
+ ;// CONCATENATED MODULE: external "./getMixpanelTrackingFunction.js"
5
+
6
+ ;// CONCATENATED MODULE: external "./initializeMixpanel.js"
7
+
8
+ ;// CONCATENATED MODULE: ./src/js/index.ts
9
+
10
+
11
+
12
+ export { getMixpanelTrackingFunction, initializeMixpanel };
13
+
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/index.js","sources":["webpack://@workleap/mixpanel/./src/js/index.ts"],"sourcesContent":["export type { Environment } from \"./env.ts\";\nexport { getMixpanelTrackingFunction } from \"./getMixpanelTrackingFunction.ts\";\nexport { initializeMixpanel, type InitializeMixpanelOptions, type MixpanelTrackingFunction, type MixpanelTrackingOptions } from \"./initializeMixpanel.ts\";\nexport type { MixpanelTrackEventProperties } from \"./properties.ts\";\n\n"],"names":["getMixpanelTrackingFunction","initializeMixpanel"],"mappings":";;;;;;;;AAC+E;AAC2E"}
@@ -0,0 +1,46 @@
1
+ import { type Environment } from "./env.ts";
2
+ import { type MixpanelTrackEventProperties } from "./properties.ts";
3
+ /**
4
+ * @see https://workleap.github.io/wl-telemetry
5
+ */
6
+ export interface MixpanelTrackingOptions {
7
+ /**
8
+ * The product identifier of the target product.
9
+ */
10
+ targetProductId?: string;
11
+ /**
12
+ * Whether to keep the connection alive for the tracking request.
13
+ * It is mostly used for tracking links where the user might navigate away before the request is completed.
14
+ *
15
+ * Caution! The body size for keepalive requests is limited to 64 kibibytes.
16
+ *
17
+ * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
18
+ *
19
+ * @default false
20
+ */
21
+ keepAlive?: boolean;
22
+ }
23
+ /**
24
+ * A function that sends tracking events to the tracking API.
25
+ * @param eventName The name of the event to track.
26
+ * @param properties The properties to send with the event.
27
+ * @param options Options for tracking the event.
28
+ * @see https://workleap.github.io/wl-telemetry
29
+ */
30
+ export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelTrackEventProperties, options?: MixpanelTrackingOptions) => Promise<void>;
31
+ /**
32
+ * @see https://workleap.github.io/wl-telemetry
33
+ */
34
+ export interface InitializeMixpanelOptions {
35
+ verbose?: boolean;
36
+ }
37
+ export declare function __resetInitializationGuard(): void;
38
+ /**
39
+ * Creates a function that sends tracking events to the tracking API.
40
+ * @param productId Your product identifier.
41
+ * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
42
+ * @param options Options for creating the tracking function.
43
+ * @returns A function that sends tracking events to the tracking API.
44
+ * @see https://workleap.github.io/wl-telemetry
45
+ */
46
+ export declare function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options?: InitializeMixpanelOptions): MixpanelTrackingFunction;
@@ -0,0 +1,112 @@
1
+ import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
2
+ import { getTrackingEndpoint } from "./env.js";
3
+ import { TrackingFunctionName } from "./getMixpanelTrackingFunction.js";
4
+ import { HasExecutedGuard } from "./HasExecutedGuard.js";
5
+ import { TelemetryProperties, getBaseProperties } from "./properties.js";
6
+
7
+ ;// CONCATENATED MODULE: external "@workleap/telemetry"
8
+
9
+ ;// CONCATENATED MODULE: external "./env.js"
10
+
11
+ ;// CONCATENATED MODULE: external "./getMixpanelTrackingFunction.js"
12
+
13
+ ;// CONCATENATED MODULE: external "./HasExecutedGuard.js"
14
+
15
+ ;// CONCATENATED MODULE: external "./properties.js"
16
+
17
+ ;// CONCATENATED MODULE: ./src/js/initializeMixpanel.ts
18
+
19
+
20
+
21
+
22
+
23
+ function registerLogRocketSessionUrlListener(superProperties, verbose = false) {
24
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
25
+ // @ts-ignore
26
+ if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
27
+ // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.
28
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
29
+ // @ts-ignore
30
+ globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl)=>{
31
+ if (verbose) {
32
+ console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
33
+ }
34
+ superProperties.set(TelemetryProperties.LogRocketSessionUrl, sessionUrl);
35
+ });
36
+ } else if (verbose) {
37
+ console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
38
+ }
39
+ }
40
+ const initializationGuard = new HasExecutedGuard();
41
+ // This function should only be used by tests.
42
+ function __resetInitializationGuard() {
43
+ initializationGuard.reset();
44
+ }
45
+ /**
46
+ * Creates a function that sends tracking events to the tracking API.
47
+ * @param productId Your product identifier.
48
+ * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
49
+ * @param options Options for creating the tracking function.
50
+ * @returns A function that sends tracking events to the tracking API.
51
+ * @see https://workleap.github.io/wl-telemetry
52
+ */ function initializeMixpanel(productId, envOrTrackingApiBaseUrl, options = {}) {
53
+ const { verbose } = options;
54
+ initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
55
+ // Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.
56
+ const superProperties = new Map();
57
+ const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
58
+ const telemetryContext = getTelemetryContext({
59
+ verbose
60
+ });
61
+ superProperties.set(TelemetryProperties.TelemetryId, telemetryContext.telemetryId);
62
+ superProperties.set(TelemetryProperties.DeviceId, telemetryContext.deviceId);
63
+ const bootstrappingStore = getBootstrappingStore();
64
+ // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store
65
+ // and register the listener once a notification is received that LogRocket is registered.
66
+ if (bootstrappingStore.state.isLogRocketReady) {
67
+ registerLogRocketSessionUrlListener(superProperties, verbose);
68
+ } else {
69
+ bootstrappingStore.subscribe((action, store, unsubscribe)=>{
70
+ if (store.state.isLogRocketReady) {
71
+ unsubscribe();
72
+ registerLogRocketSessionUrlListener(superProperties, verbose);
73
+ }
74
+ });
75
+ }
76
+ const trackFunction = async (eventName, properties, _options = {})=>{
77
+ try {
78
+ const { targetProductId = null, keepAlive = false } = _options;
79
+ const baseProperties = getBaseProperties();
80
+ const allProperties = {
81
+ ...baseProperties,
82
+ ...Object.fromEntries(superProperties),
83
+ ...properties
84
+ };
85
+ await fetch(fullUrl, {
86
+ method: "POST",
87
+ credentials: "include",
88
+ keepalive: keepAlive,
89
+ headers: {
90
+ "Content-Type": "application/json"
91
+ },
92
+ body: JSON.stringify({
93
+ eventName,
94
+ productIdentifier: productId,
95
+ targetProductIdentifier: targetProductId,
96
+ properties: allProperties
97
+ })
98
+ });
99
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
100
+ } catch (error) {
101
+ // Do nothing...
102
+ }
103
+ };
104
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts-ignore
106
+ globalThis[TrackingFunctionName] = trackFunction;
107
+ return trackFunction;
108
+ }
109
+
110
+ export { __resetInitializationGuard, initializeMixpanel };
111
+
112
+ //# sourceMappingURL=initializeMixpanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { getBootstrappingStore, getTelemetryContext } from \"@workleap/telemetry\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { TrackingFunctionName } from \"./getMixpanelTrackingFunction.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getBaseProperties, TelemetryProperties, type MixpanelTrackEventProperties } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface MixpanelTrackingOptions {\n /**\n * The product identifier of the target product.\n */\n targetProductId?: string;\n /**\n * Whether to keep the connection alive for the tracking request.\n * It is mostly used for tracking links where the user might navigate away before the request is completed.\n *\n * Caution! The body size for keepalive requests is limited to 64 kibibytes.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive\n *\n * @default false\n */\n keepAlive?: boolean;\n}\n\n/**\n * A function that sends tracking events to the tracking API.\n * @param eventName The name of the event to track.\n * @param properties The properties to send with the event.\n * @param options Options for tracking the event.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport type MixpanelTrackingFunction = (eventName: string, properties: MixpanelTrackEventProperties, options?: MixpanelTrackingOptions) => Promise<void>;\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface InitializeMixpanelOptions {\n verbose?: boolean;\n}\n\nfunction registerLogRocketSessionUrlListener(superProperties: Map<string, string>, verbose = false) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {\n // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {\n if (verbose) {\n console.log(\"[mixpanel] Received LogRocket session replay URL:\", sessionUrl);\n }\n\n superProperties.set(TelemetryProperties.LogRocketSessionUrl, sessionUrl);\n });\n } else if (verbose) {\n console.log(\"[mixpanel] Cannot integrate with LogRocket because \\\"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\\\" is not available.\");\n }\n}\n\nconst initializationGuard = new HasExecutedGuard();\n\n// This function should only be used by tests.\nexport function __resetInitializationGuard() {\n initializationGuard.reset();\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier.\n * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.\n * @param options Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) : MixpanelTrackingFunction {\n const {\n verbose\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n // Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.\n const superProperties = new Map<string, string>();\n\n const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n const telemetryContext = getTelemetryContext({ verbose });\n\n superProperties.set(TelemetryProperties.TelemetryId, telemetryContext.telemetryId);\n superProperties.set(TelemetryProperties.DeviceId, telemetryContext.deviceId);\n\n const bootstrappingStore = getBootstrappingStore();\n\n // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store\n // and register the listener once a notification is received that LogRocket is registered.\n if (bootstrappingStore.state.isLogRocketReady) {\n registerLogRocketSessionUrlListener(superProperties, verbose);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(superProperties, verbose);\n }\n });\n }\n\n const trackFunction: MixpanelTrackingFunction = async (eventName, properties, _options = {}) => {\n try {\n const {\n targetProductId = null,\n keepAlive = false\n } = _options;\n\n const baseProperties = getBaseProperties();\n\n const allProperties = {\n ...baseProperties,\n ...Object.fromEntries(superProperties),\n ...properties\n };\n\n await fetch(fullUrl, {\n method: \"POST\",\n credentials: \"include\",\n keepalive: keepAlive,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n eventName,\n productIdentifier: productId,\n targetProductIdentifier : targetProductId,\n properties: allProperties\n })\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: unknown) {\n // Do nothing...\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[TrackingFunctionName] = trackFunction;\n\n return trackFunction;\n}\n"],"names":["getBootstrappingStore","getTelemetryContext","getTrackingEndpoint","TrackingFunctionName","HasExecutedGuard","getBaseProperties","TelemetryProperties","registerLogRocketSessionUrlListener","superProperties","verbose","globalThis","sessionUrl","console","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","Map","fullUrl","telemetryContext","bootstrappingStore","action","store","unsubscribe","trackFunction","eventName","properties","_options","targetProductId","keepAlive","baseProperties","allProperties","Object","fetch","JSON","error"],"mappings":";;;;;;;;;;;;;;;;;AAAi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YAAYC,WAAW,CAAC,CAAC;QACvF,IAAI;YACA,MAAM,EACFC,kBAAkB,IAAI,EACtBC,YAAY,KAAK,EACpB,GAAGF;YAEJ,MAAMG,iBAAiB3B,iBAAiBA;YAExC,MAAM4B,gBAAgB;gBAClB,GAAGD,cAAc;gBACjB,GAAGE,OAAO,WAAW,CAAC1B,gBAAgB;gBACtC,GAAGoB,UAAU;YACjB;YAEA,MAAMO,MAAMf,SAAS;gBACjB,QAAQ;gBACR,aAAa;gBACb,WAAWW;gBACX,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9C,MAAMK,KAAK,SAAS,CAAC;oBACjBT;oBACA,mBAAmBX;oBACnB,yBAA0Bc;oBAC1B,YAAYG;gBAChB;YACJ;QACJ,6DAA6D;QAC7D,EAAE,OAAOI,OAAgB;QACrB,gBAAgB;QACpB;IACJ;IAEA,6DAA6D;IAC7D,aAAa;IACb3B,UAAU,CAACP,oBAAoBA,CAAC,GAAGuB;IAEnC,OAAOA;AACX"}
@@ -0,0 +1,30 @@
1
+ export type MixpanelTrackEventProperties = Record<string, unknown>;
2
+ export declare const BaseProperties: {
3
+ readonly Browser: "$browser";
4
+ readonly BrowserVersion: "$browser_version";
5
+ readonly CurrentUrl: "$current_url";
6
+ readonly Device: "$device";
7
+ readonly IsMobile: "Is Mobile";
8
+ readonly Os: "$os";
9
+ readonly Referrer: "$referrer";
10
+ readonly ReferringDomain: "$referring_domain";
11
+ readonly ScreenHeight: "$screen_height";
12
+ readonly ScreenWidth: "$screen_width";
13
+ };
14
+ export declare const TelemetryProperties: {
15
+ readonly DeviceId: "Device Id";
16
+ readonly LogRocketSessionUrl: "LogRocket Session Url";
17
+ readonly TelemetryId: "Telemetry Id";
18
+ };
19
+ export declare function getBaseProperties(): {
20
+ $os: string;
21
+ $browser: string;
22
+ $referrer: string;
23
+ $referring_domain: string;
24
+ $device: string;
25
+ $current_url: string;
26
+ $browser_version: number | null;
27
+ $screen_height: number;
28
+ $screen_width: number;
29
+ "Is Mobile": boolean;
30
+ };
@@ -0,0 +1,43 @@
1
+ import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.js";
2
+
3
+ ;// CONCATENATED MODULE: external "./utils.js"
4
+
5
+ ;// CONCATENATED MODULE: ./src/js/properties.ts
6
+
7
+ const BaseProperties = {
8
+ Browser: "$browser",
9
+ BrowserVersion: "$browser_version",
10
+ CurrentUrl: "$current_url",
11
+ Device: "$device",
12
+ IsMobile: "Is Mobile",
13
+ Os: "$os",
14
+ Referrer: "$referrer",
15
+ ReferringDomain: "$referring_domain",
16
+ ScreenHeight: "$screen_height",
17
+ ScreenWidth: "$screen_width"
18
+ };
19
+ const TelemetryProperties = {
20
+ DeviceId: "Device Id",
21
+ LogRocketSessionUrl: "LogRocket Session Url",
22
+ TelemetryId: "Telemetry Id"
23
+ };
24
+ function getBaseProperties() {
25
+ const userAgent = navigator.userAgent;
26
+ const device = deviceType(userAgent);
27
+ return {
28
+ [BaseProperties.Os]: osName(userAgent),
29
+ [BaseProperties.Browser]: browserName(userAgent, navigator.vendor),
30
+ [BaseProperties.Referrer]: document.referrer,
31
+ [BaseProperties.ReferringDomain]: referringDomain(document.referrer),
32
+ [BaseProperties.Device]: device,
33
+ [BaseProperties.CurrentUrl]: window.location.href,
34
+ [BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
35
+ [BaseProperties.ScreenHeight]: window.screen.height,
36
+ [BaseProperties.ScreenWidth]: window.screen.width,
37
+ [BaseProperties.IsMobile]: device.length > 0
38
+ };
39
+ }
40
+
41
+ export { BaseProperties, TelemetryProperties, getBaseProperties };
42
+
43
+ //# sourceMappingURL=properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/properties.js","sources":["webpack://@workleap/mixpanel/./src/js/properties.ts"],"sourcesContent":["\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport type MixpanelTrackEventProperties = Record<string, unknown>;\n\nexport const BaseProperties = {\n Browser: \"$browser\",\n BrowserVersion: \"$browser_version\",\n CurrentUrl: \"$current_url\",\n Device: \"$device\",\n IsMobile: \"Is Mobile\",\n Os: \"$os\",\n Referrer: \"$referrer\",\n ReferringDomain: \"$referring_domain\",\n ScreenHeight: \"$screen_height\",\n ScreenWidth: \"$screen_width\"\n} as const;\n\nexport const TelemetryProperties = {\n DeviceId: \"Device Id\",\n LogRocketSessionUrl: \"LogRocket Session Url\",\n TelemetryId: \"Telemetry Id\"\n} as const;\n\nexport function getBaseProperties() {\n const userAgent = navigator.userAgent;\n const device = deviceType(userAgent);\n\n return {\n [BaseProperties.Os]: osName(userAgent),\n [BaseProperties.Browser]: browserName(userAgent, navigator.vendor),\n [BaseProperties.Referrer]: document.referrer,\n [BaseProperties.ReferringDomain]: referringDomain(document.referrer),\n [BaseProperties.Device]: device,\n [BaseProperties.CurrentUrl]: window.location.href,\n [BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),\n [BaseProperties.ScreenHeight]: window.screen.height,\n [BaseProperties.ScreenWidth]: window.screen.width,\n [BaseProperties.IsMobile]: device.length > 0\n } satisfies MixpanelTrackEventProperties;\n}\n"],"names":["browserName","browserVersion","deviceType","osName","referringDomain","BaseProperties","TelemetryProperties","getBaseProperties","userAgent","navigator","device","document","window"],"mappings":";;;;;AAC8F;AAIvF,MAAMK,iBAAiB;IAC1B,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,UAAU;IACV,iBAAiB;IACjB,cAAc;IACd,aAAa;AACjB,EAAW;AAEJ,MAAMC,sBAAsB;IAC/B,UAAU;IACV,qBAAqB;IACrB,aAAa;AACjB,EAAW;AAEJ,SAASC;IACZ,MAAMC,YAAYC,UAAU,SAAS;IACrC,MAAMC,SAASR,UAAUA,CAACM;IAE1B,OAAO;QACH,CAACH,eAAe,EAAE,CAAC,EAAEF,MAAMA,CAACK;QAC5B,CAACH,eAAe,OAAO,CAAC,EAAEL,WAAWA,CAACQ,WAAWC,UAAU,MAAM;QACjE,CAACJ,eAAe,QAAQ,CAAC,EAAEM,SAAS,QAAQ;QAC5C,CAACN,eAAe,eAAe,CAAC,EAAED,eAAeA,CAACO,SAAS,QAAQ;QACnE,CAACN,eAAe,MAAM,CAAC,EAAEK;QACzB,CAACL,eAAe,UAAU,CAAC,EAAEO,OAAO,QAAQ,CAAC,IAAI;QACjD,CAACP,eAAe,cAAc,CAAC,EAAEJ,cAAcA,CAACO,WAAWC,UAAU,MAAM;QAC3E,CAACJ,eAAe,YAAY,CAAC,EAAEO,OAAO,MAAM,CAAC,MAAM;QACnD,CAACP,eAAe,WAAW,CAAC,EAAEO,OAAO,MAAM,CAAC,KAAK;QACjD,CAACP,eAAe,QAAQ,CAAC,EAAEK,OAAO,MAAM,GAAG;IAC/C;AACJ"}
@@ -1,5 +1,5 @@
1
1
 
2
- ;// CONCATENATED MODULE: ./src/utils.ts?__rslib_entry__
2
+ ;// CONCATENATED MODULE: ./src/js/utils.ts
3
3
  // This code is adapted from https://github.com/mixpanel/mixpanel-js/blob/master/src/utils.js
4
4
  function browserName(userAgent, vendor, opera) {
5
5
  // vendor is undefined for at least IE9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/utils.js","sources":["webpack://@workleap/mixpanel/./src/js/utils.ts"],"sourcesContent":["// This code is adapted from https://github.com/mixpanel/mixpanel-js/blob/master/src/utils.js\nexport function browserName(userAgent: string, vendor?: string, opera?: object) {\n // vendor is undefined for at least IE9\n vendor = vendor || \"\"; // eslint-disable-line no-param-reassign\n\n if (opera || userAgent.includes(\" OPR/\")) {\n if (userAgent.includes(\"Mini\")) {\n return \"Opera Mini\";\n }\n\n return \"Opera\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) {\n return \"BlackBerry\";\n } else if (userAgent.includes(\"IEMobile\") || userAgent.includes(\"WPDesktop\")) {\n return \"Internet Explorer Mobile\";\n } else if (userAgent.includes(\"Edge\")) {\n return \"Microsoft Edge\";\n } else if (userAgent.includes(\"FBIOS\")) {\n return \"Facebook Mobile\";\n } else if (userAgent.includes(\"Chrome\")) {\n return \"Chrome\";\n } else if (userAgent.includes(\"CriOS\")) {\n return \"Chrome iOS\";\n } else if (userAgent.includes(\"UCWEB\") || userAgent.includes(\"UCBrowser\")) {\n return \"UC Browser\";\n } else if (userAgent.includes(\"FxiOS\")) {\n return \"Firefox iOS\";\n } else if (vendor.includes(\"Apple\")) {\n if (userAgent.includes(\"Mobile\")) {\n return \"Mobile Safari\";\n }\n\n return \"Safari\";\n } else if (userAgent.includes(\"Android\")) {\n return \"Android Mobile\";\n } else if (userAgent.includes(\"Konqueror\")) {\n return \"Konqueror\";\n } else if (userAgent.includes(\"Firefox\")) {\n return \"Firefox\";\n } else if (userAgent.includes(\"MSIE\") || userAgent.includes(\"Trident/\")) {\n return \"Internet Explorer\";\n } else if (userAgent.includes(\"Gecko\")) {\n return \"Mozilla\";\n }\n\n return \"\";\n}\n\n/**\n * This function detects which browser version is running this script,\n * parsing major and minor version (e.g., 42.1). User agent strings from:\n * http://www.useragentstring.com/pages/useragentstring.php\n */\nexport function browserVersion(userAgent: string, vendor?: string, opera?: object) {\n const browser = browserName(userAgent, vendor, opera);\n const versionRegexs: { [key: string]: RegExp } = {\n \"Internet Explorer Mobile\": /rv:(\\d+(\\.\\d+)?)/,\n \"Microsoft Edge\": /Edge\\/(\\d+(\\.\\d+)?)/,\n \"Chrome\": /Chrome\\/(\\d+(\\.\\d+)?)/,\n \"Chrome iOS\": /CriOS\\/(\\d+(\\.\\d+)?)/,\n \"UC Browser\": /(UCBrowser|UCWEB)\\/(\\d+(\\.\\d+)?)/,\n \"Safari\": /Version\\/(\\d+(\\.\\d+)?)/,\n \"Mobile Safari\": /Version\\/(\\d+(\\.\\d+)?)/,\n \"Opera\": /(Opera|OPR)\\/(\\d+(\\.\\d+)?)/,\n \"Firefox\": /Firefox\\/(\\d+(\\.\\d+)?)/,\n \"Firefox iOS\": /FxiOS\\/(\\d+(\\.\\d+)?)/,\n \"Konqueror\": /Konqueror:(\\d+(\\.\\d+)?)/,\n \"BlackBerry\": /BlackBerry (\\d+(\\.\\d+)?)/,\n \"Android Mobile\": /android\\s(\\d+(\\.\\d+)?)/,\n \"Internet Explorer\": /(rv:|MSIE )(\\d+(\\.\\d+)?)/,\n \"Mozilla\": /rv:(\\d+(\\.\\d+)?)/\n };\n const regex = versionRegexs[browser];\n if (regex === undefined) {\n return null;\n }\n const matches = userAgent.match(regex);\n if (!matches) {\n return null;\n }\n\n return parseFloat(matches[matches.length - 2]);\n}\n\nexport function osName(userAgent: string) {\n const a = userAgent;\n if (/Windows/i.test(a)) {\n if (/Phone/.test(a) || /WPDesktop/.test(a)) {\n return \"Windows Phone\";\n }\n\n return \"Windows\";\n } else if (/(iPhone|iPad|iPod)/.test(a)) {\n return \"iOS\";\n } else if (/Android/.test(a)) {\n return \"Android\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {\n return \"BlackBerry\";\n } else if (/Mac/i.test(a)) {\n return \"Mac OS X\";\n } else if (/Linux/.test(a)) {\n return \"Linux\";\n } else if (/CrOS/.test(a)) {\n return \"Chrome OS\";\n }\n\n return \"\";\n}\n\nexport function deviceType(userAgent: string) {\n if (/Windows Phone/i.test(userAgent) || /WPDesktop/.test(userAgent)) {\n return \"Windows Phone\";\n } else if (/iPad/.test(userAgent)) {\n return \"iPad\";\n } else if (/iPod/.test(userAgent)) {\n return \"iPod Touch\";\n } else if (/iPhone/.test(userAgent)) {\n return \"iPhone\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) {\n return \"BlackBerry\";\n } else if (/Android/.test(userAgent)) {\n return \"Android\";\n }\n\n return \"\";\n}\n\nexport function referringDomain(referrer: string) {\n const split = referrer.split(\"/\");\n if (split.length >= 3) {\n return split[2];\n }\n\n return \"\";\n}\n"],"names":["browserName","userAgent","vendor","opera","browserVersion","browser","versionRegexs","regex","undefined","matches","parseFloat","osName","a","deviceType","referringDomain","referrer","split"],"mappings":";;AAAA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ACA,YAAY;QACjC,OAAO;IACX,OAAO,IAAI,8BAA8B,IAAI,CAACA,YAAY;QACtD,OAAO;IACX,OAAO,IAAI,UAAU,IAAI,CAACA,YAAY;QAClC,OAAO;IACX;IAEA,OAAO;AACX;AAEO,SAASa,gBAAgBC,QAAgB;IAC5C,MAAMC,QAAQD,SAAS,KAAK,CAAC;IAC7B,IAAIC,MAAM,MAAM,IAAI,GAAG;QACnB,OAAOA,KAAK,CAAC,EAAE;IACnB;IAEA,OAAO;AACX"}
@@ -0,0 +1 @@
1
+ export { useMixpanelTracking } from "./useMixpanelTracking.ts";
@@ -0,0 +1,10 @@
1
+ import { useMixpanelTracking } from "./useMixpanelTracking.js";
2
+
3
+ ;// CONCATENATED MODULE: external "./useMixpanelTracking.js"
4
+
5
+ ;// CONCATENATED MODULE: ./src/react/index.ts
6
+
7
+
8
+ export { useMixpanelTracking };
9
+
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react/index.js","sources":["webpack://@workleap/mixpanel/./src/react/index.ts"],"sourcesContent":["export { useMixpanelTracking } from \"./useMixpanelTracking.ts\";\n\n"],"names":["useMixpanelTracking"],"mappings":";;;;;AAA+D"}
@@ -0,0 +1,11 @@
1
+ import { type GetMixpanelTrackingFunctionOptions } from "../js/getMixpanelTrackingFunction.ts";
2
+ /**
3
+ * @see https://workleap.github.io/wl-telemetry
4
+ */
5
+ export type UseMixpanelTrackingOptions = GetMixpanelTrackingFunctionOptions;
6
+ /**
7
+ * Retrieve the track function.
8
+ * @returns A function that sends tracking events to the tracking API.
9
+ * @see https://workleap.github.io/wl-telemetry
10
+ */
11
+ export declare function useMixpanelTracking(options?: UseMixpanelTrackingOptions): import("../js/initializeMixpanel.ts").MixpanelTrackingFunction;
@@ -0,0 +1,17 @@
1
+ import { getMixpanelTrackingFunction } from "../js/getMixpanelTrackingFunction.js";
2
+
3
+ ;// CONCATENATED MODULE: external "../js/getMixpanelTrackingFunction.js"
4
+
5
+ ;// CONCATENATED MODULE: ./src/react/useMixpanelTracking.ts
6
+
7
+ /**
8
+ * Retrieve the track function.
9
+ * @returns A function that sends tracking events to the tracking API.
10
+ * @see https://workleap.github.io/wl-telemetry
11
+ */ function useMixpanelTracking(options) {
12
+ return getMixpanelTrackingFunction(options);
13
+ }
14
+
15
+ export { useMixpanelTracking };
16
+
17
+ //# sourceMappingURL=useMixpanelTracking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react/useMixpanelTracking.js","sources":["webpack://@workleap/mixpanel/./src/react/useMixpanelTracking.ts"],"sourcesContent":["import { getMixpanelTrackingFunction, type GetMixpanelTrackingFunctionOptions } from \"../js/getMixpanelTrackingFunction.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport type UseMixpanelTrackingOptions = GetMixpanelTrackingFunctionOptions;\n\n/**\n * Retrieve the track function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function useMixpanelTracking(options?: UseMixpanelTrackingOptions) {\n return getMixpanelTrackingFunction(options);\n}\n"],"names":["getMixpanelTrackingFunction","useMixpanelTracking","options"],"mappings":";;;;;AAA4H;AAO5H;;;;CAIC,GACM,SAASC,oBAAoBC,OAAoC;IACpE,OAAOF,2BAA2BA,CAACE;AACvC"}
package/package.json CHANGED
@@ -1,25 +1,29 @@
1
1
  {
2
2
  "name": "@workleap/mixpanel",
3
3
  "author": "Workleap",
4
- "version": "1.1.1",
4
+ "version": "2.0.0",
5
5
  "description": "A package containing utilities for Mixpanel telemetry.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/workleap/wl-tracking.git",
9
+ "url": "git+https://github.com/workleap/wl-telemetry.git",
10
10
  "directory": "packages/mixpanel"
11
11
  },
12
+ "type": "module",
12
13
  "publishConfig": {
13
14
  "access": "public",
14
15
  "provenance": true
15
16
  },
16
- "type": "module",
17
- "main": "./dist/index.js",
18
17
  "exports": {
19
18
  ".": {
20
- "import": "./dist/index.js",
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
19
+ "types": "./dist/js/index.d.ts",
20
+ "import": "./dist/js/index.js",
21
+ "default": "./dist/js/index.js"
22
+ },
23
+ "./react": {
24
+ "types": "./dist/react/index.d.ts",
25
+ "import": "./dist/react/index.js",
26
+ "default": "./dist/react/index.js"
23
27
  }
24
28
  },
25
29
  "files": [
@@ -28,19 +32,30 @@
28
32
  "CHANGELOG.md",
29
33
  "README.md"
30
34
  ],
35
+ "peerDependencies": {
36
+ "react": "^18.0.0 || ^19.0.0",
37
+ "react-dom": "^18.0.0 || ^19.0.0",
38
+ "@workleap/telemetry": "1.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "react": {
42
+ "optional": true
43
+ },
44
+ "react-dom": {
45
+ "optional": true
46
+ }
47
+ },
31
48
  "devDependencies": {
32
- "@rsbuild/core": "1.2.19",
33
- "@rslib/core": "0.5.5",
34
- "@workleap/eslint-plugin": "3.3.1",
35
- "@workleap/rslib-configs": "1.0.3",
36
- "@workleap/typescript-configs": "3.0.2",
49
+ "@rsbuild/core": "1.4.6",
50
+ "@rslib/core": "0.10.5",
51
+ "@types/react": "19.1.8",
52
+ "@workleap/eslint-plugin": "3.4.2",
53
+ "@workleap/rslib-configs": "1.0.6",
54
+ "@workleap/typescript-configs": "3.0.4",
37
55
  "eslint": "8.57.1",
38
- "happy-dom": "17.4.4",
39
- "typescript": "5.8.2",
40
- "vitest": "3.0.9"
41
- },
42
- "engines": {
43
- "node": ">=18.0.0"
56
+ "happy-dom": "18.0.1",
57
+ "typescript": "5.8.3",
58
+ "vitest": "3.2.4"
44
59
  },
45
60
  "sideEffects": false,
46
61
  "scripts": {