@workleap/mixpanel 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/js/MixpanelClient.d.ts +1 -1
- package/dist/js/MixpanelClient.js +2 -0
- package/dist/js/MixpanelClient.js.map +1 -1
- package/dist/js/createTrackingFunction.d.ts +1 -34
- package/dist/js/createTrackingFunction.js.map +1 -1
- package/dist/js/index.d.ts +2 -2
- package/dist/js/index.js.map +1 -1
- package/dist/js/properties.d.ts +0 -1
- package/dist/js/properties.js.map +1 -1
- package/dist/react/useTrackingFunction.d.ts +2 -2
- package/dist/react/useTrackingFunction.js.map +1 -1
- package/package.json +3 -3
- package/src/js/MixpanelClient.ts +3 -1
- package/src/js/createTrackingFunction.ts +2 -37
- package/src/js/index.ts +2 -2
- package/src/js/properties.ts +1 -3
- package/src/react/useTrackingFunction.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @workleap/mixpanel
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#99](https://github.com/workleap/wl-telemetry/pull/99) [`0fc78f2`](https://github.com/workleap/wl-telemetry/commit/0fc78f29c914075ced4d96c916edcb78e8033983) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added a MixpanelPartialClient to the core package.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`0fc78f2`](https://github.com/workleap/wl-telemetry/commit/0fc78f29c914075ced4d96c916edcb78e8033983)]:
|
|
10
|
+
- @workleap/logrocket@2.0.2
|
|
11
|
+
- @workleap-telemetry/core@1.0.2
|
|
12
|
+
|
|
3
13
|
## 3.0.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
1
2
|
import type { Logger } from "@workleap/logging";
|
|
2
|
-
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "./createTrackingFunction.ts";
|
|
3
3
|
export type MixpanelGlobalEventProperties = Map<string, unknown>;
|
|
4
4
|
/**
|
|
5
5
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
@@ -17,6 +17,8 @@ import { getBaseProperties } from "./properties.js";
|
|
|
17
17
|
this.#globalEventProperties = globalEventProperties;
|
|
18
18
|
this.#logger = logger;
|
|
19
19
|
}
|
|
20
|
+
// IMPORTANT: If you update this method, make sure to update the MixpanelPartialClient
|
|
21
|
+
// interface as well in @workleap-telemetry/core.
|
|
20
22
|
/**
|
|
21
23
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
22
24
|
*/ createTrackingFunction(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/MixpanelClient.js","sources":["webpack://@workleap/mixpanel/./src/js/MixpanelClient.ts"],"sourcesContent":["import type {
|
|
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 class 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 /**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\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 /**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\n setGlobalEventProperty(key: string, value: unknown) {\n this.#globalEventProperties.set(key, value);\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-telemetry}\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","MixpanelClient","productId","endpoint","globalEventProperties","logger","options","targetProductId","trackFunction","eventName","properties","_options","keepAlive","baseProperties","allProperties","Object","fetch","JSON","error","key","value","values","x"],"mappings":";;;;;AAEoD;AAIpD;;CAEC,GACM,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;;KAEC,GACD,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;;KAEC,GACD,uBAAuBW,GAAW,EAAEC,KAAc,EAAE;QAChD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACD,KAAKC;IACzC;IAEA;;KAEC,GACD,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,37 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
4
|
-
*/
|
|
5
|
-
export interface CreateMixpanelTrackingFunctionOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The product identifier of the target product.
|
|
8
|
-
*/
|
|
9
|
-
targetProductId?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
13
|
-
*/
|
|
14
|
-
export interface MixpanelTrackingFunctionOptions {
|
|
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 {@link https://workleap.github.io/wl-telemetry}
|
|
33
|
-
*/
|
|
34
|
-
export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: MixpanelTrackingFunctionOptions) => Promise<void>;
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
35
2
|
/**
|
|
36
3
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
37
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/createTrackingFunction.ts"],"sourcesContent":["// DEPRECATED: Grace period ends on January 1th 2026.\n// Must keep this code until the end of the grace period because host applications using version 2.* of\n// this package would get runtime errors from the Platform Widgets CDN otherwise.\n\nimport {
|
|
1
|
+
{"version":3,"file":"js/createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/js/createTrackingFunction.ts"],"sourcesContent":["// DEPRECATED: Grace period ends on January 1th 2026.\n// Must keep this code until the end of the grace period because host applications using version 2.* of\n// this package would get runtime errors from the Platform Widgets CDN otherwise.\n\nimport type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from \"@workleap-telemetry/core\";\nimport { getMixpanelContext } from \"./context.ts\";\nimport { getBaseProperties } from \"./properties.ts\";\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function createTrackingFunction(options: CreateMixpanelTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n const {\n productId,\n endpoint,\n globalEventProperties,\n logger\n } = getMixpanelContext();\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(globalEventProperties),\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 } catch (error: unknown) {\n logger\n .withText(`[mixpanel] An error occurred while sending a tracking event to \"${endpoint}\":`)\n .withError(error as Error)\n .error();\n }\n };\n\n return trackFunction;\n}\n"],"names":["getMixpanelContext","getBaseProperties","createTrackingFunction","options","targetProductId","productId","endpoint","globalEventProperties","logger","trackFunction","eventName","properties","_options","keepAlive","baseProperties","allProperties","Object","fetch","JSON","error"],"mappings":";;;;;;;;AAAA,qDAAqD;AACrD,uGAAuG;AACvG,iFAAiF;AAG/B;AACE;AAEpD;;CAEC,GACM,SAASE,uBAAuBC,UAAiD,CAAC,CAAC;IACtF,MAAM,EACFC,eAAe,EAClB,GAAGD;IAEJ,MAAM,EACFE,SAAS,EACTC,QAAQ,EACRC,qBAAqB,EACrBC,MAAM,EACT,GAAGR,kBAAkBA;IAEtB,MAAMS,gBAA0C,OAAOC,WAAWC,YAAYC,WAAW,CAAC,CAAC;QACvF,IAAI;YACA,MAAM,EACFC,YAAY,KAAK,EACpB,GAAGD;YAEJ,MAAME,iBAAiBb,iBAAiBA;YAExC,MAAMc,gBAAgB;gBAClB,GAAGD,cAAc;gBACjB,GAAGE,OAAO,WAAW,CAACT,sBAAsB;gBAC5C,GAAGI,UAAU;YACjB;YAEA,MAAMM,MAAMX,UAAU;gBAClB,QAAQ;gBACR,aAAa;gBACb,WAAWO;gBACX,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9C,MAAMK,KAAK,SAAS,CAAC;oBACjBR;oBACA,mBAAmBL;oBACnB,uFAAuF;oBACvF,gBAAgB;oBAChB,yBAA0BD,mBAAmB;oBAC7C,YAAYW;gBAChB;YACJ;QACJ,EAAE,OAAOI,OAAgB;YACrBX,OACK,QAAQ,CAAC,CAAC,gEAAgE,EAAEF,SAAS,EAAE,CAAC,EACxF,SAAS,CAACa,OACV,KAAK;QACd;IACJ;IAEA,OAAOV;AACX"}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createTelemetryContext, type CreateTelemetryContextOptions, type TelemetryContext } from "@workleap-telemetry/core";
|
|
2
|
-
export {
|
|
2
|
+
export type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, MixpanelTrackingFunction, MixpanelTrackingFunctionOptions } from "@workleap-telemetry/core";
|
|
3
|
+
export { createTrackingFunction } from "./createTrackingFunction.ts";
|
|
3
4
|
export type { MixpanelEnvironment } from "./env.ts";
|
|
4
5
|
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
5
6
|
export { MixpanelClient, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
6
|
-
export { type MixpanelEventProperties } from "./properties.ts";
|
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 {
|
|
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, type MixpanelGlobalEventProperties } from \"./MixpanelClient.ts\";\n\n"],"names":["createTelemetryContext","createTrackingFunction","initializeMixpanel","MixpanelClient"],"mappings":";;;;;;;;;;;;;;AAA6H;AAExD;AAEwB;AACJ"}
|
package/dist/js/properties.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js/properties.js","sources":["webpack://@workleap/mixpanel/./src/js/properties.ts"],"sourcesContent":["\nimport type { TelemetryContext } from \"@workleap-telemetry/core\";\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport
|
|
1
|
+
{"version":3,"file":"js/properties.js","sources":["webpack://@workleap/mixpanel/./src/js/properties.ts"],"sourcesContent":["\nimport type { MixpanelEventProperties, TelemetryContext } from \"@workleap-telemetry/core\";\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\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"],"names":["browserName","browserVersion","deviceType","osName","referringDomain","BaseProperties","getBaseProperties","userAgent","navigator","device","document","window","TelemetryProperties","getTelemetryProperties","context","OtherProperties"],"mappings":";;;;;AAE8F;AAEvF,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions } from "@workleap-telemetry/core";
|
|
2
2
|
/**
|
|
3
3
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
4
4
|
*/
|
|
@@ -7,4 +7,4 @@ export type UseTrackingFunctionOptions = CreateMixpanelTrackingFunctionOptions;
|
|
|
7
7
|
* Create a Mixpanel tracking function.
|
|
8
8
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
9
9
|
*/
|
|
10
|
-
export declare function useTrackingFunction(options?: UseTrackingFunctionOptions): import("
|
|
10
|
+
export declare function useTrackingFunction(options?: UseTrackingFunctionOptions): import("@workleap-telemetry/core").MixpanelTrackingFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react/useTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/react/useTrackingFunction.ts"],"sourcesContent":["import { useContext, useMemo } from \"react\";\nimport { createTrackingFunction
|
|
1
|
+
{"version":3,"file":"react/useTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/react/useTrackingFunction.ts"],"sourcesContent":["import type { CreateMixpanelTrackingFunctionOptions } from \"@workleap-telemetry/core\";\nimport { useContext, useMemo } from \"react\";\nimport { createTrackingFunction } from \"../js/createTrackingFunction.ts\";\nimport { MixpanelContext } from \"./MixpanelContext.tsx\";\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport type UseTrackingFunctionOptions = CreateMixpanelTrackingFunctionOptions;\n\n/**\n * Create a Mixpanel tracking function.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function useTrackingFunction(options: UseTrackingFunctionOptions = {}) {\n const {\n targetProductId\n } = options;\n\n const client = useContext(MixpanelContext);\n\n return useMemo(() => {\n const trackOptions = {\n targetProductId\n } satisfies CreateMixpanelTrackingFunctionOptions;\n\n // DEPRECATED: Grace period ends on January 1th 2026.\n // After the grace period, only create the tracking function from the client, remove the fallback\n // and also use \"useMixpanelClient\" to retrieve the client rather than \"useContext\".\n return client\n ? client.createTrackingFunction(trackOptions)\n : createTrackingFunction(trackOptions);\n }, [client, targetProductId]);\n}\n"],"names":["useContext","useMemo","createTrackingFunction","MixpanelContext","useTrackingFunction","options","targetProductId","client","trackOptions"],"mappings":";;;;;;;;;;;AAC4C;AAC6B;AACjB;AAOxD;;;CAGC,GACM,SAASI,oBAAoBC,UAAsC,CAAC,CAAC;IACxE,MAAM,EACFC,eAAe,EAClB,GAAGD;IAEJ,MAAME,SAASP,UAAUA,CAACG,eAAeA;IAEzC,OAAOF,OAAOA,CAAC;QACX,MAAMO,eAAe;YACjBF;QACJ;QAEA,qDAAqD;QACrD,iGAAiG;QACjG,oFAAoF;QACpF,OAAOC,SACDA,OAAO,sBAAsB,CAACC,gBAC9BN,sBAAsBA,CAACM;IACjC,GAAG;QAACD;QAAQD;KAAgB;AAChC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workleap/mixpanel",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
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.0.
|
|
38
|
+
"@workleap/logrocket": "2.0.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@workleap/logrocket": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@workleap/logging": "^1.3.0",
|
|
53
|
-
"@workleap-telemetry/core": "1.0.
|
|
53
|
+
"@workleap-telemetry/core": "1.0.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@rsbuild/core": "1.5.13",
|
package/src/js/MixpanelClient.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
1
2
|
import type { Logger } from "@workleap/logging";
|
|
2
|
-
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "./createTrackingFunction.ts";
|
|
3
3
|
import { getBaseProperties } from "./properties.ts";
|
|
4
4
|
|
|
5
5
|
export type MixpanelGlobalEventProperties = Map<string, unknown>;
|
|
@@ -20,6 +20,8 @@ export class MixpanelClient {
|
|
|
20
20
|
this.#logger = logger;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// IMPORTANT: If you update this method, make sure to update the MixpanelPartialClient
|
|
24
|
+
// interface as well in @workleap-telemetry/core.
|
|
23
25
|
/**
|
|
24
26
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
25
27
|
*/
|
|
@@ -2,44 +2,9 @@
|
|
|
2
2
|
// Must keep this code until the end of the grace period because host applications using version 2.* of
|
|
3
3
|
// this package would get runtime errors from the Platform Widgets CDN otherwise.
|
|
4
4
|
|
|
5
|
+
import type { CreateMixpanelTrackingFunctionOptions, MixpanelTrackingFunction } from "@workleap-telemetry/core";
|
|
5
6
|
import { getMixpanelContext } from "./context.ts";
|
|
6
|
-
import { getBaseProperties
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
10
|
-
*/
|
|
11
|
-
export interface CreateMixpanelTrackingFunctionOptions {
|
|
12
|
-
/**
|
|
13
|
-
* The product identifier of the target product.
|
|
14
|
-
*/
|
|
15
|
-
targetProductId?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
20
|
-
*/
|
|
21
|
-
export interface MixpanelTrackingFunctionOptions {
|
|
22
|
-
/**
|
|
23
|
-
* Whether to keep the connection alive for the tracking request.
|
|
24
|
-
* It is mostly used for tracking links where the user might navigate away before the request is completed.
|
|
25
|
-
*
|
|
26
|
-
* Caution! The body size for keepalive requests is limited to 64 kibibytes.
|
|
27
|
-
*
|
|
28
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
|
|
29
|
-
*
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
keepAlive?: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A function that sends tracking events to the tracking API.
|
|
37
|
-
* @param eventName The name of the event to track.
|
|
38
|
-
* @param properties The properties to send with the event.
|
|
39
|
-
* @param options Options for tracking the event.
|
|
40
|
-
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
41
|
-
*/
|
|
42
|
-
export type MixpanelTrackingFunction = (eventName: string, properties: MixpanelEventProperties, options?: MixpanelTrackingFunctionOptions) => Promise<void>;
|
|
7
|
+
import { getBaseProperties } from "./properties.ts";
|
|
43
8
|
|
|
44
9
|
/**
|
|
45
10
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
package/src/js/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createTelemetryContext, type CreateTelemetryContextOptions, type TelemetryContext } from "@workleap-telemetry/core";
|
|
2
|
-
export {
|
|
2
|
+
export type { CreateMixpanelTrackingFunctionOptions, MixpanelEventProperties, MixpanelTrackingFunction, MixpanelTrackingFunctionOptions } from "@workleap-telemetry/core";
|
|
3
|
+
export { createTrackingFunction } from "./createTrackingFunction.ts";
|
|
3
4
|
export type { MixpanelEnvironment } from "./env.ts";
|
|
4
5
|
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
5
6
|
export { MixpanelClient, type MixpanelGlobalEventProperties } from "./MixpanelClient.ts";
|
|
6
|
-
export { type MixpanelEventProperties } from "./properties.ts";
|
|
7
7
|
|
package/src/js/properties.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import type { TelemetryContext } from "@workleap-telemetry/core";
|
|
2
|
+
import type { MixpanelEventProperties, TelemetryContext } from "@workleap-telemetry/core";
|
|
3
3
|
import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
|
|
4
4
|
|
|
5
|
-
export type MixpanelEventProperties = Record<string, unknown>;
|
|
6
|
-
|
|
7
5
|
export const BaseProperties = {
|
|
8
6
|
Browser: "$browser",
|
|
9
7
|
BrowserVersion: "$browser_version",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CreateMixpanelTrackingFunctionOptions } from "@workleap-telemetry/core";
|
|
1
2
|
import { useContext, useMemo } from "react";
|
|
2
|
-
import { createTrackingFunction
|
|
3
|
+
import { createTrackingFunction } from "../js/createTrackingFunction.ts";
|
|
3
4
|
import { MixpanelContext } from "./MixpanelContext.tsx";
|
|
4
5
|
|
|
5
6
|
/**
|