@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/package.json
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workleap/mixpanel",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "A package containing utilities for Mixpanel telemetry.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/workleap/wl-
|
|
9
|
+
"url": "git+https://github.com/workleap/wl-telemetry.git",
|
|
10
10
|
"directory": "packages/mixpanel"
|
|
11
11
|
},
|
|
12
|
+
"type": "module",
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"access": "public",
|
|
14
15
|
"provenance": true
|
|
15
16
|
},
|
|
16
|
-
"type": "module",
|
|
17
|
-
"main": "./dist/index.js",
|
|
18
17
|
"exports": {
|
|
19
18
|
".": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"default": "./dist/index.js"
|
|
19
|
+
"types": "./dist/js/index.d.ts",
|
|
20
|
+
"import": "./dist/js/index.js",
|
|
21
|
+
"default": "./dist/js/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./react": {
|
|
24
|
+
"types": "./dist/react/index.d.ts",
|
|
25
|
+
"import": "./dist/react/index.js",
|
|
26
|
+
"default": "./dist/react/index.js"
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
@@ -28,19 +32,30 @@
|
|
|
28
32
|
"CHANGELOG.md",
|
|
29
33
|
"README.md"
|
|
30
34
|
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
37
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
38
|
+
"@workleap/telemetry": "1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"react": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"react-dom": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
31
48
|
"devDependencies": {
|
|
32
|
-
"@rsbuild/core": "1.
|
|
33
|
-
"@rslib/core": "0.
|
|
49
|
+
"@rsbuild/core": "1.4.6",
|
|
50
|
+
"@rslib/core": "0.10.5",
|
|
51
|
+
"@types/react": "19.1.8",
|
|
34
52
|
"@workleap/eslint-plugin": "3.4.2",
|
|
35
53
|
"@workleap/rslib-configs": "1.0.6",
|
|
36
54
|
"@workleap/typescript-configs": "3.0.4",
|
|
37
55
|
"eslint": "8.57.1",
|
|
38
|
-
"happy-dom": "
|
|
56
|
+
"happy-dom": "18.0.1",
|
|
39
57
|
"typescript": "5.8.3",
|
|
40
|
-
"vitest": "3.
|
|
41
|
-
},
|
|
42
|
-
"engines": {
|
|
43
|
-
"node": ">=18.0.0"
|
|
58
|
+
"vitest": "3.2.4"
|
|
44
59
|
},
|
|
45
60
|
"sideEffects": false,
|
|
46
61
|
"scripts": {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class HasExecutedGuard {
|
|
2
|
+
#hasExecuted: boolean = false;
|
|
3
|
+
|
|
4
|
+
throw(message: string) {
|
|
5
|
+
if (this.#hasExecuted) {
|
|
6
|
+
throw new Error(message);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
this.#hasExecuted = true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get hasExecuted() {
|
|
13
|
+
return this.#hasExecuted;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
reset() {
|
|
17
|
+
this.#hasExecuted = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -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/{env.ts → js/env.ts}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const EnvironmentList = ["development", "staging", "production", "local", "msw"] as const;
|
|
3
|
+
|
|
3
4
|
export type Environment = typeof EnvironmentList[number];
|
|
4
5
|
|
|
5
6
|
const NavigationApiBaseUrl: Record<Environment, string> = {
|
|
@@ -17,6 +18,7 @@ function resolveApiUrl(path: string, baseUrl: string | undefined) : string {
|
|
|
17
18
|
|
|
18
19
|
export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {
|
|
19
20
|
let baseUrl: string;
|
|
21
|
+
|
|
20
22
|
if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {
|
|
21
23
|
baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];
|
|
22
24
|
} else {
|
package/src/js/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
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";
|
|
5
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
import { setMixpanelContext } from "./context.ts";
|
|
3
|
+
import { getTrackingEndpoint, type Environment } from "./env.ts";
|
|
4
|
+
import { HasExecutedGuard } from "./HasExecutedGuard.ts";
|
|
5
|
+
import { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from "./properties.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
9
|
+
*/
|
|
10
|
+
export interface InitializeMixpanelOptions {
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
}
|
|
13
|
+
function registerLogRocketSessionUrlListener(verbose = false) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {
|
|
17
|
+
// Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {
|
|
21
|
+
if (verbose) {
|
|
22
|
+
console.log("[mixpanel] Received LogRocket session replay URL:", sessionUrl);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);
|
|
26
|
+
});
|
|
27
|
+
} else if (verbose) {
|
|
28
|
+
console.log("[mixpanel] Cannot integrate with LogRocket because \"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\" is not available.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const initializationGuard = new HasExecutedGuard();
|
|
33
|
+
|
|
34
|
+
// This function should only be used by tests.
|
|
35
|
+
export function __resetInitializationGuard() {
|
|
36
|
+
initializationGuard.reset();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a function that sends tracking events to the tracking API.
|
|
41
|
+
* @param productId Your product identifier.
|
|
42
|
+
* @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.
|
|
43
|
+
* @param options Options for creating the tracking function.
|
|
44
|
+
* @returns A function that sends tracking events to the tracking API.
|
|
45
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
46
|
+
*/
|
|
47
|
+
export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {
|
|
48
|
+
const {
|
|
49
|
+
verbose = false
|
|
50
|
+
} = options;
|
|
51
|
+
|
|
52
|
+
initializationGuard.throw("[mixpanel] Mixpanel has already been initialized. Did you call the \"initializeMixpanel\" function twice?");
|
|
53
|
+
|
|
54
|
+
const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
55
|
+
const telemetryContext = getTelemetryContext({ verbose });
|
|
56
|
+
|
|
57
|
+
setSuperProperties(getTelemetryProperties(telemetryContext));
|
|
58
|
+
|
|
59
|
+
const bootstrappingStore = getBootstrappingStore();
|
|
60
|
+
|
|
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
|
+
|
|
74
|
+
setMixpanelContext({
|
|
75
|
+
productId,
|
|
76
|
+
endpoint,
|
|
77
|
+
superProperties: getSuperProperties(),
|
|
78
|
+
verbose
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (verbose) {
|
|
82
|
+
console.log("[mixpanel] Mixpanel is initialized.");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import type { TelemetryContext } from "@workleap/telemetry";
|
|
3
|
+
import { browserName, browserVersion, deviceType, osName, referringDomain } from "./utils.ts";
|
|
4
|
+
|
|
5
|
+
export type MixpanelEventProperties = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export 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
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export function getBaseProperties() {
|
|
21
|
+
const userAgent = navigator.userAgent;
|
|
22
|
+
const device = deviceType(userAgent);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
[BaseProperties.Os]: osName(userAgent),
|
|
26
|
+
[BaseProperties.Browser]: browserName(userAgent, navigator.vendor),
|
|
27
|
+
[BaseProperties.Referrer]: document.referrer,
|
|
28
|
+
[BaseProperties.ReferringDomain]: referringDomain(document.referrer),
|
|
29
|
+
[BaseProperties.Device]: device,
|
|
30
|
+
[BaseProperties.CurrentUrl]: window.location.href,
|
|
31
|
+
[BaseProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),
|
|
32
|
+
[BaseProperties.ScreenHeight]: window.screen.height,
|
|
33
|
+
[BaseProperties.ScreenWidth]: window.screen.width,
|
|
34
|
+
[BaseProperties.IsMobile]: device.length > 0
|
|
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();
|
|
79
|
+
}
|
|
@@ -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,45 +0,0 @@
|
|
|
1
|
-
import { type Environment } from "./env.ts";
|
|
2
|
-
import { type TrackEventProperties } from "./properties.ts";
|
|
3
|
-
export interface TrackingOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Whether to keep the connection alive for the tracking request.
|
|
6
|
-
* It is mostly used for tracking links where the user might navigate away before the request is completed.
|
|
7
|
-
*
|
|
8
|
-
* Caution! The body size for keepalive requests is limited to 64 kibibytes.
|
|
9
|
-
*
|
|
10
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
|
|
11
|
-
*
|
|
12
|
-
* @default false
|
|
13
|
-
*/
|
|
14
|
-
keepAlive?: boolean;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A function that sends tracking events to the tracking API.
|
|
18
|
-
* @param eventName The name of the event to track.
|
|
19
|
-
* @param properties The properties to send with the event.
|
|
20
|
-
* @param options Options for tracking the event.
|
|
21
|
-
*/
|
|
22
|
-
export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
|
|
23
|
-
export interface CreateTrackingFunctionOptions {
|
|
24
|
-
/**
|
|
25
|
-
* The product identifier of the target product.
|
|
26
|
-
* @default null
|
|
27
|
-
*/
|
|
28
|
-
targetProductId?: string | null;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Creates a function that sends tracking events to the tracking API.
|
|
32
|
-
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
33
|
-
* @param env The environment to get the navigation url from . e.g. "local", "prod"
|
|
34
|
-
* @param createOptions Options for creating the tracking function.
|
|
35
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
36
|
-
*/
|
|
37
|
-
export declare function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a function that sends tracking events to the tracking API.
|
|
40
|
-
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
41
|
-
* @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
|
|
42
|
-
* @param createOptions Options for creating the tracking function.
|
|
43
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
44
|
-
*/
|
|
45
|
-
export declare function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__ from "./env.js";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__ from "./properties.js";
|
|
3
|
-
|
|
4
|
-
;// CONCATENATED MODULE: external "./env.js"
|
|
5
|
-
|
|
6
|
-
;// CONCATENATED MODULE: external "./properties.js"
|
|
7
|
-
|
|
8
|
-
;// CONCATENATED MODULE: ./src/createTrackingFunction.ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function createTrackingFunction(productId, envOrTrackingApiBaseUrl, createOptions = {}) {
|
|
12
|
-
const targetProductId = createOptions?.targetProductId ?? null;
|
|
13
|
-
const fullUrl = (0,__WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__.getTrackingEndpoint)(envOrTrackingApiBaseUrl);
|
|
14
|
-
return async (eventName, properties, options)=>{
|
|
15
|
-
const baseProperties = (0,__WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__.getBaseProperties)();
|
|
16
|
-
const allProperties = {
|
|
17
|
-
...baseProperties,
|
|
18
|
-
...properties
|
|
19
|
-
};
|
|
20
|
-
await fetch(fullUrl, {
|
|
21
|
-
method: "POST",
|
|
22
|
-
credentials: "include",
|
|
23
|
-
keepalive: options?.keepAlive,
|
|
24
|
-
headers: {
|
|
25
|
-
"Content-Type": "application/json"
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({
|
|
28
|
-
eventName,
|
|
29
|
-
productIdentifier: productId,
|
|
30
|
-
targetProductIdentifier: targetProductId,
|
|
31
|
-
properties: allProperties
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { createTrackingFunction };
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=createTrackingFunction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/createTrackingFunction.ts"],"sourcesContent":["import { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { getBaseProperties, type TrackEventProperties } from \"./properties.ts\";\n\nexport interface TrackingOptions {\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 */\nexport type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;\n\nexport interface CreateTrackingFunctionOptions {\n /**\n * The product identifier of the target product.\n * @default null\n */\n targetProductId?: string | null;\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param env The environment to get the navigation url from . e.g. \"local\", \"prod\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. \"https://api.platform.workleap-dev.com/shell/navigation/\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\nexport function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {\n const targetProductId = createOptions?.targetProductId ?? null;\n const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n\n return async (eventName, properties, options) => {\n const baseProperties = getBaseProperties();\n const allProperties = { ...baseProperties, ...properties };\n\n await fetch(fullUrl, {\n method: \"POST\",\n credentials: \"include\",\n keepalive: options?.keepAlive,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n eventName,\n productIdentifier: productId,\n targetProductIdentifier : targetProductId,\n properties: allProperties\n })\n });\n };\n}\n"],"names":["getTrackingEndpoint","getBaseProperties","createTrackingFunction","productId","envOrTrackingApiBaseUrl","createOptions","targetProductId","fullUrl","eventName","properties","options","baseProperties","allProperties","fetch","JSON"],"mappings":";;;;;;;;AAAiE;AACc;AAgDxE,SAASE,uBAAuBC,SAAiB,EAAEC,uBAAoD,EAAEC,gBAA+C,CAAC,CAAC;IAC7J,MAAMC,kBAAkBD,eAAe,mBAAmB;IAC1D,MAAME,UAAUP,oEAAmBA,CAACI;IAEpC,OAAO,OAAOI,WAAWC,YAAYC;QACjC,MAAMC,iBAAiBV,yEAAiBA;QACxC,MAAMW,gBAAgB;YAAE,GAAGD,cAAc;YAAE,GAAGF,UAAU;QAAC;QAEzD,MAAMI,MAAMN,SAAS;YACjB,QAAQ;YACR,aAAa;YACb,WAAWG,SAAS;YACpB,SAAS;gBAAE,gBAAgB;YAAmB;YAC9C,MAAMI,KAAK,SAAS,CAAC;gBACjBN;gBACA,mBAAmBL;gBACnB,yBAA0BG;gBAC1B,YAAYM;YAChB;QACJ;IACJ;AACJ"}
|
package/dist/env.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sources":["webpack://@workleap/mixpanel/./src/env.ts"],"sourcesContent":["\nconst EnvironmentList = [\"development\", \"staging\", \"production\", \"local\", \"msw\"] as const;\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 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;AAGhF,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;IACJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAc,kBAAkBE;AAC3C"}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack://@workleap/mixpanel/./src/index.ts"],"sourcesContent":["export * from \"./createTrackingFunction.ts\";\nexport type { Environment } from \"./env.ts\";\nexport type { TrackEventProperties } from \"./properties.ts\";\n\n"],"names":[],"mappings":";;;AAA4C"}
|
package/dist/properties.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type TrackEventProperties = Record<string, unknown>;
|
|
2
|
-
export declare function getBaseProperties(): {
|
|
3
|
-
$os: string;
|
|
4
|
-
$browser: string;
|
|
5
|
-
$referrer: string;
|
|
6
|
-
$referring_domain: string;
|
|
7
|
-
$device: string;
|
|
8
|
-
$current_url: string;
|
|
9
|
-
$browser_version: number | null;
|
|
10
|
-
$screen_height: number;
|
|
11
|
-
$screen_width: number;
|
|
12
|
-
IsMobile: boolean;
|
|
13
|
-
};
|
package/dist/properties.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
2
|
-
|
|
3
|
-
;// CONCATENATED MODULE: external "./utils.js"
|
|
4
|
-
|
|
5
|
-
;// CONCATENATED MODULE: ./src/properties.ts
|
|
6
|
-
|
|
7
|
-
const BaseTrackingProperties = {
|
|
8
|
-
AppVersion: "AppVersion",
|
|
9
|
-
Browser: "$browser",
|
|
10
|
-
BrowserVersion: "$browser_version",
|
|
11
|
-
CurrentUrl: "$current_url",
|
|
12
|
-
Device: "$device",
|
|
13
|
-
IsMobile: "IsMobile",
|
|
14
|
-
Os: "$os",
|
|
15
|
-
Referrer: "$referrer",
|
|
16
|
-
ReferringDomain: "$referring_domain",
|
|
17
|
-
ScreenHeight: "$screen_height",
|
|
18
|
-
ScreenWidth: "$screen_width"
|
|
19
|
-
};
|
|
20
|
-
function getBaseProperties() {
|
|
21
|
-
const userAgent = navigator.userAgent;
|
|
22
|
-
const device = (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.deviceType)(userAgent);
|
|
23
|
-
return {
|
|
24
|
-
[BaseTrackingProperties.Os]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.osName)(userAgent),
|
|
25
|
-
[BaseTrackingProperties.Browser]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.browserName)(userAgent, navigator.vendor),
|
|
26
|
-
[BaseTrackingProperties.Referrer]: document.referrer,
|
|
27
|
-
[BaseTrackingProperties.ReferringDomain]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.referringDomain)(document.referrer),
|
|
28
|
-
[BaseTrackingProperties.Device]: device,
|
|
29
|
-
[BaseTrackingProperties.CurrentUrl]: window.location.href,
|
|
30
|
-
[BaseTrackingProperties.BrowserVersion]: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.browserVersion)(userAgent, navigator.vendor),
|
|
31
|
-
[BaseTrackingProperties.ScreenHeight]: window.screen.height,
|
|
32
|
-
[BaseTrackingProperties.ScreenWidth]: window.screen.width,
|
|
33
|
-
[BaseTrackingProperties.IsMobile]: device.length > 0
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { getBaseProperties };
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=properties.js.map
|
package/dist/properties.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sources":["webpack://@workleap/mixpanel/./src/properties.ts"],"sourcesContent":["\nimport { browserName, browserVersion, deviceType, osName, referringDomain } from \"./utils.ts\";\n\nexport type TrackEventProperties = Record<string, unknown>;\n\nconst BaseTrackingProperties = {\n AppVersion: \"AppVersion\",\n Browser: \"$browser\",\n BrowserVersion: \"$browser_version\",\n CurrentUrl: \"$current_url\",\n Device: \"$device\",\n IsMobile: \"IsMobile\",\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 [BaseTrackingProperties.Os]: osName(userAgent),\n [BaseTrackingProperties.Browser]: browserName(userAgent, navigator.vendor),\n [BaseTrackingProperties.Referrer]: document.referrer,\n [BaseTrackingProperties.ReferringDomain]: referringDomain(document.referrer),\n [BaseTrackingProperties.Device]: device,\n [BaseTrackingProperties.CurrentUrl]: window.location.href,\n [BaseTrackingProperties.BrowserVersion]: browserVersion(userAgent, navigator.vendor),\n [BaseTrackingProperties.ScreenHeight]: window.screen.height,\n [BaseTrackingProperties.ScreenWidth]: window.screen.width,\n [BaseTrackingProperties.IsMobile]: device.length > 0\n } satisfies TrackEventProperties;\n}\n"],"names":["browserName","browserVersion","deviceType","osName","referringDomain","BaseTrackingProperties","getBaseProperties","userAgent","navigator","device","document","window"],"mappings":";;;;;AAC8F;AAI9F,MAAMK,yBAAyB;IAC3B,YAAY;IACZ,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,UAAU;IACV,iBAAiB;IACjB,cAAc;IACd,aAAa;AACjB;AAEO,SAASC;IACZ,MAAMC,YAAYC,UAAU,SAAS;IACrC,MAAMC,SAASP,6DAAUA,CAACK;IAE1B,OAAO;QACH,CAACF,uBAAuB,EAAE,CAAC,EAAEF,yDAAMA,CAACI;QACpC,CAACF,uBAAuB,OAAO,CAAC,EAAEL,8DAAWA,CAACO,WAAWC,UAAU,MAAM;QACzE,CAACH,uBAAuB,QAAQ,CAAC,EAAEK,SAAS,QAAQ;QACpD,CAACL,uBAAuB,eAAe,CAAC,EAAED,kEAAeA,CAACM,SAAS,QAAQ;QAC3E,CAACL,uBAAuB,MAAM,CAAC,EAAEI;QACjC,CAACJ,uBAAuB,UAAU,CAAC,EAAEM,OAAO,QAAQ,CAAC,IAAI;QACzD,CAACN,uBAAuB,cAAc,CAAC,EAAEJ,iEAAcA,CAACM,WAAWC,UAAU,MAAM;QACnF,CAACH,uBAAuB,YAAY,CAAC,EAAEM,OAAO,MAAM,CAAC,MAAM;QAC3D,CAACN,uBAAuB,WAAW,CAAC,EAAEM,OAAO,MAAM,CAAC,KAAK;QACzD,CAACN,uBAAuB,QAAQ,CAAC,EAAEI,OAAO,MAAM,GAAG;IACvD;AACJ"}
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["webpack://@workleap/mixpanel/./src/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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"}
|