Skip to content

Commit 6bafe73

Browse files
committed
Standalone SDK: Package for Browser and Node.js
- BREAKING: Removed UMD compatibility - BREAKING: No longer works in browsers that do not support ESM. - BREAKING: Does not ingest signals stored on `window.td` - BREAKING: Changed default export to Class - BREAKING: Does not instantiate itself when used in browser context - BREAKING: Removed methods for updating AppID, user - Uses API v2 - Replace Jest with Ava
1 parent 8bfd433 commit 6bafe73

22 files changed

+2069
-2998
lines changed

.eslintrc.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
browser: true,
5+
},
6+
globals: {
7+
globalThis: true,
8+
},
9+
plugins: ['prettier', 'unicorn', 'ava'],
10+
extends: [
11+
'eslint:recommended',
12+
'plugin:prettier/recommended',
13+
'plugin:unicorn/recommended',
14+
'plugin:ava/recommended',
15+
],
16+
rules: {
17+
'unicorn/prefer-module': 'off',
18+
},
19+
};

.eslintrc.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

.prettierrc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

.prettierrc.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
singleQuote = true
2+
printWidth = 100
3+
trailingComma = "es5"

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
3+
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
4+
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Programm starten",
11+
"program": "${workspaceFolder}/node_modules/ava/entrypoints/cli.mjs",
12+
"args": ["--serial", "${file}"],
13+
"outputCapture": "std",
14+
"console": "integratedTerminal", // optional
15+
"skipFiles": ["<node_internals>/**/*.js"]
16+
}
17+
]
18+
}

README.md

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,21 @@ Test Mode is currently not supported.
1717

1818
## Usage
1919

20-
### 📄 Usage via Script tag
21-
22-
For websites and to try out the code quickly, you can use [UNPKG](https://unpkg.com), a free CDN which allows you to load files from any npm package.
23-
24-
Include the following snippet inside the `<head>` of your HTML page:
25-
26-
```html
27-
<script src="https://unpkg.com/@telemetrydeck/sdk/dist/telemetrydeck.min.js" defer></script>
28-
```
29-
30-
Then add a second script tag after it like this to send a signal once every time the page loads:
31-
32-
```html
33-
<script>
34-
window.td = window.td || [];
35-
td.push(['app', YOUR_APP_ID], ['user', USER_IDENTIFIER], ['signal']);
36-
</script>
37-
```
38-
39-
Please replace `YOUR_APP_ID` with the app ID you received from TelemetryDeck, and `USER_IDENTIFIER` with a user identifier. If you have none, consider `anonymous`.
40-
41-
You can add as many signals as you need to track different interactions with your page. Once the page and script are fully loaded, signals will be sent immediately.
42-
43-
#### Alternative usage for more complex tracking needs
44-
45-
```html
46-
<script>
47-
// Required: queue setup
48-
td = window.td || [];
49-
// Required: Set your application id
50-
td.push(['app', YOUR_APP_ID]);
51-
// Required: Set a user idenfitier. `anonymous` is a recommended default
52-
td.push(['user', USER_IDENTIFIER ?? 'anonymous']);
53-
54-
// Custom payload sent with the signal
55-
td.push(['signal']);
56-
td.push([
57-
'signal',
58-
{
59-
route: 'some/page/path',
60-
},
61-
]);
62-
</script>
63-
```
64-
6520
### 📦 Advanced usage for applications that use a bundler (like Webpack, Rollup, …)
6621

6722
After installing the package via NPM, use it like this:
6823

6924
```js
70-
import { TelemetryDeck } from '@telemetrydeck/sdk';
25+
import TelemetryDeck from '@telemetrydeck/sdk';
7126

72-
const td = new TelemetryDeck({ app: YOUR_APP_ID, user: YOUR_USER_IDENTIFIER });
27+
const td = new TelemetryDeck({ appID: YOUR_APP_ID, user: YOUR_USER_IDENTIFIER });
7328

7429
// Basic signal
75-
td.signal();
30+
td.signal('<SIGNAL_TYPE>');
7631

7732
// Adanced: Signal with custom payload
78-
td.signal({
79-
route: 'some/page/path',
33+
td.signal('<SIGNAL_TYPE>',{
34+
volume: '11',
8035
});
8136

8237
```
@@ -85,26 +40,6 @@ Please replace `YOUR_APP_ID` with the app ID you received from TelemetryDeck. If
8540

8641
If you want to pass optional parameters to the signal being sent, add them to the optional payload object.
8742

88-
You can also update your user identifier or queue events like this:
89-
90-
```js
91-
// Optional: Update app or user identifier
92-
td.app(YOUR_NEW_APP_ID);
93-
td.user(YOUR_NEW_USER_IDENTIFIER);
94-
95-
// Optional: Process any events that have been qeued up
96-
// Queued signals do not contain a client side timestamp and will be timestamped
97-
// on the server at the time of arrival. Consider adding a timestamp value to
98-
// your payloads if you need to be able to correlate them.
99-
const queuedEvents = [
100-
['app', YOUR_APP_ID],
101-
['user', YOUR_USER_IDENTIFIER],
102-
['signal'],
103-
['signal', { route: 'some/page/path' }],
104-
];
105-
td.ingest(qeuedEvents);
106-
```
107-
10843
## More Info
10944

11045
### 📱 You need an App ID

ava.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
files: ['tests/**/*.test.js'],
3+
nodeArguments: ['--experimental-json-modules'],
4+
};

