@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
@@ -0,0 +1,19 @@
1
+ export class HasExecutedGuard {
2
+ #hasExecuted: boolean = false;
3
+
4
+ throw(message: string) {
5
+ if (this.#hasExecuted) {
6
+ throw new Error(message);
7
+ }
8
+
9
+ this.#hasExecuted = true;
10
+ }
11
+
12
+ get hasExecuted() {
13
+ return this.#hasExecuted;
14
+ }
15
+
16
+ reset() {
17
+ this.#hasExecuted = false;
18
+ }
19
+ }
@@ -1,5 +1,6 @@
1
1
 
2
2
  const EnvironmentList = ["development", "staging", "production", "local", "msw"] as const;
3
+
3
4
  export type Environment = typeof EnvironmentList[number];
4
5
 
5
6
  const NavigationApiBaseUrl: Record<Environment, string> = {
@@ -17,6 +18,7 @@ function resolveApiUrl(path: string, baseUrl: string | undefined) : string {
17
18
 
18
19
  export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {
19
20
  let baseUrl: string;
21
+
20
22
  if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {
21
23
  baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];
22
24
  } else {
@@ -0,0 +1,31 @@
1
+ import type { MixpanelTrackingFunction } from "./initializeMixpanel.ts";
2
+
3
+ export const TrackingFunctionName = "__WLP_MIXPANEL_TRACKING_FUNCTION__";
4
+
5
+ /**
6
+ * @see https://workleap.github.io/wl-telemetry
7
+ */
8
+ export interface GetMixpanelTrackingFunctionOptions {
9
+ throwOnUndefined?: boolean;
10
+ }
11
+
12
+ /**
13
+ * Retrieve the track function.
14
+ * @returns A function that sends tracking events to the tracking API.
15
+ * @see https://workleap.github.io/wl-telemetry
16
+ */
17
+ export function getMixpanelTrackingFunction(options: GetMixpanelTrackingFunctionOptions = {}) {
18
+ const {
19
+ throwOnUndefined = true
20
+ } = options;
21
+
22
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
23
+ // @ts-ignore
24
+ const trackFunction = globalThis[TrackingFunctionName];
25
+
26
+ if (!trackFunction && throwOnUndefined) {
27
+ throw new Error("[mixpanel] The tracking function is undefined. Did you call the \"initializeMixpanel\" function?");
28
+ }
29
+
30
+ return trackFunction as MixpanelTrackingFunction;
31
+ }
@@ -0,0 +1,5 @@
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";
5
+
@@ -0,0 +1,147 @@
1
+ import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
2
+ import { getTrackingEndpoint, type Environment } from "./env.ts";
3
+ import { TrackingFunctionName } from "./getMixpanelTrackingFunction.ts";
4
+ import { HasExecutedGuard } from "./HasExecutedGuard.ts";
5
+ import { getBaseProperties, TelemetryProperties, type MixpanelTrackEventProperties } from "./properties.ts";
6
+
7
+ /**
8
+ * @see https://workleap.github.io/wl-telemetry
9
+ */
10
+ export interface MixpanelTrackingOptions {
11
+ /**
12
+ * The product identifier of the target product.
13
+ */
14
+ targetProductId?: string;
15
+ /**
16
+ * Whether to keep the connection alive for the tracking request.
17
+ * It is mostly used for tracking links where the user might navigate away before the request is completed.
18
+ *
19
+ * Caution! The body size for keepalive requests is limited to 64 kibibytes.
20
+ *
21
+ * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
22
+ *
23
+ * @default false
24
+ */
25
+ keepAlive?: boolean;
26
+ }
27
+
28
+ /**
29
+ * A function that sends tracking events to the tracking API.
30
+ * @param eventName The name of the event to track.
31
+ * @param properties The properties to send with the event.
32
+ * @param options Options for tracking the event.
33
+ * @see https://workleap.github.io/wl-telemetry
34
+ */
35
+ export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelTrackEventProperties, options?: MixpanelTrackingOptions) => Promise<void>;
36
+
37
+ /**
38
+ * @see https://workleap.github.io/wl-telemetry
39
+ */
40
+ export interface InitializeMixpanelOptions {
41
+ verbose?: boolean;
42
+ }
43
+
44
+ function registerLogRocketSessionUrlListener(superProperties: Map<string, string>, verbose = false) {
45
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
46
+ // @ts-ignore
47
+ if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
48
+ // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.
49
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
50
+ // @ts-ignore
51
+ globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {
52
+ if (verbose) {
53
+ console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
54
+ }
55
+
56
+ superProperties.set(TelemetryProperties.LogRocketSessionUrl, sessionUrl);
57
+ });
58
+ } else if (verbose) {
59
+ console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
60
+ }
61
+ }
62
+
63
+ const initializationGuard = new HasExecutedGuard();
64
+
65
+ // This function should only be used by tests.
66
+ export function __resetInitializationGuard() {
67
+ initializationGuard.reset();
68
+ }
69
+
70
+ /**
71
+ * Creates a function that sends tracking events to the tracking API.
72
+ * @param productId Your product identifier.
73
+ * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
74
+ * @param options Options for creating the tracking function.
75
+ * @returns A function that sends tracking events to the tracking API.
76
+ * @see https://workleap.github.io/wl-telemetry
77
+ */
78
+ export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) : MixpanelTrackingFunction {
79
+ const {
80
+ verbose
81
+ } = options;
82
+
83
+ initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
84
+
85
+ // Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.
86
+ const superProperties = new Map<string, string>();
87
+
88
+ const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
89
+ const telemetryContext = getTelemetryContext({ verbose });
90
+
91
+ superProperties.set(TelemetryProperties.TelemetryId, telemetryContext.telemetryId);
92
+ superProperties.set(TelemetryProperties.DeviceId, telemetryContext.deviceId);
93
+
94
+ const bootstrappingStore = getBootstrappingStore();
95
+
96
+ // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store
97
+ // and register the listener once a notification is received that LogRocket is registered.
98
+ if (bootstrappingStore.state.isLogRocketReady) {
99
+ registerLogRocketSessionUrlListener(superProperties, verbose);
100
+ } else {
101
+ bootstrappingStore.subscribe((action, store, unsubscribe) => {
102
+ if (store.state.isLogRocketReady) {
103
+ unsubscribe();
104
+ registerLogRocketSessionUrlListener(superProperties, verbose);
105
+ }
106
+ });
107
+ }
108
+
109
+ const trackFunction: MixpanelTrackingFunction = async (eventName, properties, _options = {}) => {
110
+ try {
111
+ const {
112
+ targetProductId = null,
113
+ keepAlive = false
114
+ } = _options;
115
+
116
+ const baseProperties = getBaseProperties();
117
+
118
+ const allProperties = {
119
+ ...baseProperties,
120
+ ...Object.fromEntries(superProperties),
121
+ ...properties
122
+ };
123
+
124
+ await fetch(fullUrl, {
125
+ method: "POST",
126
+ credentials: "include",
127
+ keepalive: keepAlive,
128
+ headers: { "Content-Type": "application/json" },
129
+ body: JSON.stringify({
130
+ eventName,
131
+ productIdentifier: productId,
132
+ targetProductIdentifier : targetProductId,
133
+ properties: allProperties
134
+ })
135
+ });
136
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
137
+ } catch (error: unknown) {
138
+ // Do nothing...
139
+ }
140
+ };
141
+
142
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
+ // @ts-ignore
144
+ globalThis[TrackingFunctionName] = trackFunction;
145
+
146
+ return trackFunction;
147
+ }
@@ -0,0 +1,41 @@
1
+
2
+ import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
3
+
4
+ export type MixpanelTrackEventProperties = Record<string, unknown>;
5
+
6
+ export const BaseProperties = {
7
+ Browser: "$browser",
8
+ BrowserVersion: "$browser_version",
9
+ CurrentUrl: "$current_url",
10
+ Device: "$device",
11
+ IsMobile: "Is Mobile",
12
+ Os: "$os",
13
+ Referrer: "$referrer",
14
+ ReferringDomain: "$referring_domain",
15
+ ScreenHeight: "$screen_height",
16
+ ScreenWidth: "$screen_width"
17
+ } as const;
18
+
19
+ export const TelemetryProperties = {
20
+ DeviceId: "Device Id",
21
+ LogRocketSessionUrl: "LogRocket Session Url",
22
+ TelemetryId: "Telemetry Id"
23
+ } as const;
24
+
25
+ export function getBaseProperties() {
26
+ const userAgent = navigator.userAgent;
27
+ const device = deviceType(userAgent);
28
+
29
+ return {
30
+ [BaseProperties.Os]: osName(userAgent),
31
+ [BaseProperties.Browser]: browserName(userAgent, navigator.vendor),
32
+ [BaseProperties.Referrer]: document.referrer,
33
+ [BaseProperties.ReferringDomain]: referringDomain(document.referrer),
34
+ [BaseProperties.Device]: device,
35
+ [BaseProperties.CurrentUrl]: window.location.href,
36
+ [BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
37
+ [BaseProperties.ScreenHeight]: window.screen.height,
38
+ [BaseProperties.ScreenWidth]: window.screen.width,
39
+ [BaseProperties.IsMobile]: device.length > 0
40
+ } satisfies MixpanelTrackEventProperties;
41
+ }
@@ -0,0 +1,2 @@
1
+ export { useMixpanelTracking } from "./useMixpanelTracking.ts";
2
+
@@ -0,0 +1,15 @@
1
+ import { getMixpanelTrackingFunction, type GetMixpanelTrackingFunctionOptions } from "../js/getMixpanelTrackingFunction.ts";
2
+
3
+ /**
4
+ * @see https://workleap.github.io/wl-telemetry
5
+ */
6
+ export type UseMixpanelTrackingOptions = GetMixpanelTrackingFunctionOptions;
7
+
8
+ /**
9
+ * Retrieve the track function.
10
+ * @returns A function that sends tracking events to the tracking API.
11
+ * @see https://workleap.github.io/wl-telemetry
12
+ */
13
+ export function useMixpanelTracking(options?: UseMixpanelTrackingOptions) {
14
+ return getMixpanelTrackingFunction(options);
15
+ }
@@ -1,45 +0,0 @@
1
- import { type Environment } from "./env.ts";
2
- import { type TrackEventProperties } from "./properties.ts";
3
- export interface TrackingOptions {
4
- /**
5
- * Whether to keep the connection alive for the tracking request.
6
- * It is mostly used for tracking links where the user might navigate away before the request is completed.
7
- *
8
- * Caution! The body size for keepalive requests is limited to 64 kibibytes.
9
- *
10
- * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
11
- *
12
- * @default false
13
- */
14
- keepAlive?: boolean;
15
- }
16
- /**
17
- * A function that sends tracking events to the tracking API.
18
- * @param eventName The name of the event to track.
19
- * @param properties The properties to send with the event.
20
- * @param options Options for tracking the event.
21
- */
22
- export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
23
- export interface CreateTrackingFunctionOptions {
24
- /**
25
- * The product identifier of the target product.
26
- * @default null
27
- */
28
- targetProductId?: string | null;
29
- }
30
- /**
31
- * Creates a function that sends tracking events to the tracking API.
32
- * @param productId Your product identifier. e.g. "wlp", "ov"
33
- * @param env The environment to get the navigation url from . e.g. "local", "prod"
34
- * @param createOptions Options for creating the tracking function.
35
- * @returns A function that sends tracking events to the tracking API.
36
- */
37
- export declare function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
38
- /**
39
- * Creates a function that sends tracking events to the tracking API.
40
- * @param productId Your product identifier. e.g. "wlp", "ov"
41
- * @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
42
- * @param createOptions Options for creating the tracking function.
43
- * @returns A function that sends tracking events to the tracking API.
44
- */
45
- export declare function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
@@ -1,39 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__ from "./env.js";
2
- import * as __WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__ from "./properties.js";
3
-
4
- ;// CONCATENATED MODULE: external "./env.js"
5
-
6
- ;// CONCATENATED MODULE: external "./properties.js"
7
-
8
- ;// CONCATENATED MODULE: ./src/createTrackingFunction.ts?__rslib_entry__
9
-
10
-
11
- function createTrackingFunction(productId, envOrTrackingApiBaseUrl, createOptions = {}) {
12
- const targetProductId = createOptions?.targetProductId ?? null;
13
- const fullUrl = (0,__WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__.getTrackingEndpoint)(envOrTrackingApiBaseUrl);
14
- return async (eventName, properties, options)=>{
15
- const baseProperties = (0,__WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__.getBaseProperties)();
16
- const allProperties = {
17
- ...baseProperties,
18
- ...properties
19
- };
20
- await fetch(fullUrl, {
21
- method: "POST",
22
- credentials: "include",
23
- keepalive: options?.keepAlive,
24
- headers: {
25
- "Content-Type": "application/json"
26
- },
27
- body: JSON.stringify({
28
- eventName,
29
- productIdentifier: productId,
30
- targetProductIdentifier: targetProductId,
31
- properties: allProperties
32
- })
33
- });
34
- };
35
- }
36
-
37
- export { createTrackingFunction };
38
-
39
- //# sourceMappingURL=createTrackingFunction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/createTrackingFunction.ts"],"sourcesContent":["import { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { getBaseProperties, type TrackEventProperties } from \"./properties.ts\";\n\nexport interface TrackingOptions {\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 */\nexport type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;\n\nexport interface CreateTrackingFunctionOptions {\n /**\n * The product identifier of the target product.\n * @default null\n */\n targetProductId?: string | null;\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param env The environment to get the navigation url from . e.g. \"local\", \"prod\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. \"https://api.platform.workleap-dev.com/shell/navigation/\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\nexport function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {\n const targetProductId = createOptions?.targetProductId ?? null;\n const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n\n return async (eventName, properties, options) => {\n const baseProperties = getBaseProperties();\n const allProperties = { ...baseProperties, ...properties };\n\n await fetch(fullUrl, {\n method: \"POST\",\n credentials: \"include\",\n keepalive: options?.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 };\n}\n"],"names":["getTrackingEndpoint","getBaseProperties","createTrackingFunction","productId","envOrTrackingApiBaseUrl","createOptions","targetProductId","fullUrl","eventName","properties","options","baseProperties","allProperties","fetch","JSON"],"mappings":";;;;;;;;AAAiE;AACc;AAgDxE,SAASE,uBAAuBC,SAAiB,EAAEC,uBAAoD,EAAEC,gBAA+C,CAAC,CAAC;IAC7J,MAAMC,kBAAkBD,eAAe,mBAAmB;IAC1D,MAAME,UAAUP,oEAAmBA,CAACI;IAEpC,OAAO,OAAOI,WAAWC,YAAYC;QACjC,MAAMC,iBAAiBV,yEAAiBA;QACxC,MAAMW,gBAAgB;YAAE,GAAGD,cAAc;YAAE,GAAGF,UAAU;QAAC;QAEzD,MAAMI,MAAMN,SAAS;YACjB,QAAQ;YACR,aAAa;YACb,WAAWG,SAAS;YACpB,SAAS;gBAAE,gBAAgB;YAAmB;YAC9C,MAAMI,KAAK,SAAS,CAAC;gBACjBN;gBACA,mBAAmBL;gBACnB,yBAA0BG;gBAC1B,YAAYM;YAChB;QACJ;IACJ;AACJ"}
package/dist/env.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sources":["webpack://@workleap/mixpanel/./src/env.ts"],"sourcesContent":["\nconst EnvironmentList = [\"development\", \"staging\", \"production\", \"local\", \"msw\"] as const;\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 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;AAGhF,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;IACJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAc,kBAAkBE;AAC3C"}
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./createTrackingFunction.ts";
2
- export type { Environment } from "./env.ts";
3
- export type { TrackEventProperties } from "./properties.ts";
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- export * from "./createTrackingFunction.js";
2
-
3
- ;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
4
-
5
-
6
-
7
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["webpack://@workleap/mixpanel/./src/index.ts"],"sourcesContent":["export * from \"./createTrackingFunction.ts\";\nexport type { Environment } from \"./env.ts\";\nexport type { TrackEventProperties } from \"./properties.ts\";\n\n"],"names":[],"mappings":";;;AAA4C"}
@@ -1,13 +0,0 @@
1
- export type TrackEventProperties = Record<string, unknown>;
2
- export declare function getBaseProperties(): {
3
- $os: string;
4
- $browser: string;
5
- $referrer: string;
6
- $referring_domain: string;
7
- $device: string;
8
- $current_url: string;
9
- $browser_version: number | null;
10
- $screen_height: number;
11
- $screen_width: number;
12
- IsMobile: boolean;
13
- };
@@ -1,39 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
2
-
3
- ;// CONCATENATED MODULE: external "./utils.js"
4
-
5
- ;// CONCATENATED MODULE: ./src/properties.ts?__rslib_entry__
6
-
7
- const BaseTrackingProperties = {
8
- AppVersion: "AppVersion",
9
- Browser: "$browser",
10
- BrowserVersion: "$browser_version",
11
- CurrentUrl: "$current_url",
12
- Device: "$device",
13
- IsMobile: "IsMobile",
14
- Os: "$os",
15
- Referrer: "$referrer",
16
- ReferringDomain: "$referring_domain",
17
- ScreenHeight: "$screen_height",
18
- ScreenWidth: "$screen_width"
19
- };
20
- function getBaseProperties() {
21
- const userAgent = navigator.userAgent;
22
- const device = (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.deviceType)(userAgent);
23
- return {
24
- [BaseTrackingProperties.Os]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.osName)(userAgent),
25
- [BaseTrackingProperties.Browser]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.browserName)(userAgent, navigator.vendor),
26
- [BaseTrackingProperties.Referrer]: document.referrer,
27
- [BaseTrackingProperties.ReferringDomain]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.referringDomain)(document.referrer),
28
- [BaseTrackingProperties.Device]: device,
29
- [BaseTrackingProperties.CurrentUrl]: window.location.href,
30
- [BaseTrackingProperties.BrowserVersion]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.browserVersion)(userAgent, navigator.vendor),
31
- [BaseTrackingProperties.ScreenHeight]: window.screen.height,
32
- [BaseTrackingProperties.ScreenWidth]: window.screen.width,
33
- [BaseTrackingProperties.IsMobile]: device.length > 0
34
- };
35
- }
36
-
37
- export { getBaseProperties };
38
-
39
- //# sourceMappingURL=properties.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"properties.js","sources":["webpack://@workleap/mixpanel/./src/properties.ts"],"sourcesContent":["\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport type TrackEventProperties = Record<string, unknown>;\n\nconst BaseTrackingProperties = {\n AppVersion: \"AppVersion\",\n Browser: \"$browser\",\n BrowserVersion: \"$browser_version\",\n CurrentUrl: \"$current_url\",\n Device: \"$device\",\n IsMobile: \"IsMobile\",\n Os: \"$os\",\n Referrer: \"$referrer\",\n ReferringDomain: \"$referring_domain\",\n ScreenHeight: \"$screen_height\",\n ScreenWidth: \"$screen_width\"\n} as const;\n\nexport function getBaseProperties() {\n const userAgent = navigator.userAgent;\n const device = deviceType(userAgent);\n\n return {\n [BaseTrackingProperties.Os]: osName(userAgent),\n [BaseTrackingProperties.Browser]: browserName(userAgent, navigator.vendor),\n [BaseTrackingProperties.Referrer]: document.referrer,\n [BaseTrackingProperties.ReferringDomain]: referringDomain(document.referrer),\n [BaseTrackingProperties.Device]: device,\n [BaseTrackingProperties.CurrentUrl]: window.location.href,\n [BaseTrackingProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),\n [BaseTrackingProperties.ScreenHeight]: window.screen.height,\n [BaseTrackingProperties.ScreenWidth]: window.screen.width,\n [BaseTrackingProperties.IsMobile]: device.length > 0\n } satisfies TrackEventProperties;\n}\n"],"names":["browserName","browserVersion","deviceType","osName","referringDomain","BaseTrackingProperties","getBaseProperties","userAgent","navigator","device","document","window"],"mappings":";;;;;AAC8F;AAI9F,MAAMK,yBAAyB;IAC3B,YAAY;IACZ,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,UAAU;IACV,iBAAiB;IACjB,cAAc;IACd,aAAa;AACjB;AAEO,SAASC;IACZ,MAAMC,YAAYC,UAAU,SAAS;IACrC,MAAMC,SAASP,6DAAUA,CAACK;IAE1B,OAAO;QACH,CAACF,uBAAuB,EAAE,CAAC,EAAEF,yDAAMA,CAACI;QACpC,CAACF,uBAAuB,OAAO,CAAC,EAAEL,8DAAWA,CAACO,WAAWC,UAAU,MAAM;QACzE,CAACH,uBAAuB,QAAQ,CAAC,EAAEK,SAAS,QAAQ;QACpD,CAACL,uBAAuB,eAAe,CAAC,EAAED,kEAAeA,CAACM,SAAS,QAAQ;QAC3E,CAACL,uBAAuB,MAAM,CAAC,EAAEI;QACjC,CAACJ,uBAAuB,UAAU,CAAC,EAAEM,OAAO,QAAQ,CAAC,IAAI;QACzD,CAACN,uBAAuB,cAAc,CAAC,EAAEJ,iEAAcA,CAACM,WAAWC,UAAU,MAAM;QACnF,CAACH,uBAAuB,YAAY,CAAC,EAAEM,OAAO,MAAM,CAAC,MAAM;QAC3D,CAACN,uBAAuB,WAAW,CAAC,EAAEM,OAAO,MAAM,CAAC,KAAK;QACzD,CAACN,uBAAuB,QAAQ,CAAC,EAAEI,OAAO,MAAM,GAAG;IACvD;AACJ"}
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["webpack://@workleap/mixpanel/./src/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":"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"}
@@ -1,71 +0,0 @@
1
- import { getTrackingEndpoint, type Environment } from "./env.ts";
2
- import { getBaseProperties, type TrackEventProperties } from "./properties.ts";
3
-
4
- export interface TrackingOptions {
5
- /**
6
- * Whether to keep the connection alive for the tracking request.
7
- * It is mostly used for tracking links where the user might navigate away before the request is completed.
8
- *
9
- * Caution! The body size for keepalive requests is limited to 64 kibibytes.
10
- *
11
- * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
12
- *
13
- * @default false
14
- */
15
- keepAlive?: boolean;
16
- }
17
-
18
- /**
19
- * A function that sends tracking events to the tracking API.
20
- * @param eventName The name of the event to track.
21
- * @param properties The properties to send with the event.
22
- * @param options Options for tracking the event.
23
- */
24
- export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
25
-
26
- export interface CreateTrackingFunctionOptions {
27
- /**
28
- * The product identifier of the target product.
29
- * @default null
30
- */
31
- targetProductId?: string | null;
32
- }
33
-
34
- /**
35
- * Creates a function that sends tracking events to the tracking API.
36
- * @param productId Your product identifier. e.g. "wlp", "ov"
37
- * @param env The environment to get the navigation url from . e.g. "local", "prod"
38
- * @param createOptions Options for creating the tracking function.
39
- * @returns A function that sends tracking events to the tracking API.
40
- */
41
- export function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
42
- /**
43
- * Creates a function that sends tracking events to the tracking API.
44
- * @param productId Your product identifier. e.g. "wlp", "ov"
45
- * @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
46
- * @param createOptions Options for creating the tracking function.
47
- * @returns A function that sends tracking events to the tracking API.
48
- */
49
- export function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
50
- export function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {
51
- const targetProductId = createOptions?.targetProductId ?? null;
52
- const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
53
-
54
- return async (eventName, properties, options) => {
55
- const baseProperties = getBaseProperties();
56
- const allProperties = { ...baseProperties, ...properties };
57
-
58
- await fetch(fullUrl, {
59
- method: "POST",
60
- credentials: "include",
61
- keepalive: options?.keepAlive,
62
- headers: { "Content-Type": "application/json" },
63
- body: JSON.stringify({
64
- eventName,
65
- productIdentifier: productId,
66
- targetProductIdentifier : targetProductId,
67
- properties: allProperties
68
- })
69
- });
70
- };
71
- }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./createTrackingFunction.ts";
2
- export type { Environment } from "./env.ts";
3
- export type { TrackEventProperties } from "./properties.ts";
4
-
package/src/properties.ts DELETED
@@ -1,36 +0,0 @@
1
-
2
- import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
3
-
4
- export type TrackEventProperties = Record<string, unknown>;
5
-
6
- const BaseTrackingProperties = {
7
- AppVersion: "AppVersion",
8
- Browser: "$browser",
9
- BrowserVersion: "$browser_version",
10
- CurrentUrl: "$current_url",
11
- Device: "$device",
12
- IsMobile: "IsMobile",
13
- Os: "$os",
14
- Referrer: "$referrer",
15
- ReferringDomain: "$referring_domain",
16
- ScreenHeight: "$screen_height",
17
- ScreenWidth: "$screen_width"
18
- } as const;
19
-
20
- export function getBaseProperties() {
21
- const userAgent = navigator.userAgent;
22
- const device = deviceType(userAgent);
23
-
24
- return {
25
- [BaseTrackingProperties.Os]: osName(userAgent),
26
- [BaseTrackingProperties.Browser]: browserName(userAgent, navigator.vendor),
27
- [BaseTrackingProperties.Referrer]: document.referrer,
28
- [BaseTrackingProperties.ReferringDomain]: referringDomain(document.referrer),
29
- [BaseTrackingProperties.Device]: device,
30
- [BaseTrackingProperties.CurrentUrl]: window.location.href,
31
- [BaseTrackingProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
32
- [BaseTrackingProperties.ScreenHeight]: window.screen.height,
33
- [BaseTrackingProperties.ScreenWidth]: window.screen.width,
34
- [BaseTrackingProperties.IsMobile]: device.length > 0
35
- } satisfies TrackEventProperties;
36
- }
File without changes
File without changes
File without changes