@leather.io/analytics 0.0.1 → 2.0.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/README.md +10 -19
- package/dist/index.d.ts +174 -80
- package/dist/index.js +15 -18
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -13,43 +13,34 @@ pnpm install @leather/analytics
|
|
|
13
13
|
Before making any analytics calls, you must configure the analytics client with your write key.
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { configureAnalyticsClient } from '@leather.io/analytics';
|
|
16
|
+
import { AnalyticsClientType, configureAnalyticsClient } from '@leather.io/analytics';
|
|
17
17
|
|
|
18
|
-
configureAnalyticsClient({
|
|
19
|
-
|
|
18
|
+
export const analytics: AnalyticsClientType = configureAnalyticsClient({
|
|
19
|
+
client: segmentClient,
|
|
20
20
|
defaultProperties: {
|
|
21
|
-
platform: '
|
|
21
|
+
platform: 'mobile',
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Now you can make analytics calls.
|
|
26
|
+
Now you can make analytics calls with your configured client.
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
import {
|
|
29
|
+
import { analytics } from 'path/to/analytics';
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
analytics.track('My Event', {
|
|
32
32
|
property: 'value',
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
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
36
|
## Development
|
|
46
37
|
|
|
47
|
-
```
|
|
38
|
+
```sh
|
|
48
39
|
pnpm build
|
|
49
|
-
|
|
40
|
+
```
|
|
50
41
|
|
|
51
42
|
or
|
|
52
43
|
|
|
53
|
-
```
|
|
44
|
+
```sh
|
|
54
45
|
pnpm build:watch
|
|
55
46
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,111 +1,205 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
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>;
|
|
1
|
+
interface Events extends HistoricalEvents {
|
|
2
|
+
test_event_submitted: undefined;
|
|
15
3
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
interface EventProperties {
|
|
22
|
-
background_analytics_schema_fail: undefined;
|
|
23
|
-
schema_fail: {
|
|
24
|
-
query: unknown;
|
|
25
|
-
hash: string;
|
|
26
|
-
error: string;
|
|
4
|
+
interface HistoricalEvents {
|
|
5
|
+
add_network: undefined;
|
|
6
|
+
bitcoin_rbf_fee_increase_error: {
|
|
7
|
+
outputDiff: number;
|
|
27
8
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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';
|
|
9
|
+
broadcast_retrieve_taproot_to_native_segwit: undefined;
|
|
10
|
+
broadcast_ordinal_transaction: undefined;
|
|
11
|
+
broadcast_ordinal_error: {
|
|
12
|
+
error: any;
|
|
46
13
|
};
|
|
47
14
|
broadcast_transaction: {
|
|
48
15
|
symbol: string;
|
|
16
|
+
amount?: number;
|
|
17
|
+
fee?: number;
|
|
18
|
+
inputs?: number;
|
|
19
|
+
outputs?: number;
|
|
49
20
|
};
|
|
50
21
|
broadcast_btc_error: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
22
|
+
error: any;
|
|
23
|
+
};
|
|
24
|
+
copy_btc_address_to_clipboard: {
|
|
25
|
+
type: string;
|
|
56
26
|
};
|
|
27
|
+
copy_secret_key_to_clipboard: undefined;
|
|
28
|
+
copy_address_to_add_new_inscription: undefined;
|
|
29
|
+
copy_stx_address_to_clipboard: undefined;
|
|
30
|
+
copy_recipient_bns_address_to_clipboard: undefined;
|
|
31
|
+
create_new_account: undefined;
|
|
32
|
+
change_network: {
|
|
33
|
+
id: string;
|
|
34
|
+
};
|
|
35
|
+
click_open_in_new_tab_menu_item: undefined;
|
|
36
|
+
click_change_network_menu_item: undefined;
|
|
37
|
+
click_change_theme_menu_item: undefined;
|
|
38
|
+
click_toggle_privacy: undefined;
|
|
39
|
+
request_psbt_cancel: undefined;
|
|
40
|
+
request_sign_psbt_submit: undefined;
|
|
41
|
+
request_update_profile_submit: undefined;
|
|
42
|
+
request_update_profile_cancel: undefined;
|
|
57
43
|
request_signature_cancel: undefined;
|
|
58
|
-
|
|
44
|
+
requesting_origin_tab_closed_with_pending_action: undefined;
|
|
45
|
+
select_add_new_collectible: undefined;
|
|
46
|
+
select_buy_option: {
|
|
47
|
+
provider: string;
|
|
48
|
+
};
|
|
49
|
+
select_theme: {
|
|
50
|
+
theme: string;
|
|
51
|
+
};
|
|
52
|
+
select_inscription_to_add_new_collectible: undefined;
|
|
53
|
+
select_maximum_amount_for_send: undefined;
|
|
54
|
+
submit_valid_password: undefined;
|
|
55
|
+
submit_invalid_password: undefined;
|
|
59
56
|
submit_fee_for_transaction: {
|
|
60
57
|
calculation: string;
|
|
61
58
|
fee: number | string;
|
|
62
59
|
type: string;
|
|
63
60
|
};
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
user_approved_send_transfer: {
|
|
62
|
+
origin: string;
|
|
63
|
+
};
|
|
64
|
+
user_approved_sign_and_broadcast_psbt: {
|
|
65
|
+
origin: string;
|
|
66
|
+
};
|
|
67
|
+
user_clicked_feedback_button: undefined;
|
|
68
|
+
unable_to_read_fee_in_stx_validator: undefined;
|
|
69
|
+
unable_to_read_available_balance_in_stx_validator: undefined;
|
|
70
|
+
view_bitcoin_transaction: undefined;
|
|
71
|
+
view_transaction: undefined;
|
|
72
|
+
view_collectibles: {
|
|
73
|
+
ordinals_count?: number;
|
|
74
|
+
stamps_count?: number;
|
|
75
|
+
stacks_nfts_count?: number;
|
|
76
|
+
};
|
|
77
|
+
view_rpc_send_transfer_confirmation: {
|
|
78
|
+
symbol: string;
|
|
79
|
+
};
|
|
80
|
+
view_rpc_sign_and_broadcast_psbt_confirmation: {
|
|
81
|
+
symbol: string;
|
|
82
|
+
};
|
|
83
|
+
view_transaction_confirmation: {
|
|
84
|
+
symbol: string;
|
|
85
|
+
};
|
|
86
|
+
view_transaction_signing: undefined;
|
|
87
|
+
view_transaction_signing_error: {
|
|
88
|
+
reason: string;
|
|
89
|
+
};
|
|
90
|
+
start_unlock: undefined;
|
|
91
|
+
complete_unlock: {
|
|
92
|
+
durationMs: number;
|
|
93
|
+
};
|
|
94
|
+
background_analytics_schema_fail: undefined;
|
|
95
|
+
new_brand_reveal_name: undefined;
|
|
96
|
+
new_brand_accept_terms: undefined;
|
|
97
|
+
new_brand_reject_terms: undefined;
|
|
98
|
+
lock_session: undefined;
|
|
99
|
+
remove_network: undefined;
|
|
100
|
+
generate_new_secret_key: undefined;
|
|
101
|
+
bitcoin_contract_error: {
|
|
102
|
+
msg: string;
|
|
103
|
+
};
|
|
104
|
+
ordinals_dot_com_unavailable: {
|
|
105
|
+
error: any;
|
|
66
106
|
};
|
|
67
|
-
|
|
68
|
-
|
|
107
|
+
schema_fail: {
|
|
108
|
+
query: any;
|
|
109
|
+
hash: string;
|
|
110
|
+
error: string;
|
|
111
|
+
};
|
|
112
|
+
request_signature_cannot_sign_message_no_account: undefined;
|
|
113
|
+
request_signature_sign: {
|
|
114
|
+
type: 'software' | 'ledger';
|
|
115
|
+
};
|
|
116
|
+
switch_account: {
|
|
117
|
+
index: number;
|
|
118
|
+
hasStxBalance: boolean;
|
|
69
119
|
};
|
|
70
120
|
non_compliant_entity_detected: {
|
|
71
|
-
address: string;
|
|
121
|
+
address: string | string[];
|
|
72
122
|
};
|
|
73
|
-
|
|
74
|
-
|
|
123
|
+
ledger_transaction_publish_error: {
|
|
124
|
+
error: {
|
|
125
|
+
message: string;
|
|
126
|
+
error: any;
|
|
127
|
+
};
|
|
75
128
|
};
|
|
76
129
|
native_segwit_tx_hex_to_ledger_tx: {
|
|
77
130
|
success: boolean;
|
|
78
131
|
};
|
|
79
|
-
|
|
80
|
-
status: 'missing_taproot_internal_key';
|
|
81
|
-
};
|
|
132
|
+
psbt_sign_request_p2tr_missing_taproot_internal_key: undefined;
|
|
82
133
|
ledger_nativesegwit_add_nonwitnessutxo: {
|
|
83
134
|
action: 'add_nonwitness_utxo' | 'skip_add_nonwitness_utxo';
|
|
84
135
|
};
|
|
136
|
+
submit_invalid_secret_key: undefined;
|
|
137
|
+
submit_valid_secret_key: undefined;
|
|
138
|
+
increase_fee_transaction: {
|
|
139
|
+
symbol: string;
|
|
140
|
+
txid: string;
|
|
141
|
+
};
|
|
142
|
+
finalize_tx_signature_error_thrown: {
|
|
143
|
+
data: unknown;
|
|
144
|
+
};
|
|
145
|
+
auth_response_with_illegal_redirect_uri: undefined;
|
|
85
146
|
redux_persist_migration_to_no_serialization: undefined;
|
|
147
|
+
sign_out: undefined;
|
|
148
|
+
ledger_app_version_info: {
|
|
149
|
+
info: object;
|
|
150
|
+
};
|
|
151
|
+
ledger_transaction_signed_approved: undefined;
|
|
152
|
+
ledger_transaction_signed_rejected: undefined;
|
|
153
|
+
ledger_message_signed_approved: undefined;
|
|
154
|
+
ledger_message_signed_rejected: undefined;
|
|
155
|
+
ledger_public_keys_pulled_from_device: undefined;
|
|
156
|
+
user_clicked_requested_by_link: {
|
|
157
|
+
endpoint: string;
|
|
158
|
+
};
|
|
159
|
+
user_approved_get_addresses: {
|
|
160
|
+
origin: string;
|
|
161
|
+
};
|
|
162
|
+
user_approved_message_signing: {
|
|
163
|
+
origin: string;
|
|
164
|
+
};
|
|
86
165
|
}
|
|
166
|
+
type EventName = keyof Events;
|
|
87
167
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
screen(name: string,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
168
|
+
interface DefaultProperties {
|
|
169
|
+
platform: 'web' | 'extension' | 'mobile';
|
|
170
|
+
}
|
|
171
|
+
interface AnalyticsClientInterface {
|
|
172
|
+
screen: (name: string, ...args: any[]) => Promise<any>;
|
|
173
|
+
track: (event: string, ...args: any[]) => Promise<any>;
|
|
174
|
+
group: (groupId: string, traits?: any, ...args: any[]) => Promise<any>;
|
|
175
|
+
identify: (...args: any[]) => Promise<any>;
|
|
176
|
+
page?: (name: string, ...args: any[]) => Promise<any>;
|
|
177
|
+
}
|
|
178
|
+
interface AnalyticsClientConfig<T extends AnalyticsClientInterface> {
|
|
179
|
+
client: T;
|
|
180
|
+
defaultProperties?: DefaultProperties;
|
|
181
|
+
defaultTraits?: JsonMap;
|
|
182
|
+
}
|
|
183
|
+
type JsonList = JsonValue[];
|
|
184
|
+
type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined | unknown | Error;
|
|
185
|
+
interface JsonMap {
|
|
186
|
+
[key: string]: JsonValue;
|
|
187
|
+
[index: number]: JsonValue;
|
|
188
|
+
}
|
|
189
|
+
type OptionalIfUndefined<T> = T extends undefined ? undefined : T;
|
|
96
190
|
|
|
97
|
-
declare
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
191
|
+
declare function configureAnalyticsClient<T extends AnalyticsClientInterface>({ client, defaultProperties, defaultTraits, }: {
|
|
192
|
+
client: T;
|
|
193
|
+
defaultProperties: DefaultProperties;
|
|
194
|
+
defaultTraits?: JsonMap;
|
|
195
|
+
}): {
|
|
196
|
+
track<K extends keyof Events>(event: K, ...properties: undefined extends Events[K] ? [] : [param: Events[K]]): Promise<any>;
|
|
197
|
+
untypedTrack(event: string, properties?: JsonMap): Promise<any>;
|
|
198
|
+
screen: (name: string, ...args: any[]) => Promise<any>;
|
|
199
|
+
group: (groupId: string, traits?: any, ...args: any[]) => Promise<any>;
|
|
200
|
+
identify: (...args: any[]) => Promise<any>;
|
|
201
|
+
page: (name: string, ...args: any[]) => Promise<any>;
|
|
202
|
+
client: T;
|
|
109
203
|
};
|
|
110
204
|
|
|
111
|
-
export {
|
|
205
|
+
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,35 +1,32 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
function AnalyticsClient(
|
|
2
|
+
function AnalyticsClient(analyticsClient, options) {
|
|
3
3
|
return {
|
|
4
|
-
async track(event, properties) {
|
|
5
|
-
return
|
|
4
|
+
async track(event, ...properties) {
|
|
5
|
+
return analyticsClient.track(event, { ...properties, ...options.defaultProperties });
|
|
6
6
|
},
|
|
7
7
|
async untypedTrack(event, properties) {
|
|
8
8
|
if (event.match(/^[a-zA-Z0-9\s][a-zA-Z0-9\s]*$/)) {
|
|
9
9
|
throw new Error("Event must be snake_case");
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return analyticsClient.track(event, { ...properties, ...options.defaultProperties });
|
|
12
12
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
async identify(userId, traits) {
|
|
20
|
-
return client.identify(userId, { ...traits, ...options.defaultTraits });
|
|
21
|
-
}
|
|
13
|
+
screen: analyticsClient.screen,
|
|
14
|
+
group: analyticsClient.group,
|
|
15
|
+
identify: analyticsClient.identify,
|
|
16
|
+
page: analyticsClient.page ? analyticsClient.page : () => Promise.resolve(),
|
|
17
|
+
client: analyticsClient
|
|
22
18
|
};
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
// src/index.ts
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
function configureAnalyticsClient({
|
|
23
|
+
client,
|
|
24
|
+
defaultProperties,
|
|
25
|
+
defaultTraits
|
|
26
|
+
}) {
|
|
27
|
+
return AnalyticsClient(client, { defaultProperties, defaultTraits });
|
|
30
28
|
}
|
|
31
29
|
export {
|
|
32
|
-
analyticsClient,
|
|
33
30
|
configureAnalyticsClient
|
|
34
31
|
};
|
|
35
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"sourcesContent":["import {
|
|
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 analyticsClient: T,\n options: Pick<AnalyticsClientConfig<T>, 'defaultProperties' | 'defaultTraits'>\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, ...options.defaultProperties });\n },\n async untypedTrack(event: string, properties?: JsonMap) {\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, { ...properties, ...options.defaultProperties });\n },\n screen: analyticsClient.screen,\n group: analyticsClient.group,\n identify: analyticsClient.identify,\n page: analyticsClient.page ? analyticsClient.page : () => Promise.resolve(),\n client: analyticsClient,\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,iBACA,SACA;AACA,SAAO;AAAA,IACL,MAAM,MACJ,UACG,YACH;AACA,aAAO,gBAAgB,MAAM,OAAO,EAAE,GAAG,YAAY,GAAG,QAAQ,kBAAkB,CAAC;AAAA,IACrF;AAAA,IACA,MAAM,aAAa,OAAe,YAAsB;AACtD,UAAI,MAAM,MAAM,+BAA+B,GAAG;AAChD,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AACA,aAAO,gBAAgB,MAAM,OAAc,EAAE,GAAG,YAAY,GAAG,QAAQ,kBAAkB,CAAC;AAAA,IAC5F;AAAA,IACA,QAAQ,gBAAgB;AAAA,IACxB,OAAO,gBAAgB;AAAA,IACvB,UAAU,gBAAgB;AAAA,IAC1B,MAAM,gBAAgB,OAAO,gBAAgB,OAAO,MAAM,QAAQ,QAAQ;AAAA,IAC1E,QAAQ;AAAA,EACV;AACF;;;ACpBO,SAAS,yBAA6D;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SAAO,gBAAmB,QAAQ,EAAE,mBAAmB,cAAc,CAAC;AACxE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leather.io/analytics",
|
|
3
|
-
"author": "leather.io",
|
|
3
|
+
"author": "Leather.io contact@leather.io",
|
|
4
4
|
"description": "Analytics package for Leather using Segment",
|
|
5
|
-
"version": "0.0
|
|
5
|
+
"version": "2.0.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/leather.io/mono/tree/dev/packages/analytics",
|
|
8
8
|
"repository": {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"types": "./index.d.ts",
|
|
17
|
-
"import": "./index.js",
|
|
18
|
-
"require": "./index.js"
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"bitcoin",
|
|
37
|
+
"leather",
|
|
38
|
+
"leather wallet"
|
|
39
|
+
],
|
|
35
40
|
"publishConfig": {
|
|
36
41
|
"access": "public"
|
|
37
42
|
},
|
|
@@ -42,6 +47,6 @@
|
|
|
42
47
|
"format:check": "prettier . --check \"src/**/*.ts\" --ignore-path ../../.prettierignore",
|
|
43
48
|
"lint": "eslint . --ignore-path ../../.eslintignore",
|
|
44
49
|
"lint:fix": "eslint . --fix --ignore-path ../../.eslintignore",
|
|
45
|
-
"typecheck": "tsc --noEmit
|
|
50
|
+
"typecheck": "tsc --noEmit"
|
|
46
51
|
}
|
|
47
52
|
}
|