@workleap/mixpanel 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/js/createTrackingFunction.js.map +1 -1
- package/dist/js/env.d.ts +1 -1
- package/dist/js/env.js +2 -2
- package/dist/js/env.js.map +1 -1
- package/dist/js/initializeMixpanel.d.ts +6 -0
- package/dist/js/initializeMixpanel.js +2 -2
- package/dist/js/initializeMixpanel.js.map +1 -1
- package/package.json +1 -1
- package/src/js/createTrackingFunction.ts +1 -1
- package/src/js/env.ts +2 -2
- package/src/js/initializeMixpanel.ts +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @workleap/mixpanel
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#50](https://github.com/workleap/wl-telemetry/pull/50) [`e53857a`](https://github.com/workleap/wl-telemetry/commit/e53857a6c1ba13894f643076f3675dc2b61a9cc5) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add the trackingEndpoint options to the initializeMixpanel function to allow specifying a custom endpoint for tracking events.
|
|
8
|
+
|
|
3
9
|
## 2.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/createTrackingFunction.ts"],"sourcesContent":["import { getMixpanelContext } from \"./context.ts\";\nimport { getBaseProperties, type MixpanelEventProperties } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface CreateTrackingFunctionOptions {\n /**\n * The product identifier of the target product.\n */\n targetProductId?: string;\n}\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface TrackingFunctionOptions {\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 TrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: TrackingFunctionOptions) => Promise<void>;\n\nexport function createTrackingFunction(options: CreateTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n const {\n productId,\n endpoint,\n superProperties\n } = getMixpanelContext();\n\n const trackFunction: TrackingFunction = async (eventName, properties, _options = {}) => {\n try {\n const {\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(endpoint, {\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 // Not sure why, but it seems important to send \"null\" if not target product identifier\n // are provided.\n targetProductIdentifier : targetProductId ?? null,\n properties: allProperties\n })\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: unknown) {\n
|
|
1
|
+
{"version":3,"file":"js/createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/createTrackingFunction.ts"],"sourcesContent":["import { getMixpanelContext } from \"./context.ts\";\nimport { getBaseProperties, type MixpanelEventProperties } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface CreateTrackingFunctionOptions {\n /**\n * The product identifier of the target product.\n */\n targetProductId?: string;\n}\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface TrackingFunctionOptions {\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 TrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: TrackingFunctionOptions) => Promise<void>;\n\nexport function createTrackingFunction(options: CreateTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n const {\n productId,\n endpoint,\n superProperties\n } = getMixpanelContext();\n\n const trackFunction: TrackingFunction = async (eventName, properties, _options = {}) => {\n try {\n const {\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(endpoint, {\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 // Not sure why, but it seems important to send \"null\" if not target product identifier\n // are provided.\n targetProductIdentifier : targetProductId ?? null,\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 return trackFunction;\n}\n"],"names":["getMixpanelContext","getBaseProperties","createTrackingFunction","options","targetProductId","productId","endpoint","superProperties","trackFunction","eventName","properties","_options","keepAlive","baseProperties","allProperties","Object","fetch","JSON","error"],"mappings":";;;;;;;;AAAkD;AACgC;AAsC3E,SAASE,uBAAuBC,UAAyC,CAAC,CAAC;IAC9E,MAAM,EACFC,eAAe,EAClB,GAAGD;IAEJ,MAAM,EACFE,SAAS,EACTC,QAAQ,EACRC,eAAe,EAClB,GAAGP,kBAAkBA;IAEtB,MAAMQ,gBAAkC,OAAOC,WAAWC,YAAYC,WAAW,CAAC,CAAC;QAC/E,IAAI;YACA,MAAM,EACFC,YAAY,KAAK,EACpB,GAAGD;YAEJ,MAAME,iBAAiBZ,iBAAiBA;YAExC,MAAMa,gBAAgB;gBAClB,GAAGD,cAAc;gBACjB,GAAGE,OAAO,WAAW,CAACR,gBAAgB;gBACtC,GAAGG,UAAU;YACjB;YAEA,MAAMM,MAAMV,UAAU;gBAClB,QAAQ;gBACR,aAAa;gBACb,WAAWM;gBACX,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9C,MAAMK,KAAK,SAAS,CAAC;oBACjBR;oBACA,mBAAmBJ;oBACnB,uFAAuF;oBACvF,gBAAgB;oBAChB,yBAA0BD,mBAAmB;oBAC7C,YAAYU;gBAChB;YACJ;QACJ,6DAA6D;QAC7D,EAAE,OAAOI,OAAgB;QACrB,gBAAgB;QACpB;IACJ;IAEA,OAAOV;AACX"}
|
package/dist/js/env.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const EnvironmentList: readonly ["development", "staging", "production", "local", "msw"];
|
|
2
2
|
export type Environment = typeof EnvironmentList[number];
|
|
3
|
-
export declare function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})): string;
|
|
3
|
+
export declare function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {}), trackingEndpoint?: string): string;
|
|
4
4
|
export {};
|
package/dist/js/env.js
CHANGED
|
@@ -18,14 +18,14 @@ const NavigationApiBaseUrl = {
|
|
|
18
18
|
function resolveApiUrl(path, baseUrl) {
|
|
19
19
|
return `${baseUrl}${baseUrl.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
20
20
|
}
|
|
21
|
-
function getTrackingEndpoint(envOrTrackingApiBaseUrl) {
|
|
21
|
+
function getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint = "tracking/track") {
|
|
22
22
|
let baseUrl;
|
|
23
23
|
if (EnvironmentList.includes(envOrTrackingApiBaseUrl)) {
|
|
24
24
|
baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl];
|
|
25
25
|
} else {
|
|
26
26
|
baseUrl = envOrTrackingApiBaseUrl;
|
|
27
27
|
}
|
|
28
|
-
return resolveApiUrl(
|
|
28
|
+
return resolveApiUrl(trackingEndpoint, baseUrl);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export { getTrackingEndpoint };
|
package/dist/js/env.js.map
CHANGED
|
@@ -1 +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(
|
|
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 & {}), trackingEndpoint = \"tracking/track\"): 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(trackingEndpoint, baseUrl);\n}\n"],"names":["EnvironmentList","NavigationApiBaseUrl","resolveApiUrl","path","baseUrl","getTrackingEndpoint","envOrTrackingApiBaseUrl","trackingEndpoint"],"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,EAAEC,mBAAmB,gBAAgB;IACzH,IAAIH;IAEJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAcK,kBAAkBH;AAC3C"}
|
|
@@ -3,6 +3,12 @@ import { type Environment } from "./env.ts";
|
|
|
3
3
|
* @see https://workleap.github.io/wl-telemetry
|
|
4
4
|
*/
|
|
5
5
|
export interface InitializeMixpanelOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The endpoint to use for tracking events.
|
|
8
|
+
* If not provided, the default endpoint for the environment will be used.
|
|
9
|
+
* @default "tracking/track"
|
|
10
|
+
*/
|
|
11
|
+
trackingEndpoint?: string;
|
|
6
12
|
verbose?: boolean;
|
|
7
13
|
}
|
|
8
14
|
export declare function __resetInitializationGuard(): void;
|
|
@@ -50,9 +50,9 @@ function __resetInitializationGuard() {
|
|
|
50
50
|
* @returns A function that sends tracking events to the tracking API.
|
|
51
51
|
* @see https://workleap.github.io/wl-telemetry
|
|
52
52
|
*/ function initializeMixpanel(productId, envOrTrackingApiBaseUrl, options = {}) {
|
|
53
|
-
const { verbose = false } = options;
|
|
53
|
+
const { verbose = false, trackingEndpoint } = options;
|
|
54
54
|
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
55
|
-
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
55
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);
|
|
56
56
|
const telemetryContext = getTelemetryContext({
|
|
57
57
|
verbose
|
|
58
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { getBootstrappingStore, getTelemetryContext } from \"@workleap/telemetry\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface InitializeMixpanelOptions {\n verbose?: boolean;\n}\nfunction registerLogRocketSessionUrlListener(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 setSuperProperty(OtherProperties.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 = {}) {\n const {\n verbose = false\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n const telemetryContext = getTelemetryContext({ verbose });\n\n setSuperProperties(getTelemetryProperties(telemetryContext));\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(verbose);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(verbose);\n }\n });\n }\n\n setMixpanelContext({\n productId,\n endpoint,\n superProperties: getSuperProperties(),\n verbose\n });\n\n if (verbose) {\n console.log(\"[mixpanel] Mixpanel is initialized.\");\n }\n}\n"],"names":["getBootstrappingStore","getTelemetryContext","setMixpanelContext","getTrackingEndpoint","HasExecutedGuard","getSuperProperties","getTelemetryProperties","OtherProperties","setSuperProperties","setSuperProperty","registerLogRocketSessionUrlListener","verbose","globalThis","sessionUrl","console","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","endpoint","telemetryContext","bootstrappingStore","action","store","unsubscribe"],"mappings":";;;;;;;;;;;;;;;;;AAAiF;AAC/B;AACe;AACR;AAC2E;
|
|
1
|
+
{"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { getBootstrappingStore, getTelemetryContext } from \"@workleap/telemetry\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface InitializeMixpanelOptions {\n /**\n * The endpoint to use for tracking events.\n * If not provided, the default endpoint for the environment will be used.\n * @default \"tracking/track\"\n */\n trackingEndpoint?: string;\n verbose?: boolean;\n}\nfunction registerLogRocketSessionUrlListener(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 setSuperProperty(OtherProperties.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 = {}) {\n const {\n verbose = false,\n trackingEndpoint\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);\n const telemetryContext = getTelemetryContext({ verbose });\n\n setSuperProperties(getTelemetryProperties(telemetryContext));\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(verbose);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(verbose);\n }\n });\n }\n\n setMixpanelContext({\n productId,\n endpoint,\n superProperties: getSuperProperties(),\n verbose\n });\n\n if (verbose) {\n console.log(\"[mixpanel] Mixpanel is initialized.\");\n }\n}\n"],"names":["getBootstrappingStore","getTelemetryContext","setMixpanelContext","getTrackingEndpoint","HasExecutedGuard","getSuperProperties","getTelemetryProperties","OtherProperties","setSuperProperties","setSuperProperty","registerLogRocketSessionUrlListener","verbose","globalThis","sessionUrl","console","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","trackingEndpoint","endpoint","telemetryContext","bootstrappingStore","action","store","unsubscribe"],"mappings":";;;;;;;;;;;;;;;;;AAAiF;AAC/B;AACe;AACR;AAC2E;AAcpI,SAASU,oCAAoCC,UAAU,KAAK;IACxD,6DAA6D;IAC7D,aAAa;IACb,IAAIC,WAAW,mEAAmE,EAAE;QAChF,uFAAuF;QACvF,6DAA6D;QAC7D,aAAa;QACbA,WAAW,mEAAmE,CAAC,CAACC;YAC5E,IAAIF,SAAS;gBACTG,QAAQ,GAAG,CAAC,qDAAqDD;YACrE;YAEAJ,gBAAgBA,CAACF,mCAAmC,EAAEM;QAC1D;IACJ,OAAO,IAAIF,SAAS;QAChBG,QAAQ,GAAG,CAAC;IAChB;AACJ;AAEA,MAAMC,sBAAsB,IAAIX,gBAAgBA;AAEhD,8CAA8C;AACvC,SAASY;IACZD,oBAAoB,KAAK;AAC7B;AAEA;;;;;;;CAOC,GACM,SAASE,mBAAmBC,SAAiB,EAAEC,uBAAoD,EAAEC,UAAqC,CAAC,CAAC;IAC/I,MAAM,EACFT,UAAU,KAAK,EACfU,gBAAgB,EACnB,GAAGD;IAEJL,oBAAoB,KAAK,CAAC;IAE1B,MAAMO,WAAWnB,mBAAmBA,CAACgB,yBAAyBE;IAC9D,MAAME,mBAAmBtB,mBAAmBA,CAAC;QAAEU;IAAQ;IAEvDH,kBAAkBA,CAACF,sBAAsBA,CAACiB;IAE1C,MAAMC,qBAAqBxB,qBAAqBA;IAEhD,4GAA4G;IAC5G,0FAA0F;IAC1F,IAAIwB,mBAAmB,KAAK,CAAC,gBAAgB,EAAE;QAC3Cd,oCAAoCC;IACxC,OAAO;QACHa,mBAAmB,SAAS,CAAC,CAACC,QAAQC,OAAOC;YACzC,IAAID,MAAM,KAAK,CAAC,gBAAgB,EAAE;gBAC9BC;gBACAjB,oCAAoCC;YACxC;QACJ;IACJ;IAEAT,kBAAkBA,CAAC;QACfgB;QACAI;QACA,iBAAiBjB,kBAAkBA;QACnCM;IACJ;IAEA,IAAIA,SAAS;QACTG,QAAQ,GAAG,CAAC;IAChB;AACJ"}
|
package/package.json
CHANGED
package/src/js/env.ts
CHANGED
|
@@ -16,7 +16,7 @@ function resolveApiUrl(path: string, baseUrl: string | undefined) : string {
|
|
|
16
16
|
return `${baseUrl}${baseUrl!.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {
|
|
19
|
+
export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {}), trackingEndpoint = "tracking/track"): string {
|
|
20
20
|
let baseUrl: string;
|
|
21
21
|
|
|
22
22
|
if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {
|
|
@@ -25,5 +25,5 @@ export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (stri
|
|
|
25
25
|
baseUrl = envOrTrackingApiBaseUrl;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return resolveApiUrl(
|
|
28
|
+
return resolveApiUrl(trackingEndpoint, baseUrl);
|
|
29
29
|
}
|
|
@@ -8,6 +8,12 @@ import { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperPr
|
|
|
8
8
|
* @see https://workleap.github.io/wl-telemetry
|
|
9
9
|
*/
|
|
10
10
|
export interface InitializeMixpanelOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The endpoint to use for tracking events.
|
|
13
|
+
* If not provided, the default endpoint for the environment will be used.
|
|
14
|
+
* @default "tracking/track"
|
|
15
|
+
*/
|
|
16
|
+
trackingEndpoint?: string;
|
|
11
17
|
verbose?: boolean;
|
|
12
18
|
}
|
|
13
19
|
function registerLogRocketSessionUrlListener(verbose = false) {
|
|
@@ -46,12 +52,13 @@ export function __resetInitializationGuard() {
|
|
|
46
52
|
*/
|
|
47
53
|
export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {
|
|
48
54
|
const {
|
|
49
|
-
verbose = false
|
|
55
|
+
verbose = false,
|
|
56
|
+
trackingEndpoint
|
|
50
57
|
} = options;
|
|
51
58
|
|
|
52
59
|
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
53
60
|
|
|
54
|
-
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
61
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);
|
|
55
62
|
const telemetryContext = getTelemetryContext({ verbose });
|
|
56
63
|
|
|
57
64
|
setSuperProperties(getTelemetryProperties(telemetryContext));
|