@dashgram/react 1.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 +26 -0
- package/README.md +188 -0
- package/dist/hooks.d.ts +12 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +120 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +64 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dashgram
|
|
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.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Dashgram React SDK
|
|
2
|
+
|
|
3
|
+
React SDK for **Telegram Mini Apps**. Track user interactions and send events to Dashgram analytics.
|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> This SDK is for **Telegram Mini Apps** built with React. For vanilla JavaScript or other frameworks, see our [other SDKs](https://docs.dashgram.io/sdk).
|
|
7
|
+
|
|
8
|
+
## Quick Start
|
|
9
|
+
|
|
10
|
+
### 1. Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @dashgram/react
|
|
14
|
+
# or
|
|
15
|
+
pnpm add @dashgram/react
|
|
16
|
+
# or
|
|
17
|
+
yarn add @dashgram/react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 2. Basic Setup
|
|
21
|
+
|
|
22
|
+
Wrap your app with `DashgramProvider`:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { DashgramProvider } from "@dashgram/react"
|
|
26
|
+
|
|
27
|
+
export function App() {
|
|
28
|
+
return (
|
|
29
|
+
<DashgramProvider projectId="your-project-id" trackLevel={2}>
|
|
30
|
+
...
|
|
31
|
+
</DashgramProvider>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Configuration:**
|
|
37
|
+
|
|
38
|
+
- `projectId` — Your project identifier from the [Dashgram dashboard](https://app.dashgram.io). Get it after creating a project.
|
|
39
|
+
- `trackLevel` — Controls which events are automatically captured. See [Track Levels](#track-levels) section below for details.
|
|
40
|
+
|
|
41
|
+
### 3. Track custom events (optional)
|
|
42
|
+
|
|
43
|
+
If you want to send custom events to Dashgram, use the useTrackEvent hook.
|
|
44
|
+
Simply call it with an event name and optional properties whenever the action happens.
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { useTrackEvent } from "@dashgram/react"
|
|
48
|
+
|
|
49
|
+
export function Button() {
|
|
50
|
+
const track = useTrackEvent()
|
|
51
|
+
|
|
52
|
+
const handleClick = () => {
|
|
53
|
+
track("button_click", { label: "Buy" })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return <button onClick={handleClick}>Click me</button>
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Track Levels
|
|
61
|
+
|
|
62
|
+
Choose how much data to collect. Higher levels capture more events but send more data.
|
|
63
|
+
|
|
64
|
+
### Level 1 — Core
|
|
65
|
+
|
|
66
|
+
**Minimal tracking** — Basic app lifecycle events only.
|
|
67
|
+
|
|
68
|
+
| Event | Description |
|
|
69
|
+
| ----------- | --------------------------------- |
|
|
70
|
+
| `app_open` | Mini App opened or became visible |
|
|
71
|
+
| `app_close` | Mini App closed or hidden |
|
|
72
|
+
|
|
73
|
+
**Use when:** You only need basic usage metrics.
|
|
74
|
+
|
|
75
|
+
### Level 2 — Interactions
|
|
76
|
+
|
|
77
|
+
**Standard tracking** — Level 1 + user interactions.
|
|
78
|
+
|
|
79
|
+
| Event | Description |
|
|
80
|
+
| --------------------- | -------------------------------- |
|
|
81
|
+
| `screen_view` | Page/route navigation |
|
|
82
|
+
| `button_click` | Button clicks |
|
|
83
|
+
| `link_click` | Link clicks (external detection) |
|
|
84
|
+
| `form_submit` | Form submissions |
|
|
85
|
+
| `input_focus` | Input field focus |
|
|
86
|
+
| `input_change` | Input field value changed |
|
|
87
|
+
| `copy` | Text copied to clipboard |
|
|
88
|
+
| `cut` | Text cut to clipboard |
|
|
89
|
+
| `paste` | Text pasted from clipboard |
|
|
90
|
+
| `text_select` | Text selection |
|
|
91
|
+
| `js_error` | JavaScript errors |
|
|
92
|
+
| `unhandled_rejection` | Unhandled Promise rejections |
|
|
93
|
+
|
|
94
|
+
**Use when:** You want standard web analytics (recommended for most apps).
|
|
95
|
+
|
|
96
|
+
### Level 3 — Deep Analytics
|
|
97
|
+
|
|
98
|
+
**Comprehensive tracking** — Level 1 + 2 + performance metrics + all Telegram events.
|
|
99
|
+
|
|
100
|
+
| Event | Description |
|
|
101
|
+
| -------------------------------- | ------------------------------ |
|
|
102
|
+
| `scroll_depth` | Scroll milestone reached |
|
|
103
|
+
| `element_visible` | Tracked element became visible |
|
|
104
|
+
| `rage_click` | Rapid repeated clicks |
|
|
105
|
+
| `long_task` | JS task >50ms |
|
|
106
|
+
| `web_vital_lcp` | Largest Contentful Paint |
|
|
107
|
+
| `web_vital_fid` | First Input Delay |
|
|
108
|
+
| `web_vital_cls` | Cumulative Layout Shift |
|
|
109
|
+
| `network_status` | Online/offline status |
|
|
110
|
+
| `orientation_change` | Device orientation change |
|
|
111
|
+
| `media_play/pause/ended` | Video/audio events |
|
|
112
|
+
| `telegram_theme_changed` | Telegram theme change |
|
|
113
|
+
| `telegram_viewport_changed` | Viewport size change |
|
|
114
|
+
| `telegram_main_button_clicked` | Main button pressed |
|
|
115
|
+
| `telegram_back_button_clicked` | Back button pressed |
|
|
116
|
+
| `telegram_invoice_closed` | Invoice closed |
|
|
117
|
+
| ...and all other Telegram events | |
|
|
118
|
+
|
|
119
|
+
**Use when:** You need detailed performance monitoring and all Telegram WebApp events.
|
|
120
|
+
|
|
121
|
+
## API Reference
|
|
122
|
+
|
|
123
|
+
### `<DashgramProvider>`
|
|
124
|
+
|
|
125
|
+
Provider component that initializes the SDK.
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<DashgramProvider projectId="your-project-id" trackLevel={2} debug={false} disabled={false}>
|
|
129
|
+
<YourApp />
|
|
130
|
+
</DashgramProvider>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Props:**
|
|
134
|
+
|
|
135
|
+
- `projectId` — **Required.** Your project ID from [Dashgram dashboard](https://app.dashgram.io)
|
|
136
|
+
- `trackLevel` — Event collection level: `1`, `2`, or `3` (default: `2`)
|
|
137
|
+
- `debug` — Enable debug logging (default: `false`)
|
|
138
|
+
- `disabled` — Disable all tracking (default: `false`)
|
|
139
|
+
|
|
140
|
+
### `useTrackEvent()`
|
|
141
|
+
|
|
142
|
+
Hook that returns a function to track custom events with optional properties.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
const track = useTrackEvent()
|
|
146
|
+
|
|
147
|
+
track("purchase_completed", {
|
|
148
|
+
product_id: "premium-plan",
|
|
149
|
+
price: 100,
|
|
150
|
+
currency: "TON"
|
|
151
|
+
})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Parameters:**
|
|
155
|
+
|
|
156
|
+
- `event` — Event name (string)
|
|
157
|
+
- `properties` — Optional event properties (object)
|
|
158
|
+
|
|
159
|
+
### `useDashgram()`
|
|
160
|
+
|
|
161
|
+
Hook to access the SDK instance.
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
const { track, isInitialized, flush } = useDashgram()
|
|
165
|
+
|
|
166
|
+
track("event_name")
|
|
167
|
+
await flush()
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `usePageView(pageName, properties?)`
|
|
171
|
+
|
|
172
|
+
Track page views for SPA routing.
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
usePageView("home_page", { section: "landing" })
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
Contributions are welcome! Please open issues or pull requests on the [GitHub repository](https://github.com/dashgram/dashgram-javascript).
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
This project is licensed under the MIT License. See the LICENSE file for more information.
|
|
185
|
+
|
|
186
|
+
## Contact
|
|
187
|
+
|
|
188
|
+
For questions or support, reach out to us at [team@dashgram.io](mailto:team@dashgram.io) or visit our [website](https://dashgram.io).
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FormEvent } from "react";
|
|
2
|
+
import type { DashgramContextValue } from "./types";
|
|
3
|
+
export declare function useDashgram(): DashgramContextValue;
|
|
4
|
+
export declare function useTrackMount(event: string, properties?: Record<string, any>): void;
|
|
5
|
+
export declare function useTrackUnmount(event: string, properties?: Record<string, any>): void;
|
|
6
|
+
export declare function useScreenTracking(): void;
|
|
7
|
+
export declare function useTrackClick(event: string, properties?: Record<string, any>): () => void;
|
|
8
|
+
export declare function useTrackSubmit(event: string, properties?: Record<string, any>): (e: FormEvent<HTMLFormElement>) => void;
|
|
9
|
+
export declare function useTrackEvent(): (event: string, properties?: Record<string, any>) => void;
|
|
10
|
+
export declare function useAutoTrack(componentName: string, properties?: Record<string, any>): void;
|
|
11
|
+
export declare function usePageView(pageName: string, properties?: Record<string, any>): void;
|
|
12
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAoBnD,wBAAgB,WAAW,IAAI,oBAAoB,CAQlD;AAKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAUnF;AAKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAUrF;AAaD,wBAAgB,iBAAiB,IAAI,IAAI,CAsCxC;AAWD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,IAAI,CAMzF;AAWD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/B,CAAC,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,KAAK,IAAI,CAMzC;AAcD,wBAAgB,aAAa,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAQzF;AAiBD,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAoB1F;AAsBD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAqBpF"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef } from "react";
|
|
2
|
+
import { DashgramContext } from "./provider";
|
|
3
|
+
let useLocation = null;
|
|
4
|
+
try {
|
|
5
|
+
if (typeof require !== "undefined" && require) {
|
|
6
|
+
const router = require("react-router-dom");
|
|
7
|
+
useLocation = router.useLocation;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
}
|
|
12
|
+
export function useDashgram() {
|
|
13
|
+
const context = useContext(DashgramContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error("useDashgram must be used within DashgramProvider");
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
export function useTrackMount(event, properties) {
|
|
20
|
+
const { track, isInitialized } = useDashgram();
|
|
21
|
+
const hasTracked = useRef(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (isInitialized && !hasTracked.current) {
|
|
24
|
+
track(event, properties);
|
|
25
|
+
hasTracked.current = true;
|
|
26
|
+
}
|
|
27
|
+
}, [isInitialized, event, properties, track]);
|
|
28
|
+
}
|
|
29
|
+
export function useTrackUnmount(event, properties) {
|
|
30
|
+
const { track, isInitialized } = useDashgram();
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
if (isInitialized) {
|
|
34
|
+
track(event, properties);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, [isInitialized, event, properties, track]);
|
|
38
|
+
}
|
|
39
|
+
export function useScreenTracking() {
|
|
40
|
+
const { track, isInitialized } = useDashgram();
|
|
41
|
+
if (!useLocation) {
|
|
42
|
+
const isDev = typeof process !== "undefined" && process?.env?.NODE_ENV !== "production";
|
|
43
|
+
if (isDev) {
|
|
44
|
+
console.warn("Dashgram: useScreenTracking requires react-router-dom. " + "Install it or use manual screen tracking.");
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const location = useLocation();
|
|
49
|
+
const previousPath = useRef("");
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!isInitialized) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const currentPath = location.pathname;
|
|
55
|
+
if (currentPath === previousPath.current) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
previousPath.current = currentPath;
|
|
59
|
+
track("screen_view", {
|
|
60
|
+
path: currentPath,
|
|
61
|
+
search: location.search,
|
|
62
|
+
hash: location.hash,
|
|
63
|
+
state: location.state
|
|
64
|
+
});
|
|
65
|
+
}, [location, isInitialized, track]);
|
|
66
|
+
}
|
|
67
|
+
export function useTrackClick(event, properties) {
|
|
68
|
+
const { track } = useDashgram();
|
|
69
|
+
return () => {
|
|
70
|
+
track(event, properties);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function useTrackSubmit(event, properties) {
|
|
74
|
+
const { track } = useDashgram();
|
|
75
|
+
return (_e) => {
|
|
76
|
+
track(event, properties);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function useTrackEvent() {
|
|
80
|
+
const { track, isInitialized } = useDashgram();
|
|
81
|
+
return (event, properties) => {
|
|
82
|
+
if (isInitialized) {
|
|
83
|
+
track(event, properties);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function useAutoTrack(componentName, properties) {
|
|
88
|
+
const { track, isInitialized } = useDashgram();
|
|
89
|
+
const hasTrackedMount = useRef(false);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (isInitialized && !hasTrackedMount.current) {
|
|
92
|
+
track(`${componentName}_mounted`, properties);
|
|
93
|
+
hasTrackedMount.current = true;
|
|
94
|
+
}
|
|
95
|
+
}, [isInitialized, componentName, properties, track]);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
return () => {
|
|
98
|
+
if (isInitialized) {
|
|
99
|
+
track(`${componentName}_unmounted`, properties);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}, [isInitialized, componentName, properties, track]);
|
|
103
|
+
}
|
|
104
|
+
export function usePageView(pageName, properties) {
|
|
105
|
+
const { track, isInitialized } = useDashgram();
|
|
106
|
+
const previousPage = useRef("");
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!isInitialized) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (pageName === previousPage.current) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
previousPage.current = pageName;
|
|
115
|
+
track("page_view", {
|
|
116
|
+
page: pageName,
|
|
117
|
+
...properties
|
|
118
|
+
});
|
|
119
|
+
}, [isInitialized, pageName, properties, track]);
|
|
120
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DashgramProvider, DashgramContext } from "./provider";
|
|
2
|
+
export type { DashgramProviderProps } from "./provider";
|
|
3
|
+
export { useDashgram, useTrackEvent, useTrackMount, useTrackUnmount, useScreenTracking, usePageView, useAutoTrack, useTrackClick, useTrackSubmit } from "./hooks";
|
|
4
|
+
export type { DashgramContextValue, DashgramConfig, EventProperties, TrackLevel } from "./types";
|
|
5
|
+
export { default as DashgramMini } from "@dashgram/javascript";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGhG,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { DashgramProvider, DashgramContext } from "./provider";
|
|
2
|
+
export { useDashgram, useTrackEvent, useTrackMount, useTrackUnmount, useScreenTracking, usePageView, useAutoTrack, useTrackClick, useTrackSubmit } from "./hooks";
|
|
3
|
+
export { default as DashgramMini } from "@dashgram/javascript";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { DashgramConfig } from "@dashgram/javascript";
|
|
3
|
+
import type { DashgramContextValue } from "./types";
|
|
4
|
+
export declare const DashgramContext: React.Context<DashgramContextValue | null>;
|
|
5
|
+
export interface DashgramProviderProps extends DashgramConfig {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare function DashgramProvider({ children, projectId, trackLevel, apiUrl, batchSize, flushInterval, debug, disabled, onError }: DashgramProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnD,eAAO,MAAM,eAAe,4CAAmD,CAAA;AAK/E,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAKD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,UAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,KAAK,EACL,QAAQ,EACR,OAAO,EACR,EAAE,qBAAqB,2CAmEvB"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useEffect, useRef, useState } from "react";
|
|
3
|
+
import DashgramMini from "@dashgram/javascript";
|
|
4
|
+
export const DashgramContext = createContext(null);
|
|
5
|
+
export function DashgramProvider({ children, projectId, trackLevel = 2, apiUrl, batchSize, flushInterval, debug, disabled, onError }) {
|
|
6
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
7
|
+
const [currentTrackLevel, setCurrentTrackLevel] = useState(trackLevel);
|
|
8
|
+
const initRef = useRef(false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (initRef.current) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
initRef.current = true;
|
|
14
|
+
try {
|
|
15
|
+
DashgramMini.init({
|
|
16
|
+
projectId,
|
|
17
|
+
trackLevel,
|
|
18
|
+
apiUrl,
|
|
19
|
+
batchSize,
|
|
20
|
+
flushInterval,
|
|
21
|
+
debug,
|
|
22
|
+
disabled,
|
|
23
|
+
onError
|
|
24
|
+
});
|
|
25
|
+
setIsInitialized(true);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error("Dashgram: Failed to initialize", error);
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
DashgramMini.shutdown();
|
|
32
|
+
};
|
|
33
|
+
}, [projectId, trackLevel, apiUrl, batchSize, flushInterval, debug, disabled, onError]);
|
|
34
|
+
const value = {
|
|
35
|
+
track: (event, properties) => {
|
|
36
|
+
if (isInitialized) {
|
|
37
|
+
DashgramMini.track(event, properties);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
isInitialized,
|
|
41
|
+
flush: async () => {
|
|
42
|
+
if (isInitialized) {
|
|
43
|
+
await DashgramMini.flush();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
setTrackLevel: level => {
|
|
47
|
+
if (isInitialized) {
|
|
48
|
+
DashgramMini.setTrackLevel(level);
|
|
49
|
+
setCurrentTrackLevel(level);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
getTrackLevel: () => {
|
|
53
|
+
return currentTrackLevel;
|
|
54
|
+
},
|
|
55
|
+
shutdown: () => {
|
|
56
|
+
if (isInitialized) {
|
|
57
|
+
DashgramMini.shutdown();
|
|
58
|
+
setIsInitialized(false);
|
|
59
|
+
initRef.current = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return _jsx(DashgramContext.Provider, { value: value, children: children });
|
|
64
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DashgramConfig, EventProperties, TrackLevel } from "@dashgram/javascript";
|
|
2
|
+
export type { DashgramConfig, EventProperties, TrackLevel };
|
|
3
|
+
export interface DashgramContextValue {
|
|
4
|
+
track: (event: string, properties?: EventProperties) => void;
|
|
5
|
+
isInitialized: boolean;
|
|
6
|
+
flush: () => Promise<void>;
|
|
7
|
+
setTrackLevel: (level: TrackLevel) => void;
|
|
8
|
+
getTrackLevel: () => TrackLevel | undefined;
|
|
9
|
+
shutdown: () => void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEvF,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,CAAA;AAK3D,MAAM,WAAW,oBAAoB;IAEnC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,eAAe,KAAK,IAAI,CAAA;IAG5D,aAAa,EAAE,OAAO,CAAA;IAGtB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAG1B,aAAa,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IAG1C,aAAa,EAAE,MAAM,UAAU,GAAG,SAAS,CAAA;IAG3C,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dashgram/react",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React wrapper for Dashgram Analytics SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"dev": "tsc --watch",
|
|
14
|
+
"type-check": "tsc --noEmit",
|
|
15
|
+
"test": "echo \"Tests require @testing-library/react and jest. See README for setup.\""
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"dashgram",
|
|
19
|
+
"analytics",
|
|
20
|
+
"react",
|
|
21
|
+
"telegram",
|
|
22
|
+
"mini-apps"
|
|
23
|
+
],
|
|
24
|
+
"author": "Dashgram",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/dashgram/dashgram-react.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/dashgram/dashgram-react/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://dashgram.io",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"react-router-dom": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@dashgram/javascript": "*"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.0.0",
|
|
47
|
+
"@types/react": "^18.2.0",
|
|
48
|
+
"react": "^18.2.0",
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
|
+
}
|
|
51
|
+
}
|