@leather.io/analytics 3.3.2 → 3.4.0
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/dist/index.d.ts +7 -7
- package/dist/index.js +32 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -210,7 +210,7 @@ interface AnalyticsClientInterface {
|
|
|
210
210
|
track: (event: string, ...args: any[]) => Promise<any>;
|
|
211
211
|
group: (groupId: string, traits?: any, ...args: any[]) => Promise<any>;
|
|
212
212
|
identify: (...args: any[]) => Promise<any>;
|
|
213
|
-
page?: (name
|
|
213
|
+
page?: (category?: string, name?: string, ...args: any[]) => Promise<any>;
|
|
214
214
|
}
|
|
215
215
|
interface AnalyticsClientConfig<T extends AnalyticsClientInterface> {
|
|
216
216
|
client: T;
|
|
@@ -231,12 +231,12 @@ declare function configureAnalyticsClient<T extends AnalyticsClientInterface>({
|
|
|
231
231
|
defaultTraits?: JsonMap;
|
|
232
232
|
}): {
|
|
233
233
|
track<K extends keyof Events>(event: K, ...properties: undefined extends Events[K] ? [] : [param: Events[K]]): Promise<any>;
|
|
234
|
-
untypedTrack(event: string, properties?: JsonMap): Promise<any>;
|
|
235
|
-
screen
|
|
236
|
-
group
|
|
237
|
-
identify
|
|
238
|
-
page
|
|
239
|
-
client:
|
|
234
|
+
untypedTrack(event: string, properties?: JsonMap | Record<string, unknown>): Promise<any>;
|
|
235
|
+
screen(name: string, properties?: JsonMap | Record<string, unknown>): Promise<any>;
|
|
236
|
+
group(groupId: string, traits?: JsonMap | Record<string, unknown>): Promise<any>;
|
|
237
|
+
identify(userId?: string, traits?: JsonMap | Record<string, unknown>): Promise<any>;
|
|
238
|
+
page(category?: string, name?: string, properties?: JsonMap | Record<string, unknown>): Promise<any>;
|
|
239
|
+
readonly client: T_1;
|
|
240
240
|
};
|
|
241
241
|
|
|
242
242
|
export { type AnalyticsClientConfig, type AnalyticsClientInterface, type DefaultProperties, type EventName, type Events, type JsonList, type JsonMap, type JsonValue, type OptionalIfUndefined, configureAnalyticsClient };
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,43 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
function AnalyticsClient(
|
|
2
|
+
function AnalyticsClient(config) {
|
|
3
|
+
const { client: analyticsClient, defaultProperties = {}, defaultTraits = {} } = config;
|
|
3
4
|
return {
|
|
4
5
|
async track(event, ...properties) {
|
|
5
|
-
return analyticsClient.track(event, { ...properties, ...
|
|
6
|
+
return analyticsClient.track(event, { ...properties, ...defaultProperties });
|
|
6
7
|
},
|
|
7
8
|
async untypedTrack(event, properties) {
|
|
8
9
|
if (event.match(/^[a-zA-Z0-9\s][a-zA-Z0-9\s]*$/)) {
|
|
9
10
|
throw new Error("Event must be snake_case");
|
|
10
11
|
}
|
|
11
|
-
return analyticsClient.track(event, {
|
|
12
|
+
return analyticsClient.track(event, {
|
|
13
|
+
...properties,
|
|
14
|
+
...defaultProperties
|
|
15
|
+
});
|
|
12
16
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
async screen(name, properties) {
|
|
18
|
+
return analyticsClient.screen(name, { ...properties, ...defaultProperties });
|
|
19
|
+
},
|
|
20
|
+
group(groupId, traits) {
|
|
21
|
+
return analyticsClient.group(groupId, { ...traits, ...defaultTraits });
|
|
22
|
+
},
|
|
23
|
+
async identify(userId, traits) {
|
|
24
|
+
return await analyticsClient.identify(userId, {
|
|
25
|
+
...traits,
|
|
26
|
+
...defaultTraits
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
page(category, name, properties) {
|
|
30
|
+
if (typeof analyticsClient.page === "function") {
|
|
31
|
+
return analyticsClient.page(category, name, {
|
|
32
|
+
...properties,
|
|
33
|
+
...defaultProperties
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return Promise.resolve();
|
|
37
|
+
},
|
|
38
|
+
get client() {
|
|
39
|
+
return analyticsClient;
|
|
40
|
+
}
|
|
18
41
|
};
|
|
19
42
|
}
|
|
20
43
|
|
|
@@ -24,7 +47,7 @@ function configureAnalyticsClient({
|
|
|
24
47
|
defaultProperties,
|
|
25
48
|
defaultTraits
|
|
26
49
|
}) {
|
|
27
|
-
return AnalyticsClient(client,
|
|
50
|
+
return AnalyticsClient({ client, defaultProperties, defaultTraits });
|
|
28
51
|
}
|
|
29
52
|
export {
|
|
30
53
|
configureAnalyticsClient
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"sourcesContent":["import { AnalyticsClientConfig, AnalyticsClientInterface, Events, JsonMap } from './types';\n\nexport function AnalyticsClient<T extends AnalyticsClientInterface>(\n
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"sourcesContent":["import { AnalyticsClientConfig, AnalyticsClientInterface, Events, JsonMap } from './types';\n\nexport function AnalyticsClient<T extends AnalyticsClientInterface>(\n config: AnalyticsClientConfig<T>\n) {\n const { client: analyticsClient, defaultProperties = {}, defaultTraits = {} } = config;\n\n return {\n async track<K extends keyof Events>(\n event: K,\n ...properties: undefined extends Events[K] ? [] : [param: Events[K]]\n ) {\n return analyticsClient.track(event, { ...properties, ...defaultProperties });\n },\n\n async untypedTrack(event: string, properties?: JsonMap | Record<string, unknown>) {\n if (event.match(/^[a-zA-Z0-9\\s][a-zA-Z0-9\\s]*$/)) {\n throw new Error('Event must be snake_case');\n }\n return analyticsClient.track(event as any, {\n ...properties,\n ...defaultProperties,\n });\n },\n\n async screen(name: string, properties?: JsonMap | Record<string, unknown>) {\n return analyticsClient.screen(name, { ...properties, ...defaultProperties });\n },\n\n group(groupId: string, traits?: JsonMap | Record<string, unknown>) {\n return analyticsClient.group(groupId, { ...traits, ...defaultTraits });\n },\n\n async identify(userId?: string, traits?: JsonMap | Record<string, unknown>) {\n return await analyticsClient.identify(userId, {\n ...traits,\n ...defaultTraits,\n });\n },\n\n page(category?: string, name?: string, properties?: JsonMap | Record<string, unknown>) {\n if (typeof analyticsClient.page === 'function') {\n return analyticsClient.page(category, name, {\n ...properties,\n ...defaultProperties,\n });\n }\n return Promise.resolve();\n },\n\n get client() {\n return analyticsClient;\n },\n };\n}\n","import { AnalyticsClient } from './client';\nimport { AnalyticsClientInterface, DefaultProperties, JsonMap } from './types';\n\nexport * from './types';\n\nexport function configureAnalyticsClient<T extends AnalyticsClientInterface>({\n client,\n defaultProperties,\n defaultTraits,\n}: {\n client: T;\n defaultProperties: DefaultProperties;\n defaultTraits?: JsonMap;\n}) {\n return AnalyticsClient<T>({ client, defaultProperties, defaultTraits });\n}\n"],"mappings":";AAEO,SAAS,gBACd,QACA;AACA,QAAM,EAAE,QAAQ,iBAAiB,oBAAoB,CAAC,GAAG,gBAAgB,CAAC,EAAE,IAAI;AAEhF,SAAO;AAAA,IACL,MAAM,MACJ,UACG,YACH;AACA,aAAO,gBAAgB,MAAM,OAAO,EAAE,GAAG,YAAY,GAAG,kBAAkB,CAAC;AAAA,IAC7E;AAAA,IAEA,MAAM,aAAa,OAAe,YAAgD;AAChF,UAAI,MAAM,MAAM,+BAA+B,GAAG;AAChD,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AACA,aAAO,gBAAgB,MAAM,OAAc;AAAA,QACzC,GAAG;AAAA,QACH,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,OAAO,MAAc,YAAgD;AACzE,aAAO,gBAAgB,OAAO,MAAM,EAAE,GAAG,YAAY,GAAG,kBAAkB,CAAC;AAAA,IAC7E;AAAA,IAEA,MAAM,SAAiB,QAA4C;AACjE,aAAO,gBAAgB,MAAM,SAAS,EAAE,GAAG,QAAQ,GAAG,cAAc,CAAC;AAAA,IACvE;AAAA,IAEA,MAAM,SAAS,QAAiB,QAA4C;AAC1E,aAAO,MAAM,gBAAgB,SAAS,QAAQ;AAAA,QAC5C,GAAG;AAAA,QACH,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AAAA,IAEA,KAAK,UAAmB,MAAe,YAAgD;AACrF,UAAI,OAAO,gBAAgB,SAAS,YAAY;AAC9C,eAAO,gBAAgB,KAAK,UAAU,MAAM;AAAA,UAC1C,GAAG;AAAA,UACH,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AACA,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,IAEA,IAAI,SAAS;AACX,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ACjDO,SAAS,yBAA6D;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SAAO,gBAAmB,EAAE,QAAQ,mBAAmB,cAAc,CAAC;AACxE;","names":[]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@leather.io/analytics",
|
|
3
3
|
"author": "Leather.io contact@leather.io",
|
|
4
4
|
"description": "Analytics package for Leather using Segment",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.4.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/leather.io/mono/tree/dev/packages/analytics",
|
|
8
8
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"tsup": "8.1.0",
|
|
26
26
|
"typescript": "5.7.3",
|
|
27
27
|
"vitest": "2.1.9",
|
|
28
|
-
"@leather.io/models": "0.
|
|
28
|
+
"@leather.io/models": "0.30.0"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist"
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"build:watch": "tsup --watch --onSuccess 'tsup --dts-only'",
|
|
44
44
|
"format": "prettier . --write \"src/**/*.ts\" --ignore-path ../../.prettierignore",
|
|
45
45
|
"format:check": "prettier . --check \"src/**/*.ts\" --ignore-path ../../.prettierignore",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest watch",
|
|
46
48
|
"typecheck": "tsc --noEmit"
|
|
47
49
|
}
|
|
48
50
|
}
|