@workleap/mixpanel 1.1.2 → 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 +30 -6
- package/README.md +1 -1
- package/dist/js/HasExecutedGuard.d.ts +6 -0
- package/dist/js/HasExecutedGuard.js +21 -0
- package/dist/js/HasExecutedGuard.js.map +1 -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/{env.js → js/env.js} +1 -1
- package/dist/js/env.js.map +1 -0
- package/dist/js/index.d.ts +4 -0
- package/dist/js/index.js +18 -0
- package/dist/js/index.js.map +1 -0
- package/dist/js/initializeMixpanel.d.ts +17 -0
- package/dist/js/initializeMixpanel.js +86 -0
- package/dist/js/initializeMixpanel.js.map +1 -0
- package/dist/js/properties.d.ts +42 -0
- package/dist/js/properties.js +69 -0
- package/dist/js/properties.js.map +1 -0
- package/dist/{utils.js → js/utils.js} +1 -1
- package/dist/js/utils.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -0
- 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 +29 -14
- package/src/js/HasExecutedGuard.ts +19 -0
- package/src/js/context.ts +34 -0
- package/src/js/createTrackingFunction.ts +86 -0
- package/src/{env.ts → js/env.ts} +2 -0
- package/src/js/index.ts +5 -0
- package/src/js/initializeMixpanel.ts +84 -0
- package/src/js/properties.ts +79 -0
- package/src/react/index.ts +2 -0
- package/src/react/useTrackingFunction.ts +14 -0
- package/dist/createTrackingFunction.d.ts +0 -45
- package/dist/createTrackingFunction.js +0 -39
- package/dist/createTrackingFunction.js.map +0 -1
- package/dist/env.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/properties.d.ts +0 -13
- package/dist/properties.js +0 -39
- package/dist/properties.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/src/createTrackingFunction.ts +0 -71
- package/src/index.ts +0 -4
- package/src/properties.ts +0 -36
- /package/dist/{env.d.ts → js/env.d.ts} +0 -0
- /package/dist/{utils.d.ts → js/utils.d.ts} +0 -0
- /package/src/{utils.ts → js/utils.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,35 +1,59 @@
|
|
|
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
|
+
|
|
9
|
+
## 2.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [#29](https://github.com/workleap/wl-telemetry/pull/29) [`812f691`](https://github.com/workleap/wl-telemetry/commit/812f691676c60a7748b0db87e38e3b86591e2a85) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Those new packages provides an integration experience for telemetry. By linking session data, performance traces, and user interactions through consistent identifiers. It becomes possible to trace a single application event across systems, from backend performance to frontend behavior to product impact. This integration streamlines will hopefully enables faster, and more informed decision-making.
|
|
14
|
+
|
|
15
|
+
For migration instruction, visit the [migrate](https://workleap.github.io/wl-telemetry/introduction/migrate/) page.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`812f691`](https://github.com/workleap/wl-telemetry/commit/812f691676c60a7748b0db87e38e3b86591e2a85)]:
|
|
20
|
+
- @workleap/telemetry@1.0.0
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`c46c378`](https://github.com/workleap/wl-telemetry/commit/c46c3783079835063d1969f547b0d4947d7bd573)]:
|
|
25
|
+
- @workleap/telemetry@1.0.0
|
|
26
|
+
|
|
3
27
|
## 1.1.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
6
30
|
|
|
7
|
-
- [#22](https://github.com/workleap/wl-
|
|
31
|
+
- [#22](https://github.com/workleap/wl-telemetry/pull/22) [`0c437d0`](https://github.com/workleap/wl-telemetry/commit/0c437d055a2f0fcdfd5130a9a2239631d6cdfc4d) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated dependencies.
|
|
8
32
|
|
|
9
33
|
## 1.1.1
|
|
10
34
|
|
|
11
35
|
### Patch Changes
|
|
12
36
|
|
|
13
|
-
- [#14](https://github.com/workleap/wl-
|
|
37
|
+
- [#14](https://github.com/workleap/wl-telemetry/pull/14) [`a639574`](https://github.com/workleap/wl-telemetry/commit/a639574d5d9f1f3a4227db6e356e6a71fad6af1d) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Fixed an issue where the payload had the wrong name for productIdentifier and targetProductIdentifier
|
|
14
38
|
|
|
15
39
|
## 1.1.0
|
|
16
40
|
|
|
17
41
|
### Minor Changes
|
|
18
42
|
|
|
19
|
-
- [#8](https://github.com/workleap/wl-
|
|
43
|
+
- [#8](https://github.com/workleap/wl-telemetry/pull/8) [`5199dc1`](https://github.com/workleap/wl-telemetry/commit/5199dc1cce5d9ab05c0cda84be2ac81cdf6a9456) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add the possibility to specify only the environment to use, and the tracking function will provide the correct URL
|
|
20
44
|
|
|
21
45
|
### Patch Changes
|
|
22
46
|
|
|
23
|
-
- [#6](https://github.com/workleap/wl-
|
|
47
|
+
- [#6](https://github.com/workleap/wl-telemetry/pull/6) [`e26a764`](https://github.com/workleap/wl-telemetry/commit/e26a764282f881b4ab50009db1f88879e8a02776) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Export types from the packages
|
|
24
48
|
|
|
25
49
|
## 1.0.2
|
|
26
50
|
|
|
27
51
|
### Patch Changes
|
|
28
52
|
|
|
29
|
-
- [#4](https://github.com/workleap/wl-
|
|
53
|
+
- [#4](https://github.com/workleap/wl-telemetry/pull/4) [`3430c6d`](https://github.com/workleap/wl-telemetry/commit/3430c6dc2ccf381a96f8d1d03e7f695670d9e9d2) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Added cjs entry point to our package
|
|
30
54
|
|
|
31
55
|
## 1.0.1
|
|
32
56
|
|
|
33
57
|
### Patch Changes
|
|
34
58
|
|
|
35
|
-
- [#2](https://github.com/workleap/wl-
|
|
59
|
+
- [#2](https://github.com/workleap/wl-telemetry/pull/2) [`5e904ad`](https://github.com/workleap/wl-telemetry/commit/5e904ad5117d86d0d7e7a727bfabe3f2db427f62) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add readme to package
|
package/README.md
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
;// CONCATENATED MODULE: ./src/js/HasExecutedGuard.ts
|
|
3
|
+
class HasExecutedGuard {
|
|
4
|
+
#hasExecuted = false;
|
|
5
|
+
throw(message) {
|
|
6
|
+
if (this.#hasExecuted) {
|
|
7
|
+
throw new Error(message);
|
|
8
|
+
}
|
|
9
|
+
this.#hasExecuted = true;
|
|
10
|
+
}
|
|
11
|
+
get hasExecuted() {
|
|
12
|
+
return this.#hasExecuted;
|
|
13
|
+
}
|
|
14
|
+
reset() {
|
|
15
|
+
this.#hasExecuted = false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { HasExecutedGuard };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=HasExecutedGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/HasExecutedGuard.js","sources":["webpack://@workleap/mixpanel/./src/js/HasExecutedGuard.ts"],"sourcesContent":["export class HasExecutedGuard {\n #hasExecuted: boolean = false;\n\n throw(message: string) {\n if (this.#hasExecuted) {\n throw new Error(message);\n }\n\n this.#hasExecuted = true;\n }\n\n get hasExecuted() {\n return this.#hasExecuted;\n }\n\n reset() {\n this.#hasExecuted = false;\n }\n}\n"],"names":["HasExecutedGuard","message","Error"],"mappings":";;AAAO,MAAMA;IACT,YAAY,GAAY,MAAM;IAE9B,MAAMC,OAAe,EAAE;QACnB,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,MAAM,IAAIC,MAAMD;QACpB;QAEA,IAAI,CAAC,YAAY,GAAG;IACxB;IAEA,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,YAAY;IAC5B;IAEA,QAAQ;QACJ,IAAI,CAAC,YAAY,GAAG;IACxB;AACJ"}
|
|
@@ -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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/env.js","sources":["webpack://@workleap/mixpanel/./src/js/env.ts"],"sourcesContent":["\nconst EnvironmentList = [\"development\", \"staging\", \"production\", \"local\", \"msw\"] as const;\n\nexport type Environment = typeof EnvironmentList[number];\n\nconst NavigationApiBaseUrl: Record<Environment, string> = {\n \"production\": \"https://api.platform.workleap.com/shell/navigation/\",\n \"staging\": \"https://api.platform.workleap-stg.com/shell/navigation/\",\n \"development\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"local\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"msw\": \"/api/shell/navigation/\"\n};\n\n// Cannot use URL() because it doesn't support relative base url: https://github.com/whatwg/url/issues/531.\nfunction resolveApiUrl(path: string, baseUrl: string | undefined) : string {\n return `${baseUrl}${baseUrl!.endsWith(\"/\") ? \"\" : \"/\"}${path.startsWith(\"/\") ? path.substring(1) : path}`;\n}\n\nexport function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {\n let baseUrl: string;\n\n if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {\n baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];\n } else {\n baseUrl = envOrTrackingApiBaseUrl;\n }\n\n return resolveApiUrl(\"tracking/track\", baseUrl);\n}\n"],"names":["EnvironmentList","NavigationApiBaseUrl","resolveApiUrl","path","baseUrl","getTrackingEndpoint","envOrTrackingApiBaseUrl"],"mappings":";;AACA,MAAMA,kBAAkB;IAAC;IAAe;IAAW;IAAc;IAAS;CAAM;AAIhF,MAAMC,uBAAoD;IACtD,cAAc;IACd,WAAW;IACX,eAAe;IACf,SAAS;IACT,OAAO;AACX;AAEA,2GAA2G;AAC3G,SAASC,cAAcC,IAAY,EAAEC,OAA2B;IAC5D,OAAO,GAAGA,UAAUA,QAAS,QAAQ,CAAC,OAAO,KAAK,MAAMD,KAAK,UAAU,CAAC,OAAOA,KAAK,SAAS,CAAC,KAAKA,MAAM;AAC7G;AAEO,SAASE,oBAAoBC,uBAAoD;IACpF,IAAIF;IAEJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAc,kBAAkBE;AAC3C"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createTrackingFunction, type CreateTrackingFunctionOptions, type TrackingFunction, type TrackingFunctionOptions } from "./createTrackingFunction.ts";
|
|
2
|
+
export type { Environment } from "./env.ts";
|
|
3
|
+
export { initializeMixpanel, type InitializeMixpanelOptions } from "./initializeMixpanel.ts";
|
|
4
|
+
export { setSuperProperties, setSuperProperty, type MixpanelEventProperties } from "./properties.ts";
|
package/dist/js/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createTrackingFunction } from "./createTrackingFunction.js";
|
|
2
|
+
import { initializeMixpanel } from "./initializeMixpanel.js";
|
|
3
|
+
import { setSuperProperties, setSuperProperty } from "./properties.js";
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: external "./createTrackingFunction.js"
|
|
6
|
+
|
|
7
|
+
;// CONCATENATED MODULE: external "./initializeMixpanel.js"
|
|
8
|
+
|
|
9
|
+
;// CONCATENATED MODULE: external "./properties.js"
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: ./src/js/index.ts
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export { createTrackingFunction, initializeMixpanel, setSuperProperties, setSuperProperty };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Environment } from "./env.ts";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
4
|
+
*/
|
|
5
|
+
export interface InitializeMixpanelOptions {
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function __resetInitializationGuard(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a function that sends tracking events to the tracking API.
|
|
11
|
+
* @param productId Your product identifier.
|
|
12
|
+
* @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
|
|
13
|
+
* @param options Options for creating the tracking function.
|
|
14
|
+
* @returns A function that sends tracking events to the tracking API.
|
|
15
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
16
|
+
*/
|
|
17
|
+
export declare function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options?: InitializeMixpanelOptions): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
import { setMixpanelContext } from "./context.js";
|
|
3
|
+
import { getTrackingEndpoint } from "./env.js";
|
|
4
|
+
import { HasExecutedGuard } from "./HasExecutedGuard.js";
|
|
5
|
+
import { OtherProperties, getSuperProperties, getTelemetryProperties, setSuperProperties, setSuperProperty } from "./properties.js";
|
|
6
|
+
|
|
7
|
+
;// CONCATENATED MODULE: external "@workleap/telemetry"
|
|
8
|
+
|
|
9
|
+
;// CONCATENATED MODULE: external "./context.js"
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: external "./env.js"
|
|
12
|
+
|
|
13
|
+
;// CONCATENATED MODULE: external "./HasExecutedGuard.js"
|
|
14
|
+
|
|
15
|
+
;// CONCATENATED MODULE: external "./properties.js"
|
|
16
|
+
|
|
17
|
+
;// CONCATENATED MODULE: ./src/js/initializeMixpanel.ts
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function registerLogRocketSessionUrlListener(verbose = false) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
|
|
27
|
+
// Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl)=>{
|
|
31
|
+
if (verbose) {
|
|
32
|
+
console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
|
|
33
|
+
}
|
|
34
|
+
setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);
|
|
35
|
+
});
|
|
36
|
+
} else if (verbose) {
|
|
37
|
+
console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const initializationGuard = new HasExecutedGuard();
|
|
41
|
+
// This function should only be used by tests.
|
|
42
|
+
function __resetInitializationGuard() {
|
|
43
|
+
initializationGuard.reset();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a function that sends tracking events to the tracking API.
|
|
47
|
+
* @param productId Your product identifier.
|
|
48
|
+
* @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
|
|
49
|
+
* @param options Options for creating the tracking function.
|
|
50
|
+
* @returns A function that sends tracking events to the tracking API.
|
|
51
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
52
|
+
*/ function initializeMixpanel(productId, envOrTrackingApiBaseUrl, options = {}) {
|
|
53
|
+
const { verbose = false } = options;
|
|
54
|
+
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
55
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
56
|
+
const telemetryContext = getTelemetryContext({
|
|
57
|
+
verbose
|
|
58
|
+
});
|
|
59
|
+
setSuperProperties(getTelemetryProperties(telemetryContext));
|
|
60
|
+
const bootstrappingStore = getBootstrappingStore();
|
|
61
|
+
// If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store
|
|
62
|
+
// and register the listener once a notification is received that LogRocket is registered.
|
|
63
|
+
if (bootstrappingStore.state.isLogRocketReady) {
|
|
64
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
65
|
+
} else {
|
|
66
|
+
bootstrappingStore.subscribe((action, store, unsubscribe)=>{
|
|
67
|
+
if (store.state.isLogRocketReady) {
|
|
68
|
+
unsubscribe();
|
|
69
|
+
registerLogRocketSessionUrlListener(verbose);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
setMixpanelContext({
|
|
74
|
+
productId,
|
|
75
|
+
endpoint,
|
|
76
|
+
superProperties: getSuperProperties(),
|
|
77
|
+
verbose
|
|
78
|
+
});
|
|
79
|
+
if (verbose) {
|
|
80
|
+
console.log("[mixpanel] Mixpanel is initialized.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { __resetInitializationGuard, initializeMixpanel };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=initializeMixpanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { getBootstrappingStore, getTelemetryContext } from \"@workleap/telemetry\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from \"./properties.ts\";\n\n/**\n * @see https://workleap.github.io/wl-telemetry\n */\nexport interface InitializeMixpanelOptions {\n verbose?: boolean;\n}\nfunction registerLogRocketSessionUrlListener(verbose = false) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {\n // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {\n if (verbose) {\n console.log(\"[mixpanel] Received LogRocket session replay URL:\", sessionUrl);\n }\n\n setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);\n });\n } else if (verbose) {\n console.log(\"[mixpanel] Cannot integrate with LogRocket because \\\"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\\\" is not available.\");\n }\n}\n\nconst initializationGuard = new HasExecutedGuard();\n\n// This function should only be used by tests.\nexport function __resetInitializationGuard() {\n initializationGuard.reset();\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier.\n * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.\n * @param options Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n * @see https://workleap.github.io/wl-telemetry\n */\nexport function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {\n const {\n verbose = false\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n const telemetryContext = getTelemetryContext({ verbose });\n\n setSuperProperties(getTelemetryProperties(telemetryContext));\n\n const bootstrappingStore = getBootstrappingStore();\n\n // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store\n // and register the listener once a notification is received that LogRocket is registered.\n if (bootstrappingStore.state.isLogRocketReady) {\n registerLogRocketSessionUrlListener(verbose);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(verbose);\n }\n });\n }\n\n setMixpanelContext({\n productId,\n endpoint,\n superProperties: getSuperProperties(),\n verbose\n });\n\n if (verbose) {\n console.log(\"[mixpanel] Mixpanel is initialized.\");\n }\n}\n"],"names":["getBootstrappingStore","getTelemetryContext","setMixpanelContext","getTrackingEndpoint","HasExecutedGuard","getSuperProperties","getTelemetryProperties","OtherProperties","setSuperProperties","setSuperProperty","registerLogRocketSessionUrlListener","verbose","globalThis","sessionUrl","console","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","endpoint","telemetryContext","bootstrappingStore","action","store","unsubscribe"],"mappings":";;;;;;;;;;;;;;;;;AAAiF;AAC/B;AACe;AACR;AAC2E;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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
export type MixpanelEventProperties = Record<string, unknown>;
|
|
3
|
+
export declare const BaseProperties: {
|
|
4
|
+
readonly Browser: "$browser";
|
|
5
|
+
readonly BrowserVersion: "$browser_version";
|
|
6
|
+
readonly CurrentUrl: "$current_url";
|
|
7
|
+
readonly Device: "$device";
|
|
8
|
+
readonly IsMobile: "Is Mobile";
|
|
9
|
+
readonly Os: "$os";
|
|
10
|
+
readonly Referrer: "$referrer";
|
|
11
|
+
readonly ReferringDomain: "$referring_domain";
|
|
12
|
+
readonly ScreenHeight: "$screen_height";
|
|
13
|
+
readonly ScreenWidth: "$screen_width";
|
|
14
|
+
};
|
|
15
|
+
export declare function getBaseProperties(): {
|
|
16
|
+
$os: string;
|
|
17
|
+
$browser: string;
|
|
18
|
+
$referrer: string;
|
|
19
|
+
$referring_domain: string;
|
|
20
|
+
$device: string;
|
|
21
|
+
$current_url: string;
|
|
22
|
+
$browser_version: number | null;
|
|
23
|
+
$screen_height: number;
|
|
24
|
+
$screen_width: number;
|
|
25
|
+
"Is Mobile": boolean;
|
|
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;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "./utils.js"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/js/properties.ts
|
|
6
|
+
|
|
7
|
+
const BaseProperties = {
|
|
8
|
+
Browser: "$browser",
|
|
9
|
+
BrowserVersion: "$browser_version",
|
|
10
|
+
CurrentUrl: "$current_url",
|
|
11
|
+
Device: "$device",
|
|
12
|
+
IsMobile: "Is Mobile",
|
|
13
|
+
Os: "$os",
|
|
14
|
+
Referrer: "$referrer",
|
|
15
|
+
ReferringDomain: "$referring_domain",
|
|
16
|
+
ScreenHeight: "$screen_height",
|
|
17
|
+
ScreenWidth: "$screen_width"
|
|
18
|
+
};
|
|
19
|
+
function getBaseProperties() {
|
|
20
|
+
const userAgent = navigator.userAgent;
|
|
21
|
+
const device = deviceType(userAgent);
|
|
22
|
+
return {
|
|
23
|
+
[BaseProperties.Os]: osName(userAgent),
|
|
24
|
+
[BaseProperties.Browser]: browserName(userAgent, navigator.vendor),
|
|
25
|
+
[BaseProperties.Referrer]: document.referrer,
|
|
26
|
+
[BaseProperties.ReferringDomain]: referringDomain(document.referrer),
|
|
27
|
+
[BaseProperties.Device]: device,
|
|
28
|
+
[BaseProperties.CurrentUrl]: window.location.href,
|
|
29
|
+
[BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
|
|
30
|
+
[BaseProperties.ScreenHeight]: window.screen.height,
|
|
31
|
+
[BaseProperties.ScreenWidth]: window.screen.width,
|
|
32
|
+
[BaseProperties.IsMobile]: device.length > 0
|
|
33
|
+
};
|
|
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
|
+
}
|
|
66
|
+
|
|
67
|
+
export { BaseProperties, OtherProperties, TelemetryProperties, __clearSuperProperties, getBaseProperties, getSuperProperties, getTelemetryProperties, setSuperProperties, setSuperProperty };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
;// CONCATENATED MODULE: ./src/utils.ts
|
|
2
|
+
;// CONCATENATED MODULE: ./src/js/utils.ts
|
|
3
3
|
// This code is adapted from https://github.com/mixpanel/mixpanel-js/blob/master/src/utils.js
|
|
4
4
|
function browserName(userAgent, vendor, opera) {
|
|
5
5
|
// vendor is undefined for at least IE9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/utils.js","sources":["webpack://@workleap/mixpanel/./src/js/utils.ts"],"sourcesContent":["// This code is adapted from https://github.com/mixpanel/mixpanel-js/blob/master/src/utils.js\nexport function browserName(userAgent: string, vendor?: string, opera?: object) {\n // vendor is undefined for at least IE9\n vendor = vendor || \"\"; // eslint-disable-line no-param-reassign\n\n if (opera || userAgent.includes(\" OPR/\")) {\n if (userAgent.includes(\"Mini\")) {\n return \"Opera Mini\";\n }\n\n return \"Opera\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) {\n return \"BlackBerry\";\n } else if (userAgent.includes(\"IEMobile\") || userAgent.includes(\"WPDesktop\")) {\n return \"Internet Explorer Mobile\";\n } else if (userAgent.includes(\"Edge\")) {\n return \"Microsoft Edge\";\n } else if (userAgent.includes(\"FBIOS\")) {\n return \"Facebook Mobile\";\n } else if (userAgent.includes(\"Chrome\")) {\n return \"Chrome\";\n } else if (userAgent.includes(\"CriOS\")) {\n return \"Chrome iOS\";\n } else if (userAgent.includes(\"UCWEB\") || userAgent.includes(\"UCBrowser\")) {\n return \"UC Browser\";\n } else if (userAgent.includes(\"FxiOS\")) {\n return \"Firefox iOS\";\n } else if (vendor.includes(\"Apple\")) {\n if (userAgent.includes(\"Mobile\")) {\n return \"Mobile Safari\";\n }\n\n return \"Safari\";\n } else if (userAgent.includes(\"Android\")) {\n return \"Android Mobile\";\n } else if (userAgent.includes(\"Konqueror\")) {\n return \"Konqueror\";\n } else if (userAgent.includes(\"Firefox\")) {\n return \"Firefox\";\n } else if (userAgent.includes(\"MSIE\") || userAgent.includes(\"Trident/\")) {\n return \"Internet Explorer\";\n } else if (userAgent.includes(\"Gecko\")) {\n return \"Mozilla\";\n }\n\n return \"\";\n}\n\n/**\n * This function detects which browser version is running this script,\n * parsing major and minor version (e.g., 42.1). User agent strings from:\n * http://www.useragentstring.com/pages/useragentstring.php\n */\nexport function browserVersion(userAgent: string, vendor?: string, opera?: object) {\n const browser = browserName(userAgent, vendor, opera);\n const versionRegexs: { [key: string]: RegExp } = {\n \"Internet Explorer Mobile\": /rv:(\\d+(\\.\\d+)?)/,\n \"Microsoft Edge\": /Edge\\/(\\d+(\\.\\d+)?)/,\n \"Chrome\": /Chrome\\/(\\d+(\\.\\d+)?)/,\n \"Chrome iOS\": /CriOS\\/(\\d+(\\.\\d+)?)/,\n \"UC Browser\": /(UCBrowser|UCWEB)\\/(\\d+(\\.\\d+)?)/,\n \"Safari\": /Version\\/(\\d+(\\.\\d+)?)/,\n \"Mobile Safari\": /Version\\/(\\d+(\\.\\d+)?)/,\n \"Opera\": /(Opera|OPR)\\/(\\d+(\\.\\d+)?)/,\n \"Firefox\": /Firefox\\/(\\d+(\\.\\d+)?)/,\n \"Firefox iOS\": /FxiOS\\/(\\d+(\\.\\d+)?)/,\n \"Konqueror\": /Konqueror:(\\d+(\\.\\d+)?)/,\n \"BlackBerry\": /BlackBerry (\\d+(\\.\\d+)?)/,\n \"Android Mobile\": /android\\s(\\d+(\\.\\d+)?)/,\n \"Internet Explorer\": /(rv:|MSIE )(\\d+(\\.\\d+)?)/,\n \"Mozilla\": /rv:(\\d+(\\.\\d+)?)/\n };\n const regex = versionRegexs[browser];\n if (regex === undefined) {\n return null;\n }\n const matches = userAgent.match(regex);\n if (!matches) {\n return null;\n }\n\n return parseFloat(matches[matches.length - 2]);\n}\n\nexport function osName(userAgent: string) {\n const a = userAgent;\n if (/Windows/i.test(a)) {\n if (/Phone/.test(a) || /WPDesktop/.test(a)) {\n return \"Windows Phone\";\n }\n\n return \"Windows\";\n } else if (/(iPhone|iPad|iPod)/.test(a)) {\n return \"iOS\";\n } else if (/Android/.test(a)) {\n return \"Android\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {\n return \"BlackBerry\";\n } else if (/Mac/i.test(a)) {\n return \"Mac OS X\";\n } else if (/Linux/.test(a)) {\n return \"Linux\";\n } else if (/CrOS/.test(a)) {\n return \"Chrome OS\";\n }\n\n return \"\";\n}\n\nexport function deviceType(userAgent: string) {\n if (/Windows Phone/i.test(userAgent) || /WPDesktop/.test(userAgent)) {\n return \"Windows Phone\";\n } else if (/iPad/.test(userAgent)) {\n return \"iPad\";\n } else if (/iPod/.test(userAgent)) {\n return \"iPod Touch\";\n } else if (/iPhone/.test(userAgent)) {\n return \"iPhone\";\n } else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) {\n return \"BlackBerry\";\n } else if (/Android/.test(userAgent)) {\n return \"Android\";\n }\n\n return \"\";\n}\n\nexport function referringDomain(referrer: string) {\n const split = referrer.split(\"/\");\n if (split.length >= 3) {\n return split[2];\n }\n\n return \"\";\n}\n"],"names":["browserName","userAgent","vendor","opera","browserVersion","browser","versionRegexs","regex","undefined","matches","parseFloat","osName","a","deviceType","referringDomain","referrer","split"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTrackingFunction, type UseTrackingFunctionOptions } from "./useTrackingFunction.ts";
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|