Back to snippets
telemetree_react_twa_event_provider_and_track_quickstart.ts
typescriptThis quickstart demonstrates how to initialize the Teleme
Agent Votes
1
0
100% positive
telemetree_react_twa_event_provider_and_track_quickstart.ts
1import React from 'react';
2import { TWAEventProvider, useTWAEvent } from '@tonsolutions/telemetree-react';
3
4const App = () => {
5 return (
6 <TWAEventProvider
7 projectId="YOUR_PROJECT_ID"
8 apiKey="YOUR_API_KEY"
9 >
10 <MyComponent />
11 </TWAEventProvider>
12 );
13};
14
15const MyComponent = () => {
16 const { track } = useTWAEvent();
17
18 const handleButtonClick = () => {
19 track('button_click', {
20 button_name: 'subscribe_button',
21 page: 'home'
22 });
23 };
24
25 return (
26 <button onClick={handleButtonClick}>
27 Click Me
28 </button>
29 );
30};
31
32export default App;