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
@@ -63,19 +63,13 @@ Have feedback on Typewriter? Consider opening a [GitHub issue here](https://gith
63
63
64
64
## Prerequisites
65
65
66
-
Typewriter is built using [Node.js](https://nodejs.org/en/), and requires `node@8.x` or later, and `[email protected]` or later to function.
66
+
Typewriter is built using [Node.js](https://nodejs.org/en/), and requires node >= 14.x
67
67
68
68
You can check if you have Node and NPM installed by running the following commands in your command-line window:
69
69
70
70
```sh
71
71
$ node --version
72
-
v10.15.3
73
-
74
-
$ npm --version
75
-
6.9.0
76
-
77
-
$ npx --version
78
-
6.9.0
72
+
v14.x
79
73
```
80
74
81
75
If you don't have these, [you'll need to install `node`](https://nodejs.org/en/download/package-manager). Installing `node` also installs `npm` and `npx` for you. If you're on macOS, you can install it with [Homebrew](https://brew.sh/):
@@ -90,38 +84,62 @@ Once you've installed Node and NPM, run the `--version` commands again to verify
90
84
91
85
To get started with Typewriter in your browser:
92
86
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites) above.
93
-
2. Install `analytics.js` in your app. For now, you just need to complete [`Step 1: Copy the Snippet`](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet) from the [`analytics.js` Quickstart Guide](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/).
87
+
2. Install `analytics.js` in your app. There are two methods.
88
+
-**Snippet method (most common)**: Paste the snippet in the[`Step 1: Copy the Snippet`](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet) from the [`analytics.js` Quickstart Guide](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/).
89
+
-**NPM method**: Load analytics.js with the npm library. Learn more about using the npm method [here](https://github.com/segmentio/analytics-next/tree/master/packages/browser#readme).
90
+
94
91
3. Once you've got `analytics.js` installed, add Typewriter as a developer dependency in your project:
95
92
96
93
```sh
97
94
$ npm install --save-dev typewriter
98
95
```
99
-
100
-
4. Run `npx typewriter init` to use the Typewriter quickstart wizard that generates a [`typewriter.yml`](#configuration-reference) configuration, along with your first Typewriter client. When you run the command, it creates a `typewriter.yml` file in your project. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference).
101
-
96
+
4. If you are a snippet user that uses TypeScript, you should also install the npm library as a dev dependency to get the typescript types.
97
+
```sh
98
+
$ npm install --save-dev @segment/analytics-next
99
+
```
100
+
5. Run `npx typewriter init` to use the Typewriter quickstart wizard that generates a [`typewriter.yml`](#configuration-reference) configuration, along with your first Typewriter client. When you run the command, it creates a `typewriter.yml` file in your project. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference).
102
101
The command also adds a new Typewriter client in`./analytics` (or whichever path you configured). You can import this client into your project, like so:
> Run `npx typewriter` to regenerate your Typewriter client. You need to do this each time you update your Tracking Plan.
117
137
118
138
To help you minimize your bundle size, Typewriter supports [tree-shaking](https://webpack.js.org/guides/tree-shaking/){:target="_blank"} using named exports. All generated analytics calls generate and export automatically, so you can import them like so:
@@ -132,9 +150,9 @@ Typewriter wraps your analytics calls in an [ES6 `Proxy`](https://developer.mozi
132
150
133
151
## Node.js Quickstart
134
152
135
-
To get started with Nodejs:
153
+
To get started with Node.js:
136
154
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites) above.
137
-
2. Install `analytics-node` in your app. For now, you just need to complete [`Step 2: Install the Module`](/docs/connections/sources/catalog/libraries/server/node/quickstart/#step-2-install-the-module) from the [`analytics-node` Quickstart Guide](/docs/connections/sources/catalog/libraries/server/node/quickstart).
155
+
2. Install `@segment/analytics-node` in your app. For now, you just need to complete [`Step 2: Install the Module`](/docs/connections/sources/catalog/libraries/server/node/quickstart/#step-2-install-the-module) from the [`analytics-node` Quickstart Guide](/docs/connections/sources/catalog/libraries/server/node/quickstart).
138
156
3. Once you have `analytics-node` installed, add Typewriter as a developer dependency in your project:
139
157
140
158
```sh
@@ -143,13 +161,14 @@ To get started with Nodejs:
143
161
144
162
4. Run `npx typewriter init` to use the Typewriter quickstart wizard that generates a [`typewriter.yml`](#configuration-reference) configuration, along with your first Typewriter client. When you run the command, it creates a `typewriter.yml` file in your repo. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference). The command also adds a new Typewriter client in `./analytics` (or whichever path you configured). You can import this client into your project, like so:
145
163
146
-
```js
164
+
```ts
165
+
// Import your auto-generated Typewriter client.
166
+
import typewriter from './analytics'
167
+
147
168
// Initialize analytics-node, per the analytics-node guide above.
148
-
const Analytics = require('analytics-node')
149
-
const analytics = new Analytics('YOUR_WRITE_KEY')
169
+
import { Analytics } from '@segment/analytics-node'
150
170
151
-
// Import your auto-generated Typewriter client.
152
-
const typewriter = require('./analytics')
171
+
export const analytics = new Analytics({ writeKey: 'YOUR_WRITE_KEY' })
153
172
154
173
// Pass in your analytics-node instance to Typewriter.
155
174
typewriter.setTypewriterOptions({
@@ -330,7 +349,7 @@ Segment recommends you use a [Token Script](#token-script) to share an API token
330
349
Segment also recommends you to pipe through your API Token as this will let you keep your token secret, but it also allows you to share it across your team.
331
350
332
351
> warning ""
333
-
> Segment is keeping the Token Script execution for compatibility purposes only in v8 of Typewriter. Segment might deprecate this feature in the future, and encourages you to execute your script and pipe in the token. For example, `echo $TW_TOKEN | typewriter build`.
352
+
> Segment is temporarily keeping the Token Script execution for compatibility purposes. Segment might deprecate this feature in the future, and encourages you to execute your script and pipe in the token. For example, `echo $TW_TOKEN | typewriter build`.
334
353
335
354
## Editor Configuration
336
355
@@ -490,10 +509,10 @@ You can provide a custom handler that fires whenever a violation is seen. By def
490
509
491
510
For `analytics.js` and `analytics-node` clients, you can configure this handler with `setTypewriterOptions`:
A common use casefor this handler is to configure Typewriter to detect when your tests are running and if so, throw an error to fail your unit tests. For example:
0 commit comments