jest.config.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

jest.setup.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
{
22
"name": "@telemetrydeck/sdk",
3-
"version": "1.0.5",
3+
"version": "2.0.0",
44
"description": "Send analytics signals to TelemetryDeck",
55
"main": "dist/telemetrydeck.js",
66
"module": "dist/telemetrydeck.mjs",
7+
"files": [
8+
"dist/*",
9+
"README.md",
10+
"CHANGELOG.md",
11+
"LICENSE"
12+
],
713
"scripts": {
814
"build": "rollup -c",
915
"changelog": "lerna-changelog",
1016
"lint:fix": "eslint . --fix",
1117
"lint": "eslint . --cache",
1218
"prepublish": "rollup -c",
1319
"release": "dotenv release-it --",
14-
"test:watch": "jest --watch",
15-
"test": "jest"
20+
"test": "ava",
21+
"test:watch": "ava --watch"
1622
},
1723
"repository": {
1824
"type": "git",
1925
"url": "git+https://github.com/TelemetryDeck/JavaScriptSDK.git"
2026
},
2127
"private": false,
28+
"type": "commonjs",
2229
"publishConfig": {
2330
"access": "public"
2431
},
@@ -38,22 +45,21 @@
3845
},
3946
"homepage": "https://github.com/TelemetryDeck/JavaScriptSDK#readme",
4047
"devDependencies": {
41-
"@rollup/plugin-json": "^4.1.0",
42-
"dotenv-cli": "^4.1.1",
43-
"eslint": "^8.6.0",
44-
"eslint-config-prettier": "^8.3.0",
45-
"eslint-plugin-jest": "^25.3.4",
46-
"eslint-plugin-prettier": "^4.0.0",
47-
"eslint-plugin-unicorn": "^40.0.0",
48-
"jest": "^27.4.7",
49-
"jest-fetch-mock": "^3.0.3",
48+
"@rollup/plugin-commonjs": "^25.0.3",
49+
"@rollup/plugin-replace": "^5.0.2",
50+
"ava": "^5.3.1",
51+
"dotenv-cli": "^7.2.1",
52+
"eslint": "^8.45.0",
53+
"eslint-config-prettier": "^8.8.0",
54+
"eslint-plugin-ava": "^14.0.0",
55+
"eslint-plugin-prettier": "^5.0.0",
56+
"eslint-plugin-unicorn": "^48.0.0",
5057
"lerna-changelog": "^2.2.0",
51-
"prettier": "^2.5.1",
58+
"prettier": "^3.0.0",
5259
"release-it": "^14.12.1",
5360
"release-it-lerna-changelog": "^4.0.1",
54-
"rollup": "^2.63.0",
55-
"rollup-jest": "^1.1.3",
56-
"rollup-plugin-terser": "^7.0.2",
61+
"rollup": "^3.26.3",
62+
"sinon": "^15.2.0",
5763
"typescript": "^4.5.4"
5864
}
5965
}

0 commit comments

Comments
 (0)