@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
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getTrackingEndpoint, type Environment } from "./env.ts";
|
|
2
|
-
import { getBaseProperties, type TrackEventProperties } from "./properties.ts";
|
|
3
|
-
|
|
4
|
-
export interface TrackingOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Whether to keep the connection alive for the tracking request.
|
|
7
|
-
* It is mostly used for tracking links where the user might navigate away before the request is completed.
|
|
8
|
-
*
|
|
9
|
-
* Caution! The body size for keepalive requests is limited to 64 kibibytes.
|
|
10
|
-
*
|
|
11
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
|
|
12
|
-
*
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
keepAlive?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A function that sends tracking events to the tracking API.
|
|
20
|
-
* @param eventName The name of the event to track.
|
|
21
|
-
* @param properties The properties to send with the event.
|
|
22
|
-
* @param options Options for tracking the event.
|
|
23
|
-
*/
|
|
24
|
-
export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
|
|
25
|
-
|
|
26
|
-
export interface CreateTrackingFunctionOptions {
|
|
27
|
-
/**
|
|
28
|
-
* The product identifier of the target product.
|
|
29
|
-
* @default null
|
|
30
|
-
*/
|
|
31
|
-
targetProductId?: string | null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Creates a function that sends tracking events to the tracking API.
|
|
36
|
-
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
37
|
-
* @param env The environment to get the navigation url from . e.g. "local", "prod"
|
|
38
|
-
* @param createOptions Options for creating the tracking function.
|
|
39
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
40
|
-
*/
|
|
41
|
-
export function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a function that sends tracking events to the tracking API.
|
|
44
|
-
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
45
|
-
* @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
|
|
46
|
-
* @param createOptions Options for creating the tracking function.
|
|
47
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
48
|
-
*/
|
|
49
|
-
export function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
|
|
50
|
-
export function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {
|
|
51
|
-
const targetProductId = createOptions?.targetProductId ?? null;
|
|
52
|
-
const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
53
|
-
|
|
54
|
-
return async (eventName, properties, options) => {
|
|
55
|
-
const baseProperties = getBaseProperties();
|
|
56
|
-
const allProperties = { ...baseProperties, ...properties };
|
|
57
|
-
|
|
58
|
-
await fetch(fullUrl, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
credentials: "include",
|
|
61
|
-
keepalive: options?.keepAlive,
|
|
62
|
-
headers: { "Content-Type": "application/json" },
|
|
63
|
-
body: JSON.stringify({
|
|
64
|
-
eventName,
|
|
65
|
-
productIdentifier: productId,
|
|
66
|
-
targetProductIdentifier : targetProductId,
|
|
67
|
-
properties: allProperties
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
}
|
package/src/index.ts
DELETED
package/src/properties.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
|
|
3
|
-
|
|
4
|
-
export type TrackEventProperties = Record<string, unknown>;
|
|
5
|
-
|
|
6
|
-
const BaseTrackingProperties = {
|
|
7
|
-
AppVersion: "AppVersion",
|
|
8
|
-
Browser: "$browser",
|
|
9
|
-
BrowserVersion: "$browser_version",
|
|
10
|
-
CurrentUrl: "$current_url",
|
|
11
|
-
Device: "$device",
|
|
12
|
-
IsMobile: "IsMobile",
|
|
13
|
-
Os: "$os",
|
|
14
|
-
Referrer: "$referrer",
|
|
15
|
-
ReferringDomain: "$referring_domain",
|
|
16
|
-
ScreenHeight: "$screen_height",
|
|
17
|
-
ScreenWidth: "$screen_width"
|
|
18
|
-
} as const;
|
|
19
|
-
|
|
20
|
-
export function getBaseProperties() {
|
|
21
|
-
const userAgent = navigator.userAgent;
|
|
22
|
-
const device = deviceType(userAgent);
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
[BaseTrackingProperties.Os]: osName(userAgent),
|
|
26
|
-
[BaseTrackingProperties.Browser]: browserName(userAgent, navigator.vendor),
|
|
27
|
-
[BaseTrackingProperties.Referrer]: document.referrer,
|
|
28
|
-
[BaseTrackingProperties.ReferringDomain]: referringDomain(document.referrer),
|
|
29
|
-
[BaseTrackingProperties.Device]: device,
|
|
30
|
-
[BaseTrackingProperties.CurrentUrl]: window.location.href,
|
|
31
|
-
[BaseTrackingProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
|
|
32
|
-
[BaseTrackingProperties.ScreenHeight]: window.screen.height,
|
|
33
|
-
[BaseTrackingProperties.ScreenWidth]: window.screen.width,
|
|
34
|
-
[BaseTrackingProperties.IsMobile]: device.length > 0
|
|
35
|
-
} satisfies TrackEventProperties;
|
|
36
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|