@workleap/mixpanel 2.0.0 → 2.0.1
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/context.d.ts +10 -0
- package/dist/js/context.js +25 -0
- package/dist/js/context.js.map +1 -0
- package/dist/js/createTrackingFunction.d.ts +35 -0
- package/dist/js/createTrackingFunction.js +49 -0
- package/dist/js/createTrackingFunction.js.map +1 -0
- package/dist/js/index.d.ts +3 -3
- package/dist/js/index.js +7 -3
- package/dist/js/index.js.map +1 -1
- package/dist/js/initializeMixpanel.d.ts +1 -30
- package/dist/js/initializeMixpanel.js +20 -46
- package/dist/js/initializeMixpanel.js.map +1 -1
- package/dist/js/properties.d.ts +18 -6
- package/dist/js/properties.js +32 -6
- package/dist/js/properties.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +3 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/useTrackingFunction.d.ts +3 -0
- package/dist/react/useTrackingFunction.js +24 -0
- package/dist/react/useTrackingFunction.js.map +1 -0
- package/package.json +1 -1
- package/src/js/context.ts +34 -0
- package/src/js/createTrackingFunction.ts +86 -0
- package/src/js/index.ts +3 -3
- package/src/js/initializeMixpanel.ts +19 -82
- package/src/js/properties.ts +46 -8
- package/src/react/index.ts +1 -1
- package/src/react/useTrackingFunction.ts +14 -0
- package/dist/js/getMixpanelTrackingFunction.d.ts +0 -14
- package/dist/js/getMixpanelTrackingFunction.js +0 -21
- package/dist/js/getMixpanelTrackingFunction.js.map +0 -1
- package/dist/react/useMixpanelTracking.d.ts +0 -11
- package/dist/react/useMixpanelTracking.js +0 -17
- package/dist/react/useMixpanelTracking.js.map +0 -1
- package/src/js/getMixpanelTrackingFunction.ts +0 -31
- package/src/react/useMixpanelTracking.ts +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @workleap/mixpanel
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#36](https://github.com/workleap/wl-telemetry/pull/36) [`85f432b`](https://github.com/workleap/wl-telemetry/commit/85f432bb1c45433d24a765da7249fef4abb949d4) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Minor fixes to the API.
|
|
8
|
+
|
|
3
9
|
## 2.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SuperProperties } from "./properties.ts";
|
|
2
|
+
export declare const ContextVariableName = "__WLP_MIXPANEL_CONTEXT__";
|
|
3
|
+
export interface MixpanelContext {
|
|
4
|
+
productId: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
superProperties: SuperProperties;
|
|
7
|
+
verbose: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function setMixpanelContext(context: MixpanelContext): void;
|
|
10
|
+
export declare function getMixpanelContext(): MixpanelContext;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
;// CONCATENATED MODULE: ./src/js/context.ts
|
|
3
|
+
const ContextVariableName = "__WLP_MIXPANEL_CONTEXT__";
|
|
4
|
+
function setMixpanelContext(context) {
|
|
5
|
+
// Will be used by the "track" function.
|
|
6
|
+
// It's important to share the context with a global DOM object rather than
|
|
7
|
+
// a singleton because projects like the platform widgets will use a distinct instance
|
|
8
|
+
// of this package than the host application.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
globalThis[ContextVariableName] = context;
|
|
12
|
+
}
|
|
13
|
+
function getMixpanelContext() {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const context = globalThis[ContextVariableName];
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error("[mixpanel] The Mixpanel context is not available. Did you initialize Mixpanel with the \"initializeMixpanel\" function?");
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { ContextVariableName, getMixpanelContext, setMixpanelContext };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/context.js","sources":["webpack://@workleap/mixpanel/./src/js/context.ts"],"sourcesContent":["import type { SuperProperties } from \"./properties.ts\";\n\nexport const ContextVariableName = \"__WLP_MIXPANEL_CONTEXT__\";\n\nexport interface MixpanelContext {\n productId: string;\n endpoint: string;\n superProperties: SuperProperties;\n verbose: boolean;\n}\n\nexport function setMixpanelContext(context: MixpanelContext) {\n // Will be used by the \"track\" function.\n // It's important to share the context with a global DOM object rather than\n // a singleton because projects like the platform widgets will use a distinct instance\n // of this package than the host application.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[ContextVariableName] = context;\n}\n\nexport function getMixpanelContext() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const context = globalThis[ContextVariableName] as MixpanelContext;\n\n if (!context) {\n throw new Error(\"[mixpanel] The Mixpanel context is not available. Did you initialize Mixpanel with the \\\"initializeMixpanel\\\" function?\");\n }\n\n return context;\n}\n\n\n"],"names":["ContextVariableName","setMixpanelContext","context","globalThis","getMixpanelContext","Error"],"mappings":";;AAEO,MAAMA,sBAAsB,2BAA2B;AASvD,SAASC,mBAAmBC,OAAwB;IACvD,wCAAwC;IACxC,2EAA2E;IAC3E,sFAAsF;IACtF,6CAA6C;IAC7C,6DAA6D;IAC7D,aAAa;IACbC,UAAU,CAACH,oBAAoB,GAAGE;AACtC;AAEO,SAASE;IACZ,6DAA6D;IAC7D,aAAa;IACb,MAAMF,UAAUC,UAAU,CAACH,oBAAoB;IAE/C,IAAI,CAACE,SAAS;QACV,MAAM,IAAIG,MAAM;IACpB;IAEA,OAAOH;AACX"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type MixpanelEventProperties } from "./properties.ts";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateTrackingFunctionOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The product identifier of the target product.
|
|
8
|
+
*/
|
|
9
|
+
targetProductId?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
13
|
+
*/
|
|
14
|
+
export interface TrackingFunctionOptions {
|
|
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
|
+
* A function that sends tracking events to the tracking API.
|
|
29
|
+
* @param eventName The name of the event to track.
|
|
30
|
+
* @param properties The properties to send with the event.
|
|
31
|
+
* @param options Options for tracking the event.
|
|
32
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
33
|
+
*/
|
|
34
|
+
export type TrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: TrackingFunctionOptions) => Promise<void>;
|
|
35
|
+
export declare function createTrackingFunction(options?: CreateTrackingFunctionOptions): TrackingFunction;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getMixpanelContext } from "./context.js";
|
|
2
|
+
import { getBaseProperties } from "./properties.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "./context.js"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "./properties.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/js/createTrackingFunction.ts
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function createTrackingFunction(options = {}) {
|
|
12
|
+
const { targetProductId } = options;
|
|
13
|
+
const { productId, endpoint, superProperties } = getMixpanelContext();
|
|
14
|
+
const trackFunction = async (eventName, properties, _options = {})=>{
|
|
15
|
+
try {
|
|
16
|
+
const { keepAlive = false } = _options;
|
|
17
|
+
const baseProperties = getBaseProperties();
|
|
18
|
+
const allProperties = {
|
|
19
|
+
...baseProperties,
|
|
20
|
+
...Object.fromEntries(superProperties),
|
|
21
|
+
...properties
|
|
22
|
+
};
|
|
23
|
+
await fetch(endpoint, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
credentials: "include",
|
|
26
|
+
keepalive: keepAlive,
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
eventName,
|
|
32
|
+
productIdentifier: productId,
|
|
33
|
+
// Not sure why, but it seems important to send "null" if not target product identifier
|
|
34
|
+
// are provided.
|
|
35
|
+
targetProductIdentifier: targetProductId ?? null,
|
|
36
|
+
properties: allProperties
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Do nothing...
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return trackFunction;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { createTrackingFunction };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=createTrackingFunction.js.map
|
|
@@ -0,0 +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 // 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;QACzB,gBAAgB;QAChB;IACJ;IAEA,OAAOV;AACX"}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export { createTrackingFunction, type CreateTrackingFunctionOptions, type TrackingFunction, type TrackingFunctionOptions } from "./createTrackingFunction.ts";
|
|
1
2
|
export type { Environment } from "./env.ts";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { MixpanelTrackEventProperties } from "./properties.ts";
|
|
3
|
+
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
4
|
+
export { setSuperProperties, setSuperProperty, type MixpanelEventProperties } from "./properties.ts";
|
package/dist/js/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTrackingFunction } from "./createTrackingFunction.js";
|
|
2
2
|
import { initializeMixpanel } from "./initializeMixpanel.js";
|
|
3
|
+
import { setSuperProperties, setSuperProperty } from "./properties.js";
|
|
3
4
|
|
|
4
|
-
;// CONCATENATED MODULE: external "./
|
|
5
|
+
;// CONCATENATED MODULE: external "./createTrackingFunction.js"
|
|
5
6
|
|
|
6
7
|
;// CONCATENATED MODULE: external "./initializeMixpanel.js"
|
|
7
8
|
|
|
9
|
+
;// CONCATENATED MODULE: external "./properties.js"
|
|
10
|
+
|
|
8
11
|
;// CONCATENATED MODULE: ./src/js/index.ts
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
export { createTrackingFunction, initializeMixpanel, setSuperProperties, setSuperProperty };
|
|
13
17
|
|
|
14
18
|
//# 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 type
|
|
1
|
+
{"version":3,"file":"js/index.js","sources":["webpack://@workleap/mixpanel/./src/js/index.ts"],"sourcesContent":["export { createTrackingFunction, type CreateTrackingFunctionOptions, type TrackingFunction, type TrackingFunctionOptions } from \"./createTrackingFunction.ts\";\nexport type { Environment } from \"./env.ts\";\nexport { initializeMixpanel, type InitializeMixpanelOptions } from \"./initializeMixpanel.ts\";\nexport { setSuperProperties, setSuperProperty, type MixpanelEventProperties } from \"./properties.ts\";\n\n"],"names":["createTrackingFunction","initializeMixpanel","setSuperProperties","setSuperProperty"],"mappings":";;;;;;;;;;;AAA8J;AAEjE;AACQ"}
|
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
import { type Environment } from "./env.ts";
|
|
2
|
-
import { type MixpanelTrackEventProperties } from "./properties.ts";
|
|
3
|
-
/**
|
|
4
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
5
|
-
*/
|
|
6
|
-
export interface MixpanelTrackingOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The product identifier of the target product.
|
|
9
|
-
*/
|
|
10
|
-
targetProductId?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Whether to keep the connection alive for the tracking request.
|
|
13
|
-
* It is mostly used for tracking links where the user might navigate away before the request is completed.
|
|
14
|
-
*
|
|
15
|
-
* Caution! The body size for keepalive requests is limited to 64 kibibytes.
|
|
16
|
-
*
|
|
17
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
|
|
18
|
-
*
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
keepAlive?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A function that sends tracking events to the tracking API.
|
|
25
|
-
* @param eventName The name of the event to track.
|
|
26
|
-
* @param properties The properties to send with the event.
|
|
27
|
-
* @param options Options for tracking the event.
|
|
28
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
29
|
-
*/
|
|
30
|
-
export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelTrackEventProperties, options?: MixpanelTrackingOptions) => Promise<void>;
|
|
31
2
|
/**
|
|
32
3
|
* @see https://workleap.github.io/wl-telemetry
|
|
33
4
|
*/
|
|
@@ -43,4 +14,4 @@ export declare function __resetInitializationGuard(): void;
|
|
|
43
14
|
* @returns A function that sends tracking events to the tracking API.
|
|
44
15
|
* @see https://workleap.github.io/wl-telemetry
|
|
45
16
|
*/
|
|
46
|
-
export declare function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options?: InitializeMixpanelOptions):
|
|
17
|
+
export declare function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options?: InitializeMixpanelOptions): void;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
import { setMixpanelContext } from "./context.js";
|
|
2
3
|
import { getTrackingEndpoint } from "./env.js";
|
|
3
|
-
import { TrackingFunctionName } from "./getMixpanelTrackingFunction.js";
|
|
4
4
|
import { HasExecutedGuard } from "./HasExecutedGuard.js";
|
|
5
|
-
import {
|
|
5
|
+
import { OtherProperties, getSuperProperties, getTelemetryProperties, setSuperProperties, setSuperProperty } from "./properties.js";
|
|
6
6
|
|
|
7
7
|
;// CONCATENATED MODULE: external "@workleap/telemetry"
|
|
8
8
|
|
|
9
|
-
;// CONCATENATED MODULE: external "./
|
|
9
|
+
;// CONCATENATED MODULE: external "./context.js"
|
|
10
10
|
|
|
11
|
-
;// CONCATENATED MODULE: external "./
|
|
11
|
+
;// CONCATENATED MODULE: external "./env.js"
|
|
12
12
|
|
|
13
13
|
;// CONCATENATED MODULE: external "./HasExecutedGuard.js"
|
|
14
14
|
|
|
@@ -20,7 +20,7 @@ import { TelemetryProperties, getBaseProperties } from "./properties.js";
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
function registerLogRocketSessionUrlListener(
|
|
23
|
+
function registerLogRocketSessionUrlListener(verbose = false) {
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
25
|
// @ts-ignore
|
|
26
26
|
if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
|
|
@@ -31,7 +31,7 @@ function registerLogRocketSessionUrlListener(superProperties, verbose = false) {
|
|
|
31
31
|
if (verbose) {
|
|
32
32
|
console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);
|
|
35
35
|
});
|
|
36
36
|
} else if (verbose) {
|
|
37
37
|
console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
|
|
@@ -50,61 +50,35 @@ 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 } = options;
|
|
53
|
+
const { verbose = false } = options;
|
|
54
54
|
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
55
|
-
|
|
56
|
-
const superProperties = new Map();
|
|
57
|
-
const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
55
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
58
56
|
const telemetryContext = getTelemetryContext({
|
|
59
57
|
verbose
|
|
60
58
|
});
|
|
61
|
-
|
|
62
|
-
superProperties.set(TelemetryProperties.DeviceId, telemetryContext.deviceId);
|
|
59
|
+
setSuperProperties(getTelemetryProperties(telemetryContext));
|
|
63
60
|
const bootstrappingStore = getBootstrappingStore();
|
|
64
61
|
// If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store
|
|
65
62
|
// and register the listener once a notification is received that LogRocket is registered.
|
|
66
63
|
if (bootstrappingStore.state.isLogRocketReady) {
|
|
67
|
-
registerLogRocketSessionUrlListener(
|
|
64
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
68
65
|
} else {
|
|
69
66
|
bootstrappingStore.subscribe((action, store, unsubscribe)=>{
|
|
70
67
|
if (store.state.isLogRocketReady) {
|
|
71
68
|
unsubscribe();
|
|
72
|
-
registerLogRocketSessionUrlListener(
|
|
69
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
73
70
|
}
|
|
74
71
|
});
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await fetch(fullUrl, {
|
|
86
|
-
method: "POST",
|
|
87
|
-
credentials: "include",
|
|
88
|
-
keepalive: keepAlive,
|
|
89
|
-
headers: {
|
|
90
|
-
"Content-Type": "application/json"
|
|
91
|
-
},
|
|
92
|
-
body: JSON.stringify({
|
|
93
|
-
eventName,
|
|
94
|
-
productIdentifier: productId,
|
|
95
|
-
targetProductIdentifier: targetProductId,
|
|
96
|
-
properties: allProperties
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
-
} catch (error) {
|
|
101
|
-
// Do nothing...
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
globalThis[TrackingFunctionName] = trackFunction;
|
|
107
|
-
return trackFunction;
|
|
73
|
+
setMixpanelContext({
|
|
74
|
+
productId,
|
|
75
|
+
endpoint,
|
|
76
|
+
superProperties: getSuperProperties(),
|
|
77
|
+
verbose
|
|
78
|
+
});
|
|
79
|
+
if (verbose) {
|
|
80
|
+
console.log("[mixpanel] Mixpanel is initialized.");
|
|
81
|
+
}
|
|
108
82
|
}
|
|
109
83
|
|
|
110
84
|
export { __resetInitializationGuard, initializeMixpanel };
|
|
@@ -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 {
|
|
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;AAQpI,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,EAClB,GAAGS;IAEJL,oBAAoB,KAAK,CAAC;IAE1B,MAAMM,WAAWlB,mBAAmBA,CAACgB;IACrC,MAAMG,mBAAmBrB,mBAAmBA,CAAC;QAAEU;IAAQ;IAEvDH,kBAAkBA,CAACF,sBAAsBA,CAACgB;IAE1C,MAAMC,qBAAqBvB,qBAAqBA;IAEhD,4GAA4G;IAC5G,0FAA0F;IAC1F,IAAIuB,mBAAmB,KAAK,CAAC,gBAAgB,EAAE;QAC3Cb,oCAAoCC;IACxC,OAAO;QACHY,mBAAmB,SAAS,CAAC,CAACC,QAAQC,OAAOC;YACzC,IAAID,MAAM,KAAK,CAAC,gBAAgB,EAAE;gBAC9BC;gBACAhB,oCAAoCC;YACxC;QACJ;IACJ;IAEAT,kBAAkBA,CAAC;QACfgB;QACAG;QACA,iBAAiBhB,kBAAkBA;QACnCM;IACJ;IAEA,IAAIA,SAAS;QACTG,QAAQ,GAAG,CAAC;IAChB;AACJ"}
|
package/dist/js/properties.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
export type MixpanelEventProperties = Record<string, unknown>;
|
|
2
3
|
export declare const BaseProperties: {
|
|
3
4
|
readonly Browser: "$browser";
|
|
4
5
|
readonly BrowserVersion: "$browser_version";
|
|
@@ -11,11 +12,6 @@ export declare const BaseProperties: {
|
|
|
11
12
|
readonly ScreenHeight: "$screen_height";
|
|
12
13
|
readonly ScreenWidth: "$screen_width";
|
|
13
14
|
};
|
|
14
|
-
export declare const TelemetryProperties: {
|
|
15
|
-
readonly DeviceId: "Device Id";
|
|
16
|
-
readonly LogRocketSessionUrl: "LogRocket Session Url";
|
|
17
|
-
readonly TelemetryId: "Telemetry Id";
|
|
18
|
-
};
|
|
19
15
|
export declare function getBaseProperties(): {
|
|
20
16
|
$os: string;
|
|
21
17
|
$browser: string;
|
|
@@ -28,3 +24,19 @@ export declare function getBaseProperties(): {
|
|
|
28
24
|
$screen_width: number;
|
|
29
25
|
"Is Mobile": boolean;
|
|
30
26
|
};
|
|
27
|
+
export declare const TelemetryProperties: {
|
|
28
|
+
readonly DeviceId: "Device Id";
|
|
29
|
+
readonly TelemetryId: "Telemetry Id";
|
|
30
|
+
};
|
|
31
|
+
export declare function getTelemetryProperties(context: TelemetryContext): {
|
|
32
|
+
"Telemetry Id": string;
|
|
33
|
+
"Device Id": string;
|
|
34
|
+
};
|
|
35
|
+
export declare const OtherProperties: {
|
|
36
|
+
LogRocketSessionUrl: string;
|
|
37
|
+
};
|
|
38
|
+
export type SuperProperties = Map<string, unknown>;
|
|
39
|
+
export declare function setSuperProperty(key: string, value: unknown): void;
|
|
40
|
+
export declare function setSuperProperties(values: Record<string, unknown>): void;
|
|
41
|
+
export declare function getSuperProperties(): SuperProperties;
|
|
42
|
+
export declare function __clearSuperProperties(): void;
|
package/dist/js/properties.js
CHANGED
|
@@ -16,11 +16,6 @@ const BaseProperties = {
|
|
|
16
16
|
ScreenHeight: "$screen_height",
|
|
17
17
|
ScreenWidth: "$screen_width"
|
|
18
18
|
};
|
|
19
|
-
const TelemetryProperties = {
|
|
20
|
-
DeviceId: "Device Id",
|
|
21
|
-
LogRocketSessionUrl: "LogRocket Session Url",
|
|
22
|
-
TelemetryId: "Telemetry Id"
|
|
23
|
-
};
|
|
24
19
|
function getBaseProperties() {
|
|
25
20
|
const userAgent = navigator.userAgent;
|
|
26
21
|
const device = deviceType(userAgent);
|
|
@@ -37,7 +32,38 @@ function getBaseProperties() {
|
|
|
37
32
|
[BaseProperties.IsMobile]: device.length > 0
|
|
38
33
|
};
|
|
39
34
|
}
|
|
35
|
+
const TelemetryProperties = {
|
|
36
|
+
DeviceId: "Device Id",
|
|
37
|
+
TelemetryId: "Telemetry Id"
|
|
38
|
+
};
|
|
39
|
+
function getTelemetryProperties(context) {
|
|
40
|
+
return {
|
|
41
|
+
[TelemetryProperties.TelemetryId]: context.telemetryId,
|
|
42
|
+
[TelemetryProperties.DeviceId]: context.deviceId
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const OtherProperties = {
|
|
46
|
+
LogRocketSessionUrl: "LogRocket Session Url"
|
|
47
|
+
};
|
|
48
|
+
// Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.
|
|
49
|
+
const superProperties = new Map();
|
|
50
|
+
function setSuperProperty(key, value) {
|
|
51
|
+
superProperties.set(key, value);
|
|
52
|
+
}
|
|
53
|
+
function setSuperProperties(values) {
|
|
54
|
+
Object.keys(values).forEach((x)=>{
|
|
55
|
+
superProperties.set(x, values[x]);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Must always return the actual reference to the super properties, not a copy
|
|
59
|
+
// because it will breaks the global context.
|
|
60
|
+
function getSuperProperties() {
|
|
61
|
+
return superProperties;
|
|
62
|
+
}
|
|
63
|
+
function __clearSuperProperties() {
|
|
64
|
+
superProperties.clear();
|
|
65
|
+
}
|
|
40
66
|
|
|
41
|
-
export { BaseProperties, TelemetryProperties, getBaseProperties };
|
|
67
|
+
export { BaseProperties, OtherProperties, TelemetryProperties, __clearSuperProperties, getBaseProperties, getSuperProperties, getTelemetryProperties, setSuperProperties, setSuperProperty };
|
|
42
68
|
|
|
43
69
|
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/properties.js","sources":["webpack://@workleap/mixpanel/./src/js/properties.ts"],"sourcesContent":["\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport type
|
|
1
|
+
{"version":3,"file":"js/properties.js","sources":["webpack://@workleap/mixpanel/./src/js/properties.ts"],"sourcesContent":["\nimport type { TelemetryContext } from \"@workleap/telemetry\";\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport type MixpanelEventProperties = Record<string, unknown>;\n\nexport const BaseProperties = {\n Browser: \"$browser\",\n BrowserVersion: \"$browser_version\",\n CurrentUrl: \"$current_url\",\n Device: \"$device\",\n IsMobile: \"Is Mobile\",\n Os: \"$os\",\n Referrer: \"$referrer\",\n ReferringDomain: \"$referring_domain\",\n ScreenHeight: \"$screen_height\",\n ScreenWidth: \"$screen_width\"\n} as const;\n\nexport function getBaseProperties() {\n const userAgent = navigator.userAgent;\n const device = deviceType(userAgent);\n\n return {\n [BaseProperties.Os]: osName(userAgent),\n [BaseProperties.Browser]: browserName(userAgent, navigator.vendor),\n [BaseProperties.Referrer]: document.referrer,\n [BaseProperties.ReferringDomain]: referringDomain(document.referrer),\n [BaseProperties.Device]: device,\n [BaseProperties.CurrentUrl]: window.location.href,\n [BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),\n [BaseProperties.ScreenHeight]: window.screen.height,\n [BaseProperties.ScreenWidth]: window.screen.width,\n [BaseProperties.IsMobile]: device.length > 0\n } satisfies MixpanelEventProperties;\n}\n\nexport const TelemetryProperties = {\n DeviceId: \"Device Id\",\n TelemetryId: \"Telemetry Id\"\n} as const;\n\nexport function getTelemetryProperties(context: TelemetryContext) {\n return {\n [TelemetryProperties.TelemetryId]: context.telemetryId,\n [TelemetryProperties.DeviceId]: context.deviceId\n } satisfies MixpanelEventProperties;\n}\n\nexport const OtherProperties = {\n LogRocketSessionUrl: \"LogRocket Session Url\"\n};\n\n//////////////////////\n\nexport type SuperProperties = Map<string, unknown>;\n\n// Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.\nconst superProperties: SuperProperties = new Map<string, unknown>();\n\nexport function setSuperProperty(key: string, value: unknown) {\n superProperties.set(key, value);\n}\n\nexport function setSuperProperties(values: Record<string, unknown>) {\n Object.keys(values).forEach(x => {\n superProperties.set(x, values[x]);\n });\n}\n\n// Must always return the actual reference to the super properties, not a copy\n// because it will breaks the global context.\nexport function getSuperProperties() {\n return superProperties;\n}\n\nexport function __clearSuperProperties() {\n superProperties.clear();\n}\n"],"names":["browserName","browserVersion","deviceType","osName","referringDomain","BaseProperties","getBaseProperties","userAgent","navigator","device","document","window","TelemetryProperties","getTelemetryProperties","context","OtherProperties","superProperties","Map","setSuperProperty","key","value","setSuperProperties","values","Object","x","getSuperProperties","__clearSuperProperties"],"mappings":";;;;;AAE8F;AAIvF,MAAMK,iBAAiB;IAC1B,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,UAAU;IACV,iBAAiB;IACjB,cAAc;IACd,aAAa;AACjB,EAAW;AAEJ,SAASC;IACZ,MAAMC,YAAYC,UAAU,SAAS;IACrC,MAAMC,SAASP,UAAUA,CAACK;IAE1B,OAAO;QACH,CAACF,eAAe,EAAE,CAAC,EAAEF,MAAMA,CAACI;QAC5B,CAACF,eAAe,OAAO,CAAC,EAAEL,WAAWA,CAACO,WAAWC,UAAU,MAAM;QACjE,CAACH,eAAe,QAAQ,CAAC,EAAEK,SAAS,QAAQ;QAC5C,CAACL,eAAe,eAAe,CAAC,EAAED,eAAeA,CAACM,SAAS,QAAQ;QACnE,CAACL,eAAe,MAAM,CAAC,EAAEI;QACzB,CAACJ,eAAe,UAAU,CAAC,EAAEM,OAAO,QAAQ,CAAC,IAAI;QACjD,CAACN,eAAe,cAAc,CAAC,EAAEJ,cAAcA,CAACM,WAAWC,UAAU,MAAM;QAC3E,CAACH,eAAe,YAAY,CAAC,EAAEM,OAAO,MAAM,CAAC,MAAM;QACnD,CAACN,eAAe,WAAW,CAAC,EAAEM,OAAO,MAAM,CAAC,KAAK;QACjD,CAACN,eAAe,QAAQ,CAAC,EAAEI,OAAO,MAAM,GAAG;IAC/C;AACJ;AAEO,MAAMG,sBAAsB;IAC/B,UAAU;IACV,aAAa;AACjB,EAAW;AAEJ,SAASC,uBAAuBC,OAAyB;IAC5D,OAAO;QACH,CAACF,oBAAoB,WAAW,CAAC,EAAEE,QAAQ,WAAW;QACtD,CAACF,oBAAoB,QAAQ,CAAC,EAAEE,QAAQ,QAAQ;IACpD;AACJ;AAEO,MAAMC,kBAAkB;IAC3B,qBAAqB;AACzB,EAAE;AAMF,2GAA2G;AAC3G,MAAMC,kBAAmC,IAAIC;AAEtC,SAASC,iBAAiBC,GAAW,EAAEC,KAAc;IACxDJ,gBAAgB,GAAG,CAACG,KAAKC;AAC7B;AAEO,SAASC,mBAAmBC,MAA+B;IAC9DC,OAAO,IAAI,CAACD,QAAQ,OAAO,CAACE,CAAAA;QACxBR,gBAAgB,GAAG,CAACQ,GAAGF,MAAM,CAACE,EAAE;IACpC;AACJ;AAEA,8EAA8E;AAC9E,6CAA6C;AACtC,SAASC;IACZ,OAAOT;AACX;AAEO,SAASU;IACZV,gBAAgB,KAAK;AACzB"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useTrackingFunction, type UseTrackingFunctionOptions } from "./useTrackingFunction.ts";
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useTrackingFunction } from "./useTrackingFunction.js";
|
|
2
2
|
|
|
3
|
-
;// CONCATENATED MODULE: external "./
|
|
3
|
+
;// CONCATENATED MODULE: external "./useTrackingFunction.js"
|
|
4
4
|
|
|
5
5
|
;// CONCATENATED MODULE: ./src/react/index.ts
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export { useTrackingFunction };
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
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 {
|
|
1
|
+
{"version":3,"file":"react/index.js","sources":["webpack://@workleap/mixpanel/./src/react/index.ts"],"sourcesContent":["export { useTrackingFunction, type UseTrackingFunctionOptions } from \"./useTrackingFunction.ts\";\n\n"],"names":["useTrackingFunction"],"mappings":";;;;;AAAgG"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CreateTrackingFunctionOptions } from "../js/createTrackingFunction.ts";
|
|
2
|
+
export type UseTrackingFunctionOptions = CreateTrackingFunctionOptions;
|
|
3
|
+
export declare function useTrackingFunction(options?: UseTrackingFunctionOptions): import("../js/createTrackingFunction.ts").TrackingFunction;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { createTrackingFunction } from "../js/createTrackingFunction.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "react"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "../js/createTrackingFunction.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/react/useTrackingFunction.ts
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function useTrackingFunction(options = {}) {
|
|
12
|
+
const { targetProductId } = options;
|
|
13
|
+
return useMemo(()=>{
|
|
14
|
+
return createTrackingFunction({
|
|
15
|
+
targetProductId
|
|
16
|
+
});
|
|
17
|
+
}, [
|
|
18
|
+
targetProductId
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { useTrackingFunction };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=useTrackingFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react/useTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/react/useTrackingFunction.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { createTrackingFunction, type CreateTrackingFunctionOptions } from \"../js/createTrackingFunction.ts\";\n\nexport type UseTrackingFunctionOptions = CreateTrackingFunctionOptions;\n\nexport function useTrackingFunction(options: UseTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n return useMemo(() => {\n return createTrackingFunction({ targetProductId });\n }, [targetProductId]);\n}\n"],"names":["useMemo","createTrackingFunction","useTrackingFunction","options","targetProductId"],"mappings":";;;;;;;;AAAgC;AAC6E;AAItG,SAASE,oBAAoBC,UAAsC,CAAC,CAAC;IACxE,MAAM,EACFC,eAAe,EAClB,GAAGD;IAEJ,OAAOH,OAAOA,CAAC;QACX,OAAOC,sBAAsBA,CAAC;YAAEG;QAAgB;IACpD,GAAG;QAACA;KAAgB;AACxB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SuperProperties } from "./properties.ts";
|
|
2
|
+
|
|
3
|
+
export const ContextVariableName = "__WLP_MIXPANEL_CONTEXT__";
|
|
4
|
+
|
|
5
|
+
export interface MixpanelContext {
|
|
6
|
+
productId: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
superProperties: SuperProperties;
|
|
9
|
+
verbose: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function setMixpanelContext(context: MixpanelContext) {
|
|
13
|
+
// Will be used by the "track" function.
|
|
14
|
+
// It's important to share the context with a global DOM object rather than
|
|
15
|
+
// a singleton because projects like the platform widgets will use a distinct instance
|
|
16
|
+
// of this package than the host application.
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
globalThis[ContextVariableName] = context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getMixpanelContext() {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const context = globalThis[ContextVariableName] as MixpanelContext;
|
|
26
|
+
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error("[mixpanel] The Mixpanel context is not available. Did you initialize Mixpanel with the \"initializeMixpanel\" function?");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return context;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { getMixpanelContext } from "./context.ts";
|
|
2
|
+
import { getBaseProperties, type MixpanelEventProperties } from "./properties.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
6
|
+
*/
|
|
7
|
+
export interface CreateTrackingFunctionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The product identifier of the target product.
|
|
10
|
+
*/
|
|
11
|
+
targetProductId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
16
|
+
*/
|
|
17
|
+
export interface TrackingFunctionOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Whether to keep the connection alive for the tracking request.
|
|
20
|
+
* It is mostly used for tracking links where the user might navigate away before the request is completed.
|
|
21
|
+
*
|
|
22
|
+
* Caution! The body size for keepalive requests is limited to 64 kibibytes.
|
|
23
|
+
*
|
|
24
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
keepAlive?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A function that sends tracking events to the tracking API.
|
|
33
|
+
* @param eventName The name of the event to track.
|
|
34
|
+
* @param properties The properties to send with the event.
|
|
35
|
+
* @param options Options for tracking the event.
|
|
36
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
37
|
+
*/
|
|
38
|
+
export type TrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: TrackingFunctionOptions) => Promise<void>;
|
|
39
|
+
|
|
40
|
+
export function createTrackingFunction(options: CreateTrackingFunctionOptions = {}) {
|
|
41
|
+
const {
|
|
42
|
+
targetProductId
|
|
43
|
+
} = options;
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
productId,
|
|
47
|
+
endpoint,
|
|
48
|
+
superProperties
|
|
49
|
+
} = getMixpanelContext();
|
|
50
|
+
|
|
51
|
+
const trackFunction: TrackingFunction = async (eventName, properties, _options = {}) => {
|
|
52
|
+
try {
|
|
53
|
+
const {
|
|
54
|
+
keepAlive = false
|
|
55
|
+
} = _options;
|
|
56
|
+
|
|
57
|
+
const baseProperties = getBaseProperties();
|
|
58
|
+
|
|
59
|
+
const allProperties = {
|
|
60
|
+
...baseProperties,
|
|
61
|
+
...Object.fromEntries(superProperties),
|
|
62
|
+
...properties
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
await fetch(endpoint, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
credentials: "include",
|
|
68
|
+
keepalive: keepAlive,
|
|
69
|
+
headers: { "Content-Type": "application/json" },
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
eventName,
|
|
72
|
+
productIdentifier: productId,
|
|
73
|
+
// Not sure why, but it seems important to send "null" if not target product identifier
|
|
74
|
+
// are provided.
|
|
75
|
+
targetProductIdentifier : targetProductId ?? null,
|
|
76
|
+
properties: allProperties
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
} catch (error: unknown) {
|
|
81
|
+
// Do nothing...
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return trackFunction;
|
|
86
|
+
}
|
package/src/js/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export { createTrackingFunction, type CreateTrackingFunctionOptions, type TrackingFunction, type TrackingFunctionOptions } from "./createTrackingFunction.ts";
|
|
1
2
|
export type { Environment } from "./env.ts";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { MixpanelTrackEventProperties } from "./properties.ts";
|
|
3
|
+
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
4
|
+
export { setSuperProperties, setSuperProperty, type MixpanelEventProperties } from "./properties.ts";
|
|
5
5
|
|
|
@@ -1,38 +1,8 @@
|
|
|
1
1
|
import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
import { setMixpanelContext } from "./context.ts";
|
|
2
3
|
import { getTrackingEndpoint, type Environment } from "./env.ts";
|
|
3
|
-
import { TrackingFunctionName } from "./getMixpanelTrackingFunction.ts";
|
|
4
4
|
import { HasExecutedGuard } from "./HasExecutedGuard.ts";
|
|
5
|
-
import {
|
|
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>;
|
|
5
|
+
import { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from "./properties.ts";
|
|
36
6
|
|
|
37
7
|
/**
|
|
38
8
|
* @see https://workleap.github.io/wl-telemetry
|
|
@@ -40,8 +10,7 @@ export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelT
|
|
|
40
10
|
export interface InitializeMixpanelOptions {
|
|
41
11
|
verbose?: boolean;
|
|
42
12
|
}
|
|
43
|
-
|
|
44
|
-
function registerLogRocketSessionUrlListener(superProperties: Map<string, string>, verbose = false) {
|
|
13
|
+
function registerLogRocketSessionUrlListener(verbose = false) {
|
|
45
14
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
46
15
|
// @ts-ignore
|
|
47
16
|
if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
|
|
@@ -53,7 +22,7 @@ function registerLogRocketSessionUrlListener(superProperties: Map<string, string
|
|
|
53
22
|
console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
|
|
54
23
|
}
|
|
55
24
|
|
|
56
|
-
|
|
25
|
+
setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);
|
|
57
26
|
});
|
|
58
27
|
} else if (verbose) {
|
|
59
28
|
console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
|
|
@@ -75,73 +44,41 @@ export function __resetInitializationGuard() {
|
|
|
75
44
|
* @returns A function that sends tracking events to the tracking API.
|
|
76
45
|
* @see https://workleap.github.io/wl-telemetry
|
|
77
46
|
*/
|
|
78
|
-
export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {})
|
|
47
|
+
export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {
|
|
79
48
|
const {
|
|
80
|
-
verbose
|
|
49
|
+
verbose = false
|
|
81
50
|
} = options;
|
|
82
51
|
|
|
83
52
|
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
84
53
|
|
|
85
|
-
|
|
86
|
-
const superProperties = new Map<string, string>();
|
|
87
|
-
|
|
88
|
-
const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
54
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
89
55
|
const telemetryContext = getTelemetryContext({ verbose });
|
|
90
56
|
|
|
91
|
-
|
|
92
|
-
superProperties.set(TelemetryProperties.DeviceId, telemetryContext.deviceId);
|
|
57
|
+
setSuperProperties(getTelemetryProperties(telemetryContext));
|
|
93
58
|
|
|
94
59
|
const bootstrappingStore = getBootstrappingStore();
|
|
95
60
|
|
|
96
61
|
// If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store
|
|
97
62
|
// and register the listener once a notification is received that LogRocket is registered.
|
|
98
63
|
if (bootstrappingStore.state.isLogRocketReady) {
|
|
99
|
-
registerLogRocketSessionUrlListener(
|
|
64
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
100
65
|
} else {
|
|
101
66
|
bootstrappingStore.subscribe((action, store, unsubscribe) => {
|
|
102
67
|
if (store.state.isLogRocketReady) {
|
|
103
68
|
unsubscribe();
|
|
104
|
-
registerLogRocketSessionUrlListener(
|
|
69
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
105
70
|
}
|
|
106
71
|
});
|
|
107
72
|
}
|
|
108
73
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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;
|
|
74
|
+
setMixpanelContext({
|
|
75
|
+
productId,
|
|
76
|
+
endpoint,
|
|
77
|
+
superProperties: getSuperProperties(),
|
|
78
|
+
verbose
|
|
79
|
+
});
|
|
145
80
|
|
|
146
|
-
|
|
81
|
+
if (verbose) {
|
|
82
|
+
console.log("[mixpanel] Mixpanel is initialized.");
|
|
83
|
+
}
|
|
147
84
|
}
|
package/src/js/properties.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
import type { TelemetryContext } from "@workleap/telemetry";
|
|
2
3
|
import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
|
|
3
4
|
|
|
4
|
-
export type
|
|
5
|
+
export type MixpanelEventProperties = Record<string, unknown>;
|
|
5
6
|
|
|
6
7
|
export const BaseProperties = {
|
|
7
8
|
Browser: "$browser",
|
|
@@ -16,12 +17,6 @@ export const BaseProperties = {
|
|
|
16
17
|
ScreenWidth: "$screen_width"
|
|
17
18
|
} as const;
|
|
18
19
|
|
|
19
|
-
export const TelemetryProperties = {
|
|
20
|
-
DeviceId: "Device Id",
|
|
21
|
-
LogRocketSessionUrl: "LogRocket Session Url",
|
|
22
|
-
TelemetryId: "Telemetry Id"
|
|
23
|
-
} as const;
|
|
24
|
-
|
|
25
20
|
export function getBaseProperties() {
|
|
26
21
|
const userAgent = navigator.userAgent;
|
|
27
22
|
const device = deviceType(userAgent);
|
|
@@ -37,5 +32,48 @@ export function getBaseProperties() {
|
|
|
37
32
|
[BaseProperties.ScreenHeight]: window.screen.height,
|
|
38
33
|
[BaseProperties.ScreenWidth]: window.screen.width,
|
|
39
34
|
[BaseProperties.IsMobile]: device.length > 0
|
|
40
|
-
} satisfies
|
|
35
|
+
} satisfies MixpanelEventProperties;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const TelemetryProperties = {
|
|
39
|
+
DeviceId: "Device Id",
|
|
40
|
+
TelemetryId: "Telemetry Id"
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
export function getTelemetryProperties(context: TelemetryContext) {
|
|
44
|
+
return {
|
|
45
|
+
[TelemetryProperties.TelemetryId]: context.telemetryId,
|
|
46
|
+
[TelemetryProperties.DeviceId]: context.deviceId
|
|
47
|
+
} satisfies MixpanelEventProperties;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const OtherProperties = {
|
|
51
|
+
LogRocketSessionUrl: "LogRocket Session Url"
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//////////////////////
|
|
55
|
+
|
|
56
|
+
export type SuperProperties = Map<string, unknown>;
|
|
57
|
+
|
|
58
|
+
// Equivalent to: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#setting-super-properties.
|
|
59
|
+
const superProperties: SuperProperties = new Map<string, unknown>();
|
|
60
|
+
|
|
61
|
+
export function setSuperProperty(key: string, value: unknown) {
|
|
62
|
+
superProperties.set(key, value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function setSuperProperties(values: Record<string, unknown>) {
|
|
66
|
+
Object.keys(values).forEach(x => {
|
|
67
|
+
superProperties.set(x, values[x]);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Must always return the actual reference to the super properties, not a copy
|
|
72
|
+
// because it will breaks the global context.
|
|
73
|
+
export function getSuperProperties() {
|
|
74
|
+
return superProperties;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function __clearSuperProperties() {
|
|
78
|
+
superProperties.clear();
|
|
41
79
|
}
|
package/src/react/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useTrackingFunction, type UseTrackingFunctionOptions } from "./useTrackingFunction.ts";
|
|
2
2
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { createTrackingFunction, type CreateTrackingFunctionOptions } from "../js/createTrackingFunction.ts";
|
|
3
|
+
|
|
4
|
+
export type UseTrackingFunctionOptions = CreateTrackingFunctionOptions;
|
|
5
|
+
|
|
6
|
+
export function useTrackingFunction(options: UseTrackingFunctionOptions = {}) {
|
|
7
|
+
const {
|
|
8
|
+
targetProductId
|
|
9
|
+
} = options;
|
|
10
|
+
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
return createTrackingFunction({ targetProductId });
|
|
13
|
+
}, [targetProductId]);
|
|
14
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MixpanelTrackingFunction } from "./initializeMixpanel.ts";
|
|
2
|
-
export declare const TrackingFunctionName = "__WLP_MIXPANEL_TRACKING_FUNCTION__";
|
|
3
|
-
/**
|
|
4
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
5
|
-
*/
|
|
6
|
-
export interface GetMixpanelTrackingFunctionOptions {
|
|
7
|
-
throwOnUndefined?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Retrieve the track function.
|
|
11
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
12
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
13
|
-
*/
|
|
14
|
-
export declare function getMixpanelTrackingFunction(options?: GetMixpanelTrackingFunctionOptions): MixpanelTrackingFunction;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
;// CONCATENATED MODULE: ./src/js/getMixpanelTrackingFunction.ts
|
|
3
|
-
const TrackingFunctionName = "__WLP_MIXPANEL_TRACKING_FUNCTION__";
|
|
4
|
-
/**
|
|
5
|
-
* Retrieve the track function.
|
|
6
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
7
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
8
|
-
*/ function getMixpanelTrackingFunction(options = {}) {
|
|
9
|
-
const { throwOnUndefined = true } = options;
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
const trackFunction = globalThis[TrackingFunctionName];
|
|
13
|
-
if (!trackFunction && throwOnUndefined) {
|
|
14
|
-
throw new Error("[mixpanel] The tracking function is undefined. Did you call the \"initializeMixpanel\" function?");
|
|
15
|
-
}
|
|
16
|
-
return trackFunction;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { TrackingFunctionName, getMixpanelTrackingFunction };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=getMixpanelTrackingFunction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"js/getMixpanelTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/getMixpanelTrackingFunction.ts"],"sourcesContent":["import type { MixpanelTrackingFunction } from \"./initializeMixpanel.ts\";\n\nexport const TrackingFunctionName = \"__WLP_MIXPANEL_TRACKING_FUNCTION__\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface GetMixpanelTrackingFunctionOptions {\n throwOnUndefined?: boolean;\n}\n\n/**\n * Retrieve the track function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function getMixpanelTrackingFunction(options: GetMixpanelTrackingFunctionOptions = {}) {\n const {\n throwOnUndefined = true\n } = options;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const trackFunction = globalThis[TrackingFunctionName];\n\n if (!trackFunction && throwOnUndefined) {\n throw new Error(\"[mixpanel] The tracking function is undefined. Did you call the \\\"initializeMixpanel\\\" function?\");\n }\n\n return trackFunction as MixpanelTrackingFunction;\n}\n"],"names":["TrackingFunctionName","getMixpanelTrackingFunction","options","throwOnUndefined","trackFunction","globalThis","Error"],"mappings":";;AAEO,MAAMA,uBAAuB,qCAAqC;AASzE;;;;CAIC,GACM,SAASC,4BAA4BC,UAA8C,CAAC,CAAC;IACxF,MAAM,EACFC,mBAAmB,IAAI,EAC1B,GAAGD;IAEJ,6DAA6D;IAC7D,aAAa;IACb,MAAME,gBAAgBC,UAAU,CAACL,qBAAqB;IAEtD,IAAI,CAACI,iBAAiBD,kBAAkB;QACpC,MAAM,IAAIG,MAAM;IACpB;IAEA,OAAOF;AACX"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type GetMixpanelTrackingFunctionOptions } from "../js/getMixpanelTrackingFunction.ts";
|
|
2
|
-
/**
|
|
3
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
4
|
-
*/
|
|
5
|
-
export type UseMixpanelTrackingOptions = GetMixpanelTrackingFunctionOptions;
|
|
6
|
-
/**
|
|
7
|
-
* Retrieve the track function.
|
|
8
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
9
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
10
|
-
*/
|
|
11
|
-
export declare function useMixpanelTracking(options?: UseMixpanelTrackingOptions): import("../js/initializeMixpanel.ts").MixpanelTrackingFunction;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getMixpanelTrackingFunction } from "../js/getMixpanelTrackingFunction.js";
|
|
2
|
-
|
|
3
|
-
;// CONCATENATED MODULE: external "../js/getMixpanelTrackingFunction.js"
|
|
4
|
-
|
|
5
|
-
;// CONCATENATED MODULE: ./src/react/useMixpanelTracking.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Retrieve the track function.
|
|
9
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
10
|
-
* @see https://workleap.github.io/wl-telemetry
|
|
11
|
-
*/ function useMixpanelTracking(options) {
|
|
12
|
-
return getMixpanelTrackingFunction(options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { useMixpanelTracking };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=useMixpanelTracking.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react/useMixpanelTracking.js","sources":["webpack://@workleap/mixpanel/./src/react/useMixpanelTracking.ts"],"sourcesContent":["import { getMixpanelTrackingFunction, type GetMixpanelTrackingFunctionOptions } from \"../js/getMixpanelTrackingFunction.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport type UseMixpanelTrackingOptions = GetMixpanelTrackingFunctionOptions;\n\n/**\n * Retrieve the track function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function useMixpanelTracking(options?: UseMixpanelTrackingOptions) {\n return getMixpanelTrackingFunction(options);\n}\n"],"names":["getMixpanelTrackingFunction","useMixpanelTracking","options"],"mappings":";;;;;AAA4H;AAO5H;;;;CAIC,GACM,SAASC,oBAAoBC,OAAoC;IACpE,OAAOF,2BAA2BA,CAACE;AACvC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|