@workleap/mixpanel 4.0.2 → 4.0.3
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 +9 -0
- package/dist/js/MixpanelClient.d.ts +11 -6
- package/dist/js/MixpanelClient.js +5 -13
- package/dist/js/MixpanelClient.js.map +1 -1
- package/dist/js/NoopMixpanelClient.d.ts +4 -2
- package/dist/js/NoopMixpanelClient.js +2 -0
- package/dist/js/NoopMixpanelClient.js.map +1 -1
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.js +1 -5
- package/dist/js/index.js.map +1 -1
- package/dist/js/initializeMixpanel.d.ts +1 -1
- package/dist/js/initializeMixpanel.js +4 -2
- package/dist/js/initializeMixpanel.js.map +1 -1
- package/dist/react/MixpanelContext.d.ts +15 -8
- package/dist/react/MixpanelContext.js +3 -2
- package/dist/react/MixpanelContext.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
- package/src/js/MixpanelClient.ts +19 -11
- package/src/js/NoopMixpanelClient.ts +5 -2
- package/src/js/index.ts +1 -1
- package/src/js/initializeMixpanel.ts +5 -2
- package/src/react/MixpanelContext.tsx +19 -5
- package/src/react/index.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @workleap/mixpanel
|
|
2
2
|
|
|
3
|
+
## 4.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#111](https://github.com/workleap/wl-telemetry/pull/111) [`e146e03`](https://github.com/workleap/wl-telemetry/commit/e146e030aa9e4a624d4429e0ba4f0627153179cc) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added a `NoopTelemetryClient` and added `dontThrowOnUndefined` option to the hooks to retrieve the telemetry clients.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e146e03`](https://github.com/workleap/wl-telemetry/commit/e146e030aa9e4a624d4429e0ba4f0627153179cc)]:
|
|
10
|
+
- @workleap/logrocket@2.1.3
|
|
11
|
+
|
|
3
12
|
## 4.0.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import type { CreateMixpanelTrackingFunctionOptions,
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
2
2
|
import type { Logger } from "@workleap/logging";
|
|
3
3
|
export type MixpanelGlobalEventProperties = Map<string, unknown>;
|
|
4
4
|
/**
|
|
5
5
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
#private;
|
|
9
|
-
constructor(productId: string, endpoint: string, globalEventProperties: MixpanelGlobalEventProperties, logger: Logger);
|
|
7
|
+
export interface MixpanelClient {
|
|
10
8
|
/**
|
|
11
9
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
12
10
|
*/
|
|
13
|
-
createTrackingFunction(options
|
|
11
|
+
createTrackingFunction: (options: CreateMixpanelTrackingFunctionOptions) => MixpanelTrackingFunction;
|
|
14
12
|
/**
|
|
15
13
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
16
14
|
*/
|
|
17
|
-
setGlobalEventProperty(key: string, value: unknown)
|
|
15
|
+
setGlobalEventProperty: (key: string, value: unknown) => void;
|
|
18
16
|
/**
|
|
19
17
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
20
18
|
*/
|
|
19
|
+
setGlobalEventProperties: (values: Record<string, unknown>) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare class MixpanelClientImpl implements MixpanelClient {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(productId: string, endpoint: string, globalEventProperties: MixpanelGlobalEventProperties, logger: Logger);
|
|
24
|
+
createTrackingFunction(options?: CreateMixpanelTrackingFunctionOptions): MixpanelTrackingFunction;
|
|
25
|
+
setGlobalEventProperty(key: string, value: unknown): void;
|
|
21
26
|
setGlobalEventProperties(values: Record<string, unknown>): void;
|
|
22
27
|
}
|
|
@@ -4,9 +4,7 @@ import { getBaseProperties } from "./properties.js";
|
|
|
4
4
|
|
|
5
5
|
;// CONCATENATED MODULE: ./src/js/MixpanelClient.ts
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
9
|
-
*/ class MixpanelClient {
|
|
7
|
+
class MixpanelClientImpl {
|
|
10
8
|
#productId;
|
|
11
9
|
#endpoint;
|
|
12
10
|
#globalEventProperties;
|
|
@@ -19,9 +17,7 @@ import { getBaseProperties } from "./properties.js";
|
|
|
19
17
|
}
|
|
20
18
|
// IMPORTANT: If you update this method, make sure to update the MixpanelPartialClient
|
|
21
19
|
// interface as well in @workleap-telemetry/core.
|
|
22
|
-
|
|
23
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
24
|
-
*/ createTrackingFunction(options = {}) {
|
|
20
|
+
createTrackingFunction(options = {}) {
|
|
25
21
|
const { targetProductId } = options;
|
|
26
22
|
const trackFunction = async (eventName, properties, _options = {})=>{
|
|
27
23
|
try {
|
|
@@ -54,20 +50,16 @@ import { getBaseProperties } from "./properties.js";
|
|
|
54
50
|
};
|
|
55
51
|
return trackFunction;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
59
|
-
*/ setGlobalEventProperty(key, value) {
|
|
53
|
+
setGlobalEventProperty(key, value) {
|
|
60
54
|
this.#globalEventProperties.set(key, value);
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
64
|
-
*/ setGlobalEventProperties(values) {
|
|
56
|
+
setGlobalEventProperties(values) {
|
|
65
57
|
Object.keys(values).forEach((x)=>{
|
|
66
58
|
this.#globalEventProperties.set(x, values[x]);
|
|
67
59
|
});
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
export {
|
|
63
|
+
export { MixpanelClientImpl };
|
|
72
64
|
|
|
73
65
|
//# sourceMappingURL=MixpanelClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/MixpanelClient.js","sources":["webpack://@workleap/mixpanel/./src/js/MixpanelClient.ts"],"sourcesContent":["import type { CreateMixpanelTrackingFunctionOptions,
|
|
1
|
+
{"version":3,"file":"js/MixpanelClient.js","sources":["webpack://@workleap/mixpanel/./src/js/MixpanelClient.ts"],"sourcesContent":["import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from \"@workleap-telemetry/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport { getBaseProperties } from \"./properties.ts\";\n\nexport type MixpanelGlobalEventProperties = Map<string, unknown>;\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface MixpanelClient {\n /**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n createTrackingFunction: (options: CreateMixpanelTrackingFunctionOptions) => MixpanelTrackingFunction;\n\n /**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n setGlobalEventProperty: (key: string, value: unknown) => void;\n\n /**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n setGlobalEventProperties: (values: Record<string, unknown>) => void;\n}\n\nexport class MixpanelClientImpl implements MixpanelClient {\n readonly #productId: string;\n readonly #endpoint: string;\n readonly #globalEventProperties: MixpanelGlobalEventProperties;\n readonly #logger: Logger;\n\n constructor(productId: string, endpoint: string, globalEventProperties: MixpanelGlobalEventProperties, logger: Logger) {\n this.#productId = productId;\n this.#endpoint = endpoint;\n this.#globalEventProperties = globalEventProperties;\n this.#logger = logger;\n }\n\n // IMPORTANT: If you update this method, make sure to update the MixpanelPartialClient\n // interface as well in @workleap-telemetry/core.\n createTrackingFunction(options: CreateMixpanelTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n const trackFunction: MixpanelTrackingFunction = 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(this.#globalEventProperties),\n ...properties\n };\n\n await fetch(this.#endpoint, {\n method: \"POST\",\n credentials: \"include\",\n keepalive: keepAlive,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n eventName,\n productIdentifier: this.#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 } catch (error: unknown) {\n this.#logger\n .withText(`[mixpanel] An error occurred while sending a tracking event to \"${this.#endpoint}\":`)\n .withError(error as Error)\n .error();\n }\n };\n\n return trackFunction;\n }\n\n setGlobalEventProperty(key: string, value: unknown) {\n this.#globalEventProperties.set(key, value);\n }\n\n setGlobalEventProperties(values: Record<string, unknown>) {\n Object.keys(values).forEach(x => {\n this.#globalEventProperties.set(x, values[x]);\n });\n }\n}\n"],"names":["getBaseProperties","MixpanelClientImpl","productId","endpoint","globalEventProperties","logger","options","targetProductId","trackFunction","eventName","properties","_options","keepAlive","baseProperties","allProperties","Object","fetch","JSON","error","key","value","values","x"],"mappings":";;;;;AAEoD;AAwB7C,MAAMC;IACA,UAAU,CAAS;IACnB,SAAS,CAAS;IAClB,sBAAsB,CAAgC;IACtD,OAAO,CAAS;IAEzB,YAAYC,SAAiB,EAAEC,QAAgB,EAAEC,qBAAoD,EAAEC,MAAc,CAAE;QACnH,IAAI,CAAC,UAAU,GAAGH;QAClB,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,sBAAsB,GAAGC;QAC9B,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,sFAAsF;IACtF,iDAAiD;IACjD,uBAAuBC,UAAiD,CAAC,CAAC,EAAE;QACxE,MAAM,EACFC,eAAe,EAClB,GAAGD;QAEJ,MAAME,gBAA0C,OAAOC,WAAWC,YAAYC,WAAW,CAAC,CAAC;YACvF,IAAI;gBACA,MAAM,EACFC,YAAY,KAAK,EACpB,GAAGD;gBAEJ,MAAME,iBAAiBb,iBAAiBA;gBAExC,MAAMc,gBAAgB;oBAClB,GAAGD,cAAc;oBACjB,GAAGE,OAAO,WAAW,CAAC,IAAI,CAAC,sBAAsB,CAAC;oBAClD,GAAGL,UAAU;gBACjB;gBAEA,MAAMM,MAAM,IAAI,CAAC,SAAS,EAAE;oBACxB,QAAQ;oBACR,aAAa;oBACb,WAAWJ;oBACX,SAAS;wBAAE,gBAAgB;oBAAmB;oBAC9C,MAAMK,KAAK,SAAS,CAAC;wBACjBR;wBACA,mBAAmB,IAAI,CAAC,UAAU;wBAClC,uFAAuF;wBACvF,gBAAgB;wBAChB,yBAA0BF,mBAAmB;wBAC7C,YAAYO;oBAChB;gBACJ;YACJ,EAAE,OAAOI,OAAgB;gBACrB,IAAI,CAAC,OAAO,CACP,QAAQ,CAAC,CAAC,gEAAgE,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAC9F,SAAS,CAACA,OACV,KAAK;YACd;QACJ;QAEA,OAAOV;IACX;IAEA,uBAAuBW,GAAW,EAAEC,KAAc,EAAE;QAChD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACD,KAAKC;IACzC;IAEA,yBAAyBC,MAA+B,EAAE;QACtDN,OAAO,IAAI,CAACM,QAAQ,OAAO,CAACC,CAAAA;YACxB,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACA,GAAGD,MAAM,CAACC,EAAE;QAChD;IACJ;AACJ"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare class NoopMixpanelClient implements
|
|
1
|
+
import type { MixpanelClient } from "./MixpanelClient.ts";
|
|
2
|
+
export declare class NoopMixpanelClient implements MixpanelClient {
|
|
3
3
|
createTrackingFunction(): () => Promise<void>;
|
|
4
|
+
setGlobalEventProperty(): void;
|
|
5
|
+
setGlobalEventProperties(): void;
|
|
4
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/NoopMixpanelClient.js","sources":["webpack://@workleap/mixpanel/./src/js/NoopMixpanelClient.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"js/NoopMixpanelClient.js","sources":["webpack://@workleap/mixpanel/./src/js/NoopMixpanelClient.ts"],"sourcesContent":["import type { MixpanelClient } from \"./MixpanelClient.ts\";\n\nexport class NoopMixpanelClient implements MixpanelClient {\n createTrackingFunction() {\n return () => Promise.resolve();\n }\n\n setGlobalEventProperty() {}\n setGlobalEventProperties() {}\n}\n"],"names":["NoopMixpanelClient","Promise"],"mappings":";;AAEO,MAAMA;IACT,yBAAyB;QACrB,OAAO,IAAMC,QAAQ,OAAO;IAChC;IAEA,yBAAyB,CAAC;IAC1B,2BAA2B,CAAC;AAChC"}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, Mi
|
|
|
3
3
|
export { createTrackingFunction } from "./createTrackingFunction.ts";
|
|
4
4
|
export type { MixpanelEnvironment } from "./env.ts";
|
|
5
5
|
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
6
|
-
export { MixpanelClient,
|
|
6
|
+
export type { MixpanelClient, MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
7
7
|
export { NoopMixpanelClient } from "./NoopMixpanelClient.ts";
|
package/dist/js/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createTelemetryContext } from "@workleap-telemetry/core";
|
|
2
2
|
import { createTrackingFunction } from "./createTrackingFunction.js";
|
|
3
3
|
import { initializeMixpanel } from "./initializeMixpanel.js";
|
|
4
|
-
import { MixpanelClient } from "./MixpanelClient.js";
|
|
5
4
|
import { NoopMixpanelClient } from "./NoopMixpanelClient.js";
|
|
6
5
|
|
|
7
6
|
;// CONCATENATED MODULE: external "@workleap-telemetry/core"
|
|
@@ -10,8 +9,6 @@ import { NoopMixpanelClient } from "./NoopMixpanelClient.js";
|
|
|
10
9
|
|
|
11
10
|
;// CONCATENATED MODULE: external "./initializeMixpanel.js"
|
|
12
11
|
|
|
13
|
-
;// CONCATENATED MODULE: external "./MixpanelClient.js"
|
|
14
|
-
|
|
15
12
|
;// CONCATENATED MODULE: external "./NoopMixpanelClient.js"
|
|
16
13
|
|
|
17
14
|
;// CONCATENATED MODULE: ./src/js/index.ts
|
|
@@ -20,7 +17,6 @@ import { NoopMixpanelClient } from "./NoopMixpanelClient.js";
|
|
|
20
17
|
|
|
21
18
|
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
export { MixpanelClient, NoopMixpanelClient, createTelemetryContext, createTrackingFunction, initializeMixpanel };
|
|
20
|
+
export { NoopMixpanelClient, createTelemetryContext, createTrackingFunction, initializeMixpanel };
|
|
25
21
|
|
|
26
22
|
//# sourceMappingURL=index.js.map
|
package/dist/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/index.js","sources":["webpack://@workleap/mixpanel/./src/js/index.ts"],"sourcesContent":["export { createTelemetryContext, type CreateTelemetryContextOptions, type TelemetryContext } from \"@workleap-telemetry/core\";\nexport type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, MixpanelTrackingFunction, MixpanelTrackingFunctionOptions } from \"@workleap-telemetry/core\";\nexport { createTrackingFunction } from \"./createTrackingFunction.ts\";\nexport type { MixpanelEnvironment } from \"./env.ts\";\nexport { initializeMixpanel, type InitializeMixpanelOptions } from \"./initializeMixpanel.ts\";\nexport { MixpanelClient,
|
|
1
|
+
{"version":3,"file":"js/index.js","sources":["webpack://@workleap/mixpanel/./src/js/index.ts"],"sourcesContent":["export { createTelemetryContext, type CreateTelemetryContextOptions, type TelemetryContext } from \"@workleap-telemetry/core\";\nexport type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, MixpanelTrackingFunction, MixpanelTrackingFunctionOptions } from \"@workleap-telemetry/core\";\nexport { createTrackingFunction } from \"./createTrackingFunction.ts\";\nexport type { MixpanelEnvironment } from \"./env.ts\";\nexport { initializeMixpanel, type InitializeMixpanelOptions } from \"./initializeMixpanel.ts\";\nexport type { MixpanelClient, MixpanelGlobalEventProperties } from \"./MixpanelClient.ts\";\nexport { NoopMixpanelClient } from \"./NoopMixpanelClient.ts\";\n\n"],"names":["createTelemetryContext","createTrackingFunction","initializeMixpanel","NoopMixpanelClient"],"mappings":";;;;;;;;;;;;;;AAA6H;AAExD;AAEwB;AAEhC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type LogRocketInstrumentationPartialClient, type TelemetryContext } from "@workleap-telemetry/core";
|
|
2
2
|
import { type RootLogger } from "@workleap/logging";
|
|
3
3
|
import { type MixpanelEnvironment } from "./env.ts";
|
|
4
|
-
import { MixpanelClient, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
4
|
+
import { type MixpanelClient, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
5
5
|
export declare const IsInitializedVariableName = "__WLP_MIXPANEL_IS_INITIALIZED__";
|
|
6
6
|
export declare function __resetRegistrationGuard(): void;
|
|
7
7
|
/**
|
|
@@ -2,7 +2,7 @@ import { HasExecutedGuard } from "@workleap-telemetry/core";
|
|
|
2
2
|
import { createCompositeLogger } from "@workleap/logging";
|
|
3
3
|
import { setMixpanelContext } from "./context.js";
|
|
4
4
|
import { getTrackingEndpoint } from "./env.js";
|
|
5
|
-
import {
|
|
5
|
+
import { MixpanelClientImpl } from "./MixpanelClient.js";
|
|
6
6
|
import { OtherProperties, getTelemetryProperties } from "./properties.js";
|
|
7
7
|
|
|
8
8
|
;// CONCATENATED MODULE: external "@workleap-telemetry/core"
|
|
@@ -83,7 +83,9 @@ class MixpanelInitializer {
|
|
|
83
83
|
}
|
|
84
84
|
registerDeprecatedContextAndGlobalVariables(productId, endpoint, this.#globalEventProperties, logger);
|
|
85
85
|
logger.information("[mixpanel] Mixpanel is initialized.");
|
|
86
|
-
|
|
86
|
+
const client = new MixpanelClientImpl(productId, endpoint, this.#globalEventProperties, logger);
|
|
87
|
+
// The cast is to normalize the inferred return type to the "LogRocketInstrumentationClient" type.
|
|
88
|
+
return client;
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { HasExecutedGuard, type LogRocketInstrumentationPartialClient, type TelemetryContext } from \"@workleap-telemetry/core\";\nimport { createCompositeLogger, type Logger, type RootLogger } from \"@workleap/logging\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type MixpanelEnvironment } from \"./env.ts\";\nimport { MixpanelClient, type MixpanelGlobalEventProperties } from \"./MixpanelClient.ts\";\nimport { getTelemetryProperties, OtherProperties } from \"./properties.ts\";\n\n// DEPRECATED: Grace period ends on January 1th 2026.\n// Don't forget to remove the tests as well.\nexport const IsInitializedVariableName = \"__WLP_MIXPANEL_IS_INITIALIZED__\";\n\n// DEPRECATED: Grace period ends on January 1th 2026.\nfunction registerDeprecatedContextAndGlobalVariables(productId: string, endpoint: string, globalEventProperties: Map<string, unknown>, logger: Logger) {\n setMixpanelContext({\n productId,\n endpoint,\n globalEventProperties,\n logger\n });\n\n // Indicates to the host applications that Mixpanel has been initialized.\n // It's useful in cases where an \"add-on\", like the platform widgets needs\n // to know whether or not the host application is using Mixpanel.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[IsInitializedVariableName] = true;\n}\n\n///////////////////////////\n\nlet registrationGuardInstance: HasExecutedGuard | undefined;\n\n// It's important to use a lazy singleton instead of a singleton to avoid\n// any future probleme related to HMR, tree-shaking, SSR, etc..\nfunction getRegistrationGuard() {\n if (!registrationGuardInstance) {\n registrationGuardInstance = new HasExecutedGuard();\n }\n\n return registrationGuardInstance;\n}\n\n// This function should only be used by tests.\nexport function __resetRegistrationGuard() {\n if (registrationGuardInstance) {\n registrationGuardInstance.reset();\n }\n}\n\n///////////////////////////\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface InitializeMixpanelOptions {\n /**\n * An optional tracking endpoint.\n * @default \"tracking/track\"\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n trackingEndpoint?: string;\n /**\n * Context including telemetry correlation ids.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n telemetryContext?: TelemetryContext;\n /**\n * An optional LogRocket client to automatically add the LogRocket\n * session URL to Mixpanel events once it's available.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n logRocketInstrumentationClient?: LogRocketInstrumentationPartialClient;\n /**\n * Whether or not debug information should be logged to the console.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n verbose?: boolean;\n /**\n * An array of RootLogger instances.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n loggers?: RootLogger[];\n}\n\n\nexport class MixpanelInitializer {\n readonly #globalEventProperties: MixpanelGlobalEventProperties;\n\n constructor(globalEventProperties: MixpanelGlobalEventProperties) {\n this.#globalEventProperties = globalEventProperties;\n }\n\n initialize(\n productId: string,\n envOrTrackingApiBaseUrl: MixpanelEnvironment | (string & {}),\n options: InitializeMixpanelOptions = {}\n ) {\n const {\n trackingEndpoint,\n telemetryContext,\n logRocketInstrumentationClient,\n verbose = false,\n loggers = []\n } = options;\n\n const logger = createCompositeLogger(verbose, loggers);\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);\n\n // Set the telemetry correlation ids on every Mixpanel event.\n if (telemetryContext) {\n for (const [key, value] of Object.entries(getTelemetryProperties(telemetryContext))) {\n this.#globalEventProperties.set(key, value);\n }\n }\n\n // If a LogRocket client is already available, register a listener to get the LogRocket session url\n // once it's available to set it on every Mixpanel event.\n if (logRocketInstrumentationClient) {\n logRocketInstrumentationClient.registerGetSessionUrlListener((sessionUrl: string) => {\n logger\n .withText(\"[mixpanel] Received LogRocket session replay URL:\")\n .withText(sessionUrl)\n .debug();\n\n this.#globalEventProperties.set(OtherProperties.LogRocketSessionUrl, sessionUrl);\n });\n }\n\n registerDeprecatedContextAndGlobalVariables(productId, endpoint, this.#globalEventProperties, logger);\n\n logger.information(\"[mixpanel] Mixpanel is initialized.\");\n\n
|
|
1
|
+
{"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { HasExecutedGuard, type LogRocketInstrumentationPartialClient, type TelemetryContext } from \"@workleap-telemetry/core\";\nimport { createCompositeLogger, type Logger, type RootLogger } from \"@workleap/logging\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type MixpanelEnvironment } from \"./env.ts\";\nimport { type MixpanelClient, MixpanelClientImpl, type MixpanelGlobalEventProperties } from \"./MixpanelClient.ts\";\nimport { getTelemetryProperties, OtherProperties } from \"./properties.ts\";\n\n// DEPRECATED: Grace period ends on January 1th 2026.\n// Don't forget to remove the tests as well.\nexport const IsInitializedVariableName = \"__WLP_MIXPANEL_IS_INITIALIZED__\";\n\n// DEPRECATED: Grace period ends on January 1th 2026.\nfunction registerDeprecatedContextAndGlobalVariables(productId: string, endpoint: string, globalEventProperties: Map<string, unknown>, logger: Logger) {\n setMixpanelContext({\n productId,\n endpoint,\n globalEventProperties,\n logger\n });\n\n // Indicates to the host applications that Mixpanel has been initialized.\n // It's useful in cases where an \"add-on\", like the platform widgets needs\n // to know whether or not the host application is using Mixpanel.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[IsInitializedVariableName] = true;\n}\n\n///////////////////////////\n\nlet registrationGuardInstance: HasExecutedGuard | undefined;\n\n// It's important to use a lazy singleton instead of a singleton to avoid\n// any future probleme related to HMR, tree-shaking, SSR, etc..\nfunction getRegistrationGuard() {\n if (!registrationGuardInstance) {\n registrationGuardInstance = new HasExecutedGuard();\n }\n\n return registrationGuardInstance;\n}\n\n// This function should only be used by tests.\nexport function __resetRegistrationGuard() {\n if (registrationGuardInstance) {\n registrationGuardInstance.reset();\n }\n}\n\n///////////////////////////\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface InitializeMixpanelOptions {\n /**\n * An optional tracking endpoint.\n * @default \"tracking/track\"\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n trackingEndpoint?: string;\n /**\n * Context including telemetry correlation ids.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n telemetryContext?: TelemetryContext;\n /**\n * An optional LogRocket client to automatically add the LogRocket\n * session URL to Mixpanel events once it's available.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n logRocketInstrumentationClient?: LogRocketInstrumentationPartialClient;\n /**\n * Whether or not debug information should be logged to the console.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n verbose?: boolean;\n /**\n * An array of RootLogger instances.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n loggers?: RootLogger[];\n}\n\n\nexport class MixpanelInitializer {\n readonly #globalEventProperties: MixpanelGlobalEventProperties;\n\n constructor(globalEventProperties: MixpanelGlobalEventProperties) {\n this.#globalEventProperties = globalEventProperties;\n }\n\n initialize(\n productId: string,\n envOrTrackingApiBaseUrl: MixpanelEnvironment | (string & {}),\n options: InitializeMixpanelOptions = {}\n ) {\n const {\n trackingEndpoint,\n telemetryContext,\n logRocketInstrumentationClient,\n verbose = false,\n loggers = []\n } = options;\n\n const logger = createCompositeLogger(verbose, loggers);\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);\n\n // Set the telemetry correlation ids on every Mixpanel event.\n if (telemetryContext) {\n for (const [key, value] of Object.entries(getTelemetryProperties(telemetryContext))) {\n this.#globalEventProperties.set(key, value);\n }\n }\n\n // If a LogRocket client is already available, register a listener to get the LogRocket session url\n // once it's available to set it on every Mixpanel event.\n if (logRocketInstrumentationClient) {\n logRocketInstrumentationClient.registerGetSessionUrlListener((sessionUrl: string) => {\n logger\n .withText(\"[mixpanel] Received LogRocket session replay URL:\")\n .withText(sessionUrl)\n .debug();\n\n this.#globalEventProperties.set(OtherProperties.LogRocketSessionUrl, sessionUrl);\n });\n }\n\n registerDeprecatedContextAndGlobalVariables(productId, endpoint, this.#globalEventProperties, logger);\n\n logger.information(\"[mixpanel] Mixpanel is initialized.\");\n\n const client = new MixpanelClientImpl(productId, endpoint, this.#globalEventProperties, logger);\n\n // The cast is to normalize the inferred return type to the \"LogRocketInstrumentationClient\" type.\n return client as MixpanelClient;\n }\n}\n\n/**\n * Initialize Mixpanel telemetry.\n * @param productId The Mixpanel product identifier.\n * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.\n * @param options Mixpanel instrumentation options.\n * @returns {MixpanelClient} A Mixpanel client instance.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function initializeMixpanel(\n productId: string,\n envOrTrackingApiBaseUrl: MixpanelEnvironment | (string & {}),\n options?: InitializeMixpanelOptions\n) {\n getRegistrationGuard().throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n return new MixpanelInitializer(\n new Map<string, unknown>()\n ).initialize(\n productId,\n envOrTrackingApiBaseUrl,\n options\n );\n}\n"],"names":["HasExecutedGuard","createCompositeLogger","setMixpanelContext","getTrackingEndpoint","MixpanelClientImpl","getTelemetryProperties","OtherProperties","IsInitializedVariableName","registerDeprecatedContextAndGlobalVariables","productId","endpoint","globalEventProperties","logger","globalThis","registrationGuardInstance","getRegistrationGuard","__resetRegistrationGuard","MixpanelInitializer","envOrTrackingApiBaseUrl","options","trackingEndpoint","telemetryContext","logRocketInstrumentationClient","verbose","loggers","key","value","Object","sessionUrl","client","initializeMixpanel","Map"],"mappings":";;;;;;;;;;;;;;;;;;;;AAA+H;AACvC;AACtC;AACuB;AACyC;AACxC;AAE1E,qDAAqD;AACrD,4CAA4C;AACrC,MAAMO,4BAA4B,kCAAkC;AAE3E,qDAAqD;AACrD,SAASC,4CAA4CC,SAAiB,EAAEC,QAAgB,EAAEC,qBAA2C,EAAEC,MAAc;IACjJV,kBAAkBA,CAAC;QACfO;QACAC;QACAC;QACAC;IACJ;IAEA,yEAAyE;IACzE,0EAA0E;IAC1E,iEAAiE;IACjE,6DAA6D;IAC7D,aAAa;IACbC,UAAU,CAACN,0BAA0B,GAAG;AAC5C;AAEA,2BAA2B;AAE3B,IAAIO;AAEJ,yEAAyE;AACzE,+DAA+D;AAC/D,SAASC;IACL,IAAI,CAACD,2BAA2B;QAC5BA,4BAA4B,IAAId,gBAAgBA;IACpD;IAEA,OAAOc;AACX;AAEA,8CAA8C;AACvC,SAASE;IACZ,IAAIF,2BAA2B;QAC3BA,0BAA0B,KAAK;IACnC;AACJ;AAsCO,MAAMG;IACA,sBAAsB,CAAgC;IAE/D,YAAYN,qBAAoD,CAAE;QAC9D,IAAI,CAAC,sBAAsB,GAAGA;IAClC;IAEA,WACIF,SAAiB,EACjBS,uBAA4D,EAC5DC,UAAqC,CAAC,CAAC,EACzC;QACE,MAAM,EACFC,gBAAgB,EAChBC,gBAAgB,EAChBC,8BAA8B,EAC9BC,UAAU,KAAK,EACfC,UAAU,EAAE,EACf,GAAGL;QAEJ,MAAMP,SAASX,qBAAqBA,CAACsB,SAASC;QAC9C,MAAMd,WAAWP,mBAAmBA,CAACe,yBAAyBE;QAE9D,6DAA6D;QAC7D,IAAIC,kBAAkB;YAClB,KAAK,MAAM,CAACI,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACtB,sBAAsBA,CAACgB,mBAAoB;gBACjF,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACI,KAAKC;YACzC;QACJ;QAEA,mGAAmG;QACnG,yDAAyD;QACzD,IAAIJ,gCAAgC;YAChCA,+BAA+B,6BAA6B,CAAC,CAACM;gBAC1DhB,OACK,QAAQ,CAAC,qDACT,QAAQ,CAACgB,YACT,KAAK;gBAEV,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACtB,mCAAmC,EAAEsB;YACzE;QACJ;QAEApB,4CAA4CC,WAAWC,UAAU,IAAI,CAAC,sBAAsB,EAAEE;QAE9FA,OAAO,WAAW,CAAC;QAEnB,MAAMiB,SAAS,IAAIzB,kBAAkBA,CAACK,WAAWC,UAAU,IAAI,CAAC,sBAAsB,EAAEE;QAExF,kGAAkG;QAClG,OAAOiB;IACX;AACJ;AAEA;;;;;;;CAOC,GACM,SAASC,mBACZrB,SAAiB,EACjBS,uBAA4D,EAC5DC,OAAmC;IAEnCJ,uBAAuB,KAAK,CAAC;IAE7B,OAAO,IAAIE,oBACP,IAAIc,OACN,UAAU,CACRtB,WACAS,yBACAC;AAER"}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import type { MixpanelPartialClient } from "@workleap-telemetry/core";
|
|
2
1
|
import { type PropsWithChildren } from "react";
|
|
3
|
-
|
|
2
|
+
import type { MixpanelClient } from "../js/MixpanelClient.ts";
|
|
3
|
+
export declare const MixpanelContext: import("react").Context<MixpanelClient | undefined>;
|
|
4
4
|
/**
|
|
5
5
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
6
6
|
*/
|
|
7
7
|
export interface MixpanelProviderProps extends PropsWithChildren {
|
|
8
|
-
client:
|
|
8
|
+
client: MixpanelClient;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
12
12
|
*/
|
|
13
13
|
export declare function MixpanelProvider(props: MixpanelProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export interface UseMixpanelClientOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Whether or not an exception should be thrown if the client hasn't been provided.
|
|
17
|
+
*/
|
|
18
|
+
dontThrowOnUndefined?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function useMixpanelClient(options?: {
|
|
21
|
+
dontThrowOnUndefined?: false;
|
|
22
|
+
}): MixpanelClient;
|
|
23
|
+
export declare function useMixpanelClient(options: {
|
|
24
|
+
dontThrowOnUndefined: true;
|
|
25
|
+
}): MixpanelClient | undefined;
|
|
@@ -21,9 +21,10 @@ const MixpanelContext = /*#__PURE__*/ createContext(undefined);
|
|
|
21
21
|
/**
|
|
22
22
|
* Retrieve the Mixpanel client.
|
|
23
23
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
24
|
-
*/ function useMixpanelClient() {
|
|
24
|
+
*/ function useMixpanelClient(options = {}) {
|
|
25
|
+
const { dontThrowOnUndefined = false } = options;
|
|
25
26
|
const client = useContext(MixpanelContext);
|
|
26
|
-
if (!client) {
|
|
27
|
+
if (!client && !dontThrowOnUndefined) {
|
|
27
28
|
throw new Error("[mixpanel] The useMixpanelClient function is called before a MixpanelClient instance has been provided.");
|
|
28
29
|
}
|
|
29
30
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react/MixpanelContext.js","sources":["webpack://@workleap/mixpanel/./src/react/MixpanelContext.tsx"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"react/MixpanelContext.js","sources":["webpack://@workleap/mixpanel/./src/react/MixpanelContext.tsx"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from \"react\";\nimport type { MixpanelClient } from \"../js/MixpanelClient.ts\";\n\nexport const MixpanelContext = createContext<MixpanelClient | undefined>(undefined);\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface MixpanelProviderProps extends PropsWithChildren {\n client: MixpanelClient;\n}\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function MixpanelProvider(props: MixpanelProviderProps) {\n const {\n client,\n children\n } = props;\n\n return (\n <MixpanelContext.Provider value={client}>\n {children}\n </MixpanelContext.Provider>\n );\n}\n\nexport interface UseMixpanelClientOptions {\n /**\n * Whether or not an exception should be thrown if the client hasn't been provided.\n */\n dontThrowOnUndefined?: boolean;\n}\n\nexport function useMixpanelClient(options?: { dontThrowOnUndefined?: false }): MixpanelClient;\nexport function useMixpanelClient(options: { dontThrowOnUndefined: true }): MixpanelClient | undefined;\n\n/**\n * Retrieve the Mixpanel client.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function useMixpanelClient(options: UseMixpanelClientOptions = {}) {\n const {\n dontThrowOnUndefined = false\n } = options;\n\n const client = useContext(MixpanelContext);\n\n if (!client && !dontThrowOnUndefined) {\n throw new Error(\"[mixpanel] The useMixpanelClient function is called before a MixpanelClient instance has been provided.\");\n }\n\n return client;\n}\n"],"names":["createContext","useContext","MixpanelContext","undefined","MixpanelProvider","props","client","children","useMixpanelClient","options","dontThrowOnUndefined","Error"],"mappings":";;;;;;;;;AAA0E;AAGnE,MAAME,gCAAkBF,aAAaA,CAA6BG,WAAW;AASpF;;CAEC,GACM,SAASC,iBAAiBC,KAA4B;IACzD,MAAM,EACFC,MAAM,EACNC,QAAQ,EACX,GAAGF;IAEJ,qBACI,IAACH,gBAAgB,QAAQ;QAAC,OAAOI;kBAC5BC;;AAGb;AAYA;;;CAGC,GACM,SAASC,kBAAkBC,UAAoC,CAAC,CAAC;IACpE,MAAM,EACFC,uBAAuB,KAAK,EAC/B,GAAGD;IAEJ,MAAMH,SAASL,UAAUA,CAACC;IAE1B,IAAI,CAACI,UAAU,CAACI,sBAAsB;QAClC,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOL;AACX"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "../js/index.ts";
|
|
2
|
-
export { MixpanelProvider, useMixpanelClient } from "./MixpanelContext.tsx";
|
|
2
|
+
export { MixpanelProvider, useMixpanelClient, type UseMixpanelClientOptions } from "./MixpanelContext.tsx";
|
|
3
3
|
export { useTrackingFunction, type UseTrackingFunctionOptions } from "./useTrackingFunction.ts";
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react/index.js","sources":["webpack://@workleap/mixpanel/./src/react/index.ts"],"sourcesContent":["export * from \"../js/index.ts\";\nexport { MixpanelProvider, useMixpanelClient } from \"./MixpanelContext.tsx\";\nexport { useTrackingFunction, type UseTrackingFunctionOptions } from \"./useTrackingFunction.ts\";\n\n"],"names":["MixpanelProvider","useMixpanelClient","useTrackingFunction"],"mappings":";;;;;;;;;AAA+B;
|
|
1
|
+
{"version":3,"file":"react/index.js","sources":["webpack://@workleap/mixpanel/./src/react/index.ts"],"sourcesContent":["export * from \"../js/index.ts\";\nexport { MixpanelProvider, useMixpanelClient, type UseMixpanelClientOptions } from \"./MixpanelContext.tsx\";\nexport { useTrackingFunction, type UseTrackingFunctionOptions } from \"./useTrackingFunction.ts\";\n\n"],"names":["MixpanelProvider","useMixpanelClient","useTrackingFunction"],"mappings":";;;;;;;;;AAA+B;AAC4E;AACX"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workleap/mixpanel",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.3",
|
|
5
5
|
"description": "A package containing utilities for Mixpanel telemetry.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
37
37
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
38
|
-
"@workleap/logrocket": "2.1.
|
|
38
|
+
"@workleap/logrocket": "2.1.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@workleap/logrocket": {
|
package/src/js/MixpanelClient.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateMixpanelTrackingFunctionOptions,
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
2
2
|
import type { Logger } from "@workleap/logging";
|
|
3
3
|
import { getBaseProperties } from "./properties.ts";
|
|
4
4
|
|
|
@@ -7,7 +7,24 @@ export type MixpanelGlobalEventProperties = Map<string, unknown>;
|
|
|
7
7
|
/**
|
|
8
8
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export interface MixpanelClient {
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
13
|
+
*/
|
|
14
|
+
createTrackingFunction: (options: CreateMixpanelTrackingFunctionOptions) => MixpanelTrackingFunction;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
18
|
+
*/
|
|
19
|
+
setGlobalEventProperty: (key: string, value: unknown) => void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
23
|
+
*/
|
|
24
|
+
setGlobalEventProperties: (values: Record<string, unknown>) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class MixpanelClientImpl implements MixpanelClient {
|
|
11
28
|
readonly #productId: string;
|
|
12
29
|
readonly #endpoint: string;
|
|
13
30
|
readonly #globalEventProperties: MixpanelGlobalEventProperties;
|
|
@@ -22,9 +39,6 @@ export class MixpanelClient implements MixpanelPartialClient {
|
|
|
22
39
|
|
|
23
40
|
// IMPORTANT: If you update this method, make sure to update the MixpanelPartialClient
|
|
24
41
|
// interface as well in @workleap-telemetry/core.
|
|
25
|
-
/**
|
|
26
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
27
|
-
*/
|
|
28
42
|
createTrackingFunction(options: CreateMixpanelTrackingFunctionOptions = {}) {
|
|
29
43
|
const {
|
|
30
44
|
targetProductId
|
|
@@ -69,16 +83,10 @@ export class MixpanelClient implements MixpanelPartialClient {
|
|
|
69
83
|
return trackFunction;
|
|
70
84
|
}
|
|
71
85
|
|
|
72
|
-
/**
|
|
73
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
74
|
-
*/
|
|
75
86
|
setGlobalEventProperty(key: string, value: unknown) {
|
|
76
87
|
this.#globalEventProperties.set(key, value);
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
/**
|
|
80
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
81
|
-
*/
|
|
82
90
|
setGlobalEventProperties(values: Record<string, unknown>) {
|
|
83
91
|
Object.keys(values).forEach(x => {
|
|
84
92
|
this.#globalEventProperties.set(x, values[x]);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MixpanelClient } from "./MixpanelClient.ts";
|
|
2
2
|
|
|
3
|
-
export class NoopMixpanelClient implements
|
|
3
|
+
export class NoopMixpanelClient implements MixpanelClient {
|
|
4
4
|
createTrackingFunction() {
|
|
5
5
|
return () => Promise.resolve();
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
setGlobalEventProperty() {}
|
|
9
|
+
setGlobalEventProperties() {}
|
|
7
10
|
}
|
package/src/js/index.ts
CHANGED
|
@@ -3,6 +3,6 @@ export type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, Mi
|
|
|
3
3
|
export { createTrackingFunction } from "./createTrackingFunction.ts";
|
|
4
4
|
export type { MixpanelEnvironment } from "./env.ts";
|
|
5
5
|
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
6
|
-
export { MixpanelClient,
|
|
6
|
+
export type { MixpanelClient, MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
7
7
|
export { NoopMixpanelClient } from "./NoopMixpanelClient.ts";
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { HasExecutedGuard, type LogRocketInstrumentationPartialClient, type Tele
|
|
|
2
2
|
import { createCompositeLogger, type Logger, type RootLogger } from "@workleap/logging";
|
|
3
3
|
import { setMixpanelContext } from "./context.ts";
|
|
4
4
|
import { getTrackingEndpoint, type MixpanelEnvironment } from "./env.ts";
|
|
5
|
-
import { MixpanelClient, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
5
|
+
import { type MixpanelClient, MixpanelClientImpl, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
6
6
|
import { getTelemetryProperties, OtherProperties } from "./properties.ts";
|
|
7
7
|
|
|
8
8
|
// DEPRECATED: Grace period ends on January 1th 2026.
|
|
@@ -130,7 +130,10 @@ export class MixpanelInitializer {
|
|
|
130
130
|
|
|
131
131
|
logger.information("[mixpanel] Mixpanel is initialized.");
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
const client = new MixpanelClientImpl(productId, endpoint, this.#globalEventProperties, logger);
|
|
134
|
+
|
|
135
|
+
// The cast is to normalize the inferred return type to the "LogRocketInstrumentationClient" type.
|
|
136
|
+
return client as MixpanelClient;
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { MixpanelPartialClient } from "@workleap-telemetry/core";
|
|
2
1
|
import { createContext, type PropsWithChildren, useContext } from "react";
|
|
2
|
+
import type { MixpanelClient } from "../js/MixpanelClient.ts";
|
|
3
3
|
|
|
4
|
-
export const MixpanelContext = createContext<
|
|
4
|
+
export const MixpanelContext = createContext<MixpanelClient | undefined>(undefined);
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
8
8
|
*/
|
|
9
9
|
export interface MixpanelProviderProps extends PropsWithChildren {
|
|
10
|
-
client:
|
|
10
|
+
client: MixpanelClient;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -26,14 +26,28 @@ export function MixpanelProvider(props: MixpanelProviderProps) {
|
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export interface UseMixpanelClientOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Whether or not an exception should be thrown if the client hasn't been provided.
|
|
32
|
+
*/
|
|
33
|
+
dontThrowOnUndefined?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useMixpanelClient(options?: { dontThrowOnUndefined?: false }): MixpanelClient;
|
|
37
|
+
export function useMixpanelClient(options: { dontThrowOnUndefined: true }): MixpanelClient | undefined;
|
|
38
|
+
|
|
29
39
|
/**
|
|
30
40
|
* Retrieve the Mixpanel client.
|
|
31
41
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
32
42
|
*/
|
|
33
|
-
export function useMixpanelClient() {
|
|
43
|
+
export function useMixpanelClient(options: UseMixpanelClientOptions = {}) {
|
|
44
|
+
const {
|
|
45
|
+
dontThrowOnUndefined = false
|
|
46
|
+
} = options;
|
|
47
|
+
|
|
34
48
|
const client = useContext(MixpanelContext);
|
|
35
49
|
|
|
36
|
-
if (!client) {
|
|
50
|
+
if (!client && !dontThrowOnUndefined) {
|
|
37
51
|
throw new Error("[mixpanel] The useMixpanelClient function is called before a MixpanelClient instance has been provided.");
|
|
38
52
|
}
|
|
39
53
|
|
package/src/react/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "../js/index.ts";
|
|
2
|
-
export { MixpanelProvider, useMixpanelClient } from "./MixpanelContext.tsx";
|
|
2
|
+
export { MixpanelProvider, useMixpanelClient, type UseMixpanelClientOptions } from "./MixpanelContext.tsx";
|
|
3
3
|
export { useTrackingFunction, type UseTrackingFunctionOptions } from "./useTrackingFunction.ts";
|
|
4
4
|
|