You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-6Lines changed: 61 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,52 @@
1
1
# Telemetry Deck JavaScript SDK
2
2
3
-
This package allows you to send signals to [TelemetryDeck](https://telemetrydeck.com) from your JavaScript code.
3
+
This package allows you to send signals to [TelemetryDeck](https://telemetrydeck.com) from JavaScript code.
4
+
5
+
> [!NOTE]
6
+
> If you want to use TelemetryDeck for your blog or static website, we recommend the [TelemetryDeck Web SDK](https://github.com/TelemetryDeck/WebSDK) instead of this JavaScript SDK.
4
7
5
8
It has no dependencies and supports **modern evergreen browsers** and modern versions of Node.js with support for [cryptography](https://caniuse.com/cryptography).
6
9
7
-
Signals sent with this SDK do not send any default values, besides signal `type`, `appID`, `user` and `sessionID`.
10
+
## Usage
8
11
9
-
If you want to use this package in your web application, see recommended parameters below.
12
+
### Usage in Browser Based Applications that use a bundler (React, Vue, Angular, Svelte, Ember, …)
10
13
11
-
##Usage
14
+
#### 1. Install the package
12
15
13
-
### 📦 Advanced usage for applications that use a bundler (like Webpack, Rollup, …)
16
+
Please install the package using npm or the package manager of your choice
17
+
18
+
#### 2. Initialize TelemetryDeck
19
+
20
+
Initialize the TelemetryDeck SDK with your app ID and your user's user identifer.
21
+
22
+
```javascript
23
+
importTelemetryDeckfrom'@telemetrydeck/sdk';
24
+
25
+
consttd=newTelemetryDeck({
26
+
appID:'<YOUR_APP_ID>'
27
+
user:'<YOUR_USER_IDENTIFIER>',
28
+
});
29
+
```
30
+
31
+
Please replace `<YOUR_APP_ID>` with the app ID in TelemetryDeck ([Dashboard](https://dashboard.telemetrydeck.com) -> App -> Set Up App).
32
+
33
+
You also need to identify your logged in user. Instead of `<YOUR_USER_IDENTIFIER>`, pass in any string that uniquely identifies your user, such as an email address. It will be cryptographically anonymized with a hash function.
34
+
35
+
```javascript
36
+
// Basic signal
37
+
td.signal('<SIGNAL_TYPE>');
38
+
39
+
// Advanced: Signal with custom payload
40
+
td.signal('<SIGNAL_TYPE>', {
41
+
volume:'11',
42
+
});
43
+
```
44
+
45
+
46
+
47
+
If you want to pass optional parameters to the signal being sent, add them to the optional payload object.
48
+
49
+
### Usage in Node.js Applications
14
50
15
51
After installing the package via NPM, use it like this:
16
52
@@ -35,10 +71,29 @@ Please replace `YOUR_APP_ID` with the app ID you received from TelemetryDeck. If
35
71
36
72
If you want to pass optional parameters to the signal being sent, add them to the optional payload object.
37
73
38
-
## Usage with React Native
74
+
75
+
#### Usage with React Native
39
76
40
77
React Native does not support the `crypto` module, which is required for the SDK to work. We found [react-native-quick-crypto](https://github.com/margelo/react-native-quick-crypto) to be a suitable polyfill. Please note that this is not an officially supported solution.
41
78
79
+
80
+
## Advanced Initalization Options
81
+
82
+
See [Sauce](./src/telemetrydeck.js#L6-L15) for a full list of options.
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
### 📦 Advanced usage for applications that use a bundler (like Webpack, Rollup, …)
93
+
94
+
95
+
96
+
42
97
## Queueing Signals
43
98
44
99
The `TelemetryDeck` class comes with a built-in queuing mechanism for storing signals until they are flushed in a single request. Queued signals are sent with `receivedAt` prefilled with the time they were queued.
Copy file name to clipboardExpand all lines: src/telemetrydeck.js
+25-6Lines changed: 25 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,11 @@ import { version } from './utils/version.js';
9
9
* @property {string} appID the app ID to send telemetry data to
10
10
* @property {string} clientUser the clientUser ID to send telemetry data to
11
11
* @property {string} [target] the target URL to send telemetry data to
12
-
* @property {string} [sessionID]
13
-
* @property {string} [salt]
14
-
* @property {boolean} [testMode]
15
-
* @property {Store} [store]
12
+
* @property {string} [sessionID] An optional session ID to include in each signal
13
+
* @property {string} [salt] A salt to use when hashing the clientUser ID
14
+
* @property {boolean} [testMode] If "true", signals will be marked as test signals and only show up in Test Mode in the Dashbaord
15
+
* @property {Store} [store] A store to use for queueing signals
16
+
* @property {Function} [cryptoDigest] A function to use for calculating the SHA-256 hash of the clientUser ID. Null to use the browser's built-in crypto.subtle.digest function.
16
17
*/
17
18
18
19
exportdefaultclassTelemetryDeck{
@@ -27,7 +28,7 @@ export default class TelemetryDeck {
27
28
* @param {TelemetryDeckOptions} options
28
29
*/
29
30
constructor(options={}){
30
-
const{ target, appID, clientUser, sessionID, salt, testMode, store }=options;
0 commit comments