@leather.io/analytics 0.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Leather Wallet LLC [a subsidiary of Nassau Machines]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @leather/analytics
|
|
2
|
+
|
|
3
|
+
This package provides a client for sending analytics events to various analytics services. Currently, it supports Segment but could be extended to support other services in the future.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install @leather/analytics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Before making any analytics calls, you must configure the analytics client with your write key.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { configureAnalyticsClient } from '@leather.io/analytics';
|
|
17
|
+
|
|
18
|
+
configureAnalyticsClient({
|
|
19
|
+
writeKey: 'YOUR_WRITE_KEY',
|
|
20
|
+
defaultProperties: {
|
|
21
|
+
platform: 'web',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Now you can make analytics calls.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { analyticsClient } from '@leather/analytics';
|
|
30
|
+
|
|
31
|
+
analyticsClient.track('My Event', {
|
|
32
|
+
property: 'value',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can also inject your own analytics client if you are using a custom analytics service or want to use a stubbed client for testing.
|
|
37
|
+
|
|
38
|
+
````ts
|
|
39
|
+
import { configureAnalyticsClient } from '@leather/analytics';
|
|
40
|
+
|
|
41
|
+
configureAnalyticsClient({
|
|
42
|
+
client: myAnalyticsClient,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm build
|
|
49
|
+
````
|
|
50
|
+
|
|
51
|
+
or
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pnpm build:watch
|
|
55
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
interface DefaultProperties {
|
|
2
|
+
platform: 'web' | 'extension' | 'mobile';
|
|
3
|
+
}
|
|
4
|
+
interface ExternalAnalyticsClientInterface {
|
|
5
|
+
track: (event: string, properties?: Json) => Promise<void>;
|
|
6
|
+
screen: (name: string, properties?: Json) => Promise<void>;
|
|
7
|
+
group: (groupId: string, traits?: Json) => Promise<void>;
|
|
8
|
+
identify: (userId: string, traits?: Json) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
interface AnalyticsClientConfig {
|
|
11
|
+
writeKey: string;
|
|
12
|
+
client: ExternalAnalyticsClientInterface;
|
|
13
|
+
defaultProperties?: DefaultProperties;
|
|
14
|
+
defaultTraits?: Record<string, Json>;
|
|
15
|
+
}
|
|
16
|
+
type Json = Json[] | {
|
|
17
|
+
[index: number]: Json;
|
|
18
|
+
} | {
|
|
19
|
+
[key: string]: Json;
|
|
20
|
+
};
|
|
21
|
+
interface EventProperties {
|
|
22
|
+
background_analytics_schema_fail: undefined;
|
|
23
|
+
schema_fail: {
|
|
24
|
+
query: unknown;
|
|
25
|
+
hash: string;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
switch_account: {
|
|
29
|
+
index: number;
|
|
30
|
+
hasStxBalance: boolean;
|
|
31
|
+
};
|
|
32
|
+
view_transaction_confirmation: {
|
|
33
|
+
symbol: string;
|
|
34
|
+
};
|
|
35
|
+
ordinals_dot_com_unavailable: {
|
|
36
|
+
error: {
|
|
37
|
+
errorMessage: string;
|
|
38
|
+
errorName: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
select_maximum_amount_for_send: {
|
|
42
|
+
maximum: boolean;
|
|
43
|
+
};
|
|
44
|
+
copy_recipient_bns_address_to_clipboard: {
|
|
45
|
+
value: 'thing' | 'other-thing';
|
|
46
|
+
};
|
|
47
|
+
broadcast_transaction: {
|
|
48
|
+
symbol: string;
|
|
49
|
+
};
|
|
50
|
+
broadcast_btc_error: {
|
|
51
|
+
symbol: string;
|
|
52
|
+
error: {
|
|
53
|
+
errorMessage: string;
|
|
54
|
+
errorName: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
request_signature_cancel: undefined;
|
|
58
|
+
view_transaction_signing: undefined;
|
|
59
|
+
submit_fee_for_transaction: {
|
|
60
|
+
calculation: string;
|
|
61
|
+
fee: number | string;
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
request_update_profile_submit: {
|
|
65
|
+
requestType: 'update' | 'cancel';
|
|
66
|
+
};
|
|
67
|
+
request_update_profile_cancel: {
|
|
68
|
+
requestType: 'update' | 'cancel';
|
|
69
|
+
};
|
|
70
|
+
non_compliant_entity_detected: {
|
|
71
|
+
address: string;
|
|
72
|
+
};
|
|
73
|
+
requesting_origin_tab_closed_with_pending_action: {
|
|
74
|
+
status: 'action_pending';
|
|
75
|
+
};
|
|
76
|
+
native_segwit_tx_hex_to_ledger_tx: {
|
|
77
|
+
success: boolean;
|
|
78
|
+
};
|
|
79
|
+
psbt_sign_request: {
|
|
80
|
+
status: 'missing_taproot_internal_key';
|
|
81
|
+
};
|
|
82
|
+
ledger_nativesegwit_add_nonwitnessutxo: {
|
|
83
|
+
action: 'add_nonwitness_utxo' | 'skip_add_nonwitness_utxo';
|
|
84
|
+
};
|
|
85
|
+
redux_persist_migration_to_no_serialization: undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type AnalyticsClientOptions = Pick<AnalyticsClientConfig, 'defaultProperties' | 'defaultTraits'>;
|
|
89
|
+
declare function AnalyticsClient<T extends ExternalAnalyticsClientInterface>(client: T, options: AnalyticsClientOptions): {
|
|
90
|
+
track<K extends keyof EventProperties>(event: K, properties: EventProperties[K]): Promise<void>;
|
|
91
|
+
untypedTrack(event: string, properties?: Json): Promise<void>;
|
|
92
|
+
screen(name: string, properties?: Json): Promise<void>;
|
|
93
|
+
group(groupId: string, traits?: Json): Promise<void>;
|
|
94
|
+
identify(userId: string, traits?: Json): Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare let analyticsClient: ReturnType<typeof AnalyticsClient<ExternalAnalyticsClientInterface>>;
|
|
98
|
+
/**
|
|
99
|
+
* Configures the analytics client for the web environment. Must be called before any analytics functions are used.
|
|
100
|
+
* @param {AnalyticsClientConfig} config - The configuration for the analytics client.
|
|
101
|
+
* @returns {AnalyticsClient<AnalyticsClientInterface>} The configured analytics client.
|
|
102
|
+
*/
|
|
103
|
+
declare function configureAnalyticsClient({ client, defaultProperties }: AnalyticsClientConfig): {
|
|
104
|
+
track<K extends keyof EventProperties>(event: K, properties: EventProperties[K]): Promise<void>;
|
|
105
|
+
untypedTrack(event: string, properties?: Json): Promise<void>;
|
|
106
|
+
screen(name: string, properties?: Json): Promise<void>;
|
|
107
|
+
group(groupId: string, traits?: Json): Promise<void>;
|
|
108
|
+
identify(userId: string, traits?: Json): Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { analyticsClient, configureAnalyticsClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
function AnalyticsClient(client, options) {
|
|
3
|
+
return {
|
|
4
|
+
async track(event, properties) {
|
|
5
|
+
return client.track(event, { ...properties, ...options.defaultProperties });
|
|
6
|
+
},
|
|
7
|
+
async untypedTrack(event, properties) {
|
|
8
|
+
if (event.match(/^[a-zA-Z0-9\s][a-zA-Z0-9\s]*$/)) {
|
|
9
|
+
throw new Error("Event must be snake_case");
|
|
10
|
+
}
|
|
11
|
+
return client.track(event, { ...properties, ...options.defaultProperties });
|
|
12
|
+
},
|
|
13
|
+
async screen(name, properties) {
|
|
14
|
+
return client.screen(name, { ...properties, ...options.defaultProperties });
|
|
15
|
+
},
|
|
16
|
+
async group(groupId, traits) {
|
|
17
|
+
return client.group(groupId, { ...traits, ...options.defaultTraits });
|
|
18
|
+
},
|
|
19
|
+
async identify(userId, traits) {
|
|
20
|
+
return client.identify(userId, { ...traits, ...options.defaultTraits });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var analyticsClient;
|
|
27
|
+
function configureAnalyticsClient({ client, defaultProperties }) {
|
|
28
|
+
analyticsClient = AnalyticsClient(client, { defaultProperties });
|
|
29
|
+
return analyticsClient;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
analyticsClient,
|
|
33
|
+
configureAnalyticsClient
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"sourcesContent":["import {\n AnalyticsClientConfig,\n EventProperties,\n ExternalAnalyticsClientInterface,\n Json,\n} from './types';\n\nexport type AnalyticsClientOptions = Pick<\n AnalyticsClientConfig,\n 'defaultProperties' | 'defaultTraits'\n>;\n\nexport function AnalyticsClient<T extends ExternalAnalyticsClientInterface>(\n client: T,\n options: AnalyticsClientOptions\n) {\n return {\n async track<K extends keyof EventProperties>(event: K, properties: EventProperties[K]) {\n return client.track(event, { ...properties, ...options.defaultProperties });\n },\n\n async untypedTrack(event: string, properties?: Json) {\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 client.track(event as any, { ...properties, ...options.defaultProperties });\n },\n\n async screen(name: string, properties?: Json) {\n return client.screen(name, { ...properties, ...options.defaultProperties });\n },\n\n async group(groupId: string, traits?: Json) {\n return client.group(groupId, { ...traits, ...options.defaultTraits });\n },\n\n async identify(userId: string, traits?: Json) {\n return client.identify(userId, { ...traits, ...options.defaultTraits });\n },\n };\n}\n","import { AnalyticsClientConfig, ExternalAnalyticsClientInterface } from 'types';\n\nimport { AnalyticsClient } from './client';\n\nlet analyticsClient: ReturnType<typeof AnalyticsClient<ExternalAnalyticsClientInterface>>;\n\n/**\n * Configures the analytics client for the web environment. Must be called before any analytics functions are used.\n * @param {AnalyticsClientConfig} config - The configuration for the analytics client.\n * @returns {AnalyticsClient<AnalyticsClientInterface>} The configured analytics client.\n */\nexport function configureAnalyticsClient({ client, defaultProperties }: AnalyticsClientConfig) {\n analyticsClient = AnalyticsClient(client, { defaultProperties });\n\n return analyticsClient;\n}\n\nexport { analyticsClient };\n"],"mappings":";AAYO,SAAS,gBACd,QACA,SACA;AACA,SAAO;AAAA,IACL,MAAM,MAAuC,OAAU,YAAgC;AACrF,aAAO,OAAO,MAAM,OAAO,EAAE,GAAG,YAAY,GAAG,QAAQ,kBAAkB,CAAC;AAAA,IAC5E;AAAA,IAEA,MAAM,aAAa,OAAe,YAAmB;AACnD,UAAI,MAAM,MAAM,+BAA+B,GAAG;AAChD,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AACA,aAAO,OAAO,MAAM,OAAc,EAAE,GAAG,YAAY,GAAG,QAAQ,kBAAkB,CAAC;AAAA,IACnF;AAAA,IAEA,MAAM,OAAO,MAAc,YAAmB;AAC5C,aAAO,OAAO,OAAO,MAAM,EAAE,GAAG,YAAY,GAAG,QAAQ,kBAAkB,CAAC;AAAA,IAC5E;AAAA,IAEA,MAAM,MAAM,SAAiB,QAAe;AAC1C,aAAO,OAAO,MAAM,SAAS,EAAE,GAAG,QAAQ,GAAG,QAAQ,cAAc,CAAC;AAAA,IACtE;AAAA,IAEA,MAAM,SAAS,QAAgB,QAAe;AAC5C,aAAO,OAAO,SAAS,QAAQ,EAAE,GAAG,QAAQ,GAAG,QAAQ,cAAc,CAAC;AAAA,IACxE;AAAA,EACF;AACF;;;ACpCA,IAAI;AAOG,SAAS,yBAAyB,EAAE,QAAQ,kBAAkB,GAA0B;AAC7F,oBAAkB,gBAAgB,QAAQ,EAAE,kBAAkB,CAAC;AAE/D,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leather.io/analytics",
|
|
3
|
+
"author": "leather.io",
|
|
4
|
+
"description": "Analytics package for Leather using Segment",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/leather.io/mono/tree/dev/packages/analytics",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git@github.com:leather.io/mono.git",
|
|
11
|
+
"directory": "packages/analytics"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"import": "./index.js",
|
|
18
|
+
"require": "./index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "20.14.0",
|
|
23
|
+
"concurrently": "8.2.2",
|
|
24
|
+
"eslint": "8.53.0",
|
|
25
|
+
"eslint-config-universe": "12.0.0",
|
|
26
|
+
"prettier": "3.3.3",
|
|
27
|
+
"tsup": "8.1.0",
|
|
28
|
+
"typescript": "5.5.4",
|
|
29
|
+
"vitest": "2.0.5",
|
|
30
|
+
"@leather.io/eslint-config": "0.7.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"build:watch": "tsup --watch --onSuccess 'tsup --dts-only'",
|
|
41
|
+
"format": "prettier . --write \"src/**/*.ts\" --ignore-path ../../.prettierignore",
|
|
42
|
+
"format:check": "prettier . --check \"src/**/*.ts\" --ignore-path ../../.prettierignore",
|
|
43
|
+
"lint": "eslint . --ignore-path ../../.eslintignore",
|
|
44
|
+
"lint:fix": "eslint . --fix --ignore-path ../../.eslintignore",
|
|
45
|
+
"typecheck": "tsc --noEmit --project ./tsconfig.json"
|
|
46
|
+
}
|
|
47
|
+
}
|