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
> Typewriter for analytics.js and analytics-node will receive no new features and only critical maintenance updates from Segment. Typewriter for other libraries and SDKs are not actively maintained by Segment. Typewriter is available on [GitHub](https://github.com/segmentio/typewriter/){:target="_blank”} under the MIT license for the open-source community to fork and contribute.
7
+
> Typewriter for Analytics.js and Analytics-Node will receive no new features and only critical maintenance updates from Segment. Typewriter for other libraries and SDKs are not actively maintained by Segment. Typewriter is available on [GitHub](https://github.com/segmentio/typewriter/){:target="_blank”} under the MIT license for the open-source community to fork and contribute.
8
8
9
9
[Typewriter](https://github.com/segmentio/typewriter){:target="_blank”} is a tool for generating strongly-typed Segment analytics libraries based on your pre-defined [Tracking Plan](/docs/protocols/tracking-plan) spec.
10
10
11
11
At a high-level, Typewriter can take an event from your Tracking Plan like this `"Order Completed"` event:
12
12
13
13

14
14
15
-
Typewriter uses the event to generate a typed analytics call in different languages:
15
+
Typewriter uses the event to generate a typed Analytics call in different languages:
> Typewriter can generate clients for `analytics.js`, `analytics-node`, `analytics-swift` and `analytics-kotlin`.
36
36
37
-
These generated clients are embedded with metadata from your Tracking Plan, which contextualizes your analytics instrumentation, and reduces (or entirely eliminates!) incorrect instrumentations in your production environments. In your editor, you can access event names, descriptions, property names, types and more:
37
+
These generated clients are embedded with metadata from your Tracking Plan, which contextualizes your analytics instrumentation, and reduces (or entirely eliminates) incorrect instrumentations in your production environments. In your editor, you can access event names, descriptions, property names, types and more:
38
38
39
-

39
+

40
40
41
41
You can also configure Typewriter to validate analytic events at runtime, which can alert you to instrumentation errors during development and testing. Typewriter can warn you about missing required properties, invalid enum values, regex mismatches, and any other advanced [JSON Schema](https://json-schema.org/understanding-json-schema/) you configure in your Tracking Plan.
42
42
@@ -46,11 +46,11 @@ You can use this with a test suite to automatically fail your unit tests if the
46
46
47
47

48
48
49
-
If you use a statically typed language (such as TypeScript, Java, Objective-C, or Swift), you get access to compile-time warnings about your instrumentation:
49
+
If you use a statically typed language (like TypeScript, Java, Objective-C, or Swift), you get access to compile-time warnings about your instrumentation:
Typewriter also helps teams adopt [analytics best practices](/docs/protocols/tracking-plan/best-practices/), such as avoiding autogenerated event names, and carefully considering what properties are tracked.
53
+
Typewriter also helps teams adopt [Analytics best practices](/docs/protocols/tracking-plan/best-practices/), like avoiding autogenerated event names and carefully considering what properties are tracked.
54
54
55
55
To get started, check out one of the quickstart guides below:
56
56
-[Browser Quickstart](#browser-quickstart)
@@ -66,7 +66,7 @@ Have feedback on Typewriter? Consider opening a [GitHub Issue in the @segmentio/
66
66
67
67
## Prerequisites
68
68
69
-
Typewriter is built using [Node.js](https://nodejs.org/en/){:target="_blank”}, and requires node >= 14.x
69
+
Typewriter is built using [Node.js](https://nodejs.org/en/){:target="_blank”}, and requires node >= 14.x.
70
70
71
71
You can check if you have Node and NPM installed by running the following commands in your command-line window:
72
72
@@ -83,11 +83,11 @@ $ brew install node
83
83
84
84
Once you've installed Node and NPM, run the `--version` commands again to verify that they were installed correctly.
85
85
86
-
## Browser Quickstart
86
+
## Browser quickstart
87
87
88
88
To get started with Typewriter in your browser:
89
-
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites) above.
90
-
2. Install `analytics.js` in your app. There are two methods.
89
+
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites).
90
+
2. Install `analytics.js` in your app using one of the following methods:
91
91
-**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/).
92
92
-**NPM method**: Load analytics.js with the npm library. Learn more about using the npm method in the [@segmentio/analytics-next](https://github.com/segmentio/analytics-next/tree/master/packages/browser#readme){:target="_blank”} repository.
93
93
@@ -138,7 +138,7 @@ To get started with Typewriter in your browser:
138
138
> info ""
139
139
> Run `npx typewriter` to regenerate your Typewriter client. You need to do this each time you update your Tracking Plan.
140
140
141
-
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:
141
+
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 this:
142
142
143
143
```ts
144
144
import { orderCompleted } from './analytics'
@@ -149,20 +149,20 @@ orderCompleted({
149
149
})
150
150
```
151
151
152
-
Typewriter wraps your analytics calls in an [ES6 `Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy){:target="_blank"}, which helps protect your application from crashing if you make analytics calls with a generated functionthat doesn't exist. For example, if an `Order Completed` event didn't exist in your Tracking Plan in the first example above, then your app would crash with a `TypeError: typewriter.orderCompleted is not a function`. However, since Typewriter dynamically proxies the underlying functioncalls, it can detect if a functiondoesn't exist, and handle it foryou. Typewriter logs a warning message, then fires an `Unknown Analytics Call Fired` event into your source. This helps to prevent regressions when you migrate JavaScript projects to Typewriterin bulk. Keep in mind that proxying doesn't work with named exports.
152
+
Typewriter wraps your analytics calls in an [ES6 `Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy){:target="_blank"}, which helps protect your application from crashing if you make analytics calls with a generated functionthat doesn't exist. For example, if an `Order Completed` event didn't exist in your Tracking Plan in the first example above, then your app would crash with a `TypeError: typewriter.orderCompleted is not a function` error. However, since Typewriter dynamically proxies the underlying functioncalls, it can detect if a functiondoesn't exist, and handle it foryou. Typewriter logs a warning message, then fires an `Unknown Analytics Call Fired` event into your source. This helps to prevent regressions when you migrate JavaScript projects to Typewriterin bulk. Keep in mind that proxying doesn't work with named exports.
153
153
154
-
## Node.js Quickstart
154
+
## Node.js quickstart
155
155
156
156
To get started with Node.js:
157
-
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites) above.
157
+
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites).
158
158
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).
159
159
3. Once you have `analytics-node` installed, add Typewriter as a developer dependency in your project:
160
160
161
161
```sh
162
162
$ npm install --save-dev typewriter
163
163
```
164
164
165
-
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:
165
+
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 repository. 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:
166
166
167
167
```ts
168
168
// Initialize analytics-node, per the analytics-node guide above.
@@ -193,15 +193,15 @@ To get started with Node.js:
193
193
194
194
Typewriter wraps your analytics calls in an [ES6 `Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy){:target="_blank”}, which helps protect your application from crashing if you make analytics calls with a generated function that doesn't exist. For example, if an `Order Completed` event didn't exist in your Tracking Plan in the first example above, then your app would crash with a `TypeError: typewriter.orderCompleted is not a function`. However, since `typewriter` dynamically proxies the underlying function calls, it can detect if a function does not exist, and handle it for you. Typewriter logs a warning message, then fires an `Unknown Analytics Call Fired` event into your source. This helps to prevent regressions when you migrate JavaScript projects to Typewriter in bulk. Keep in mind that proxying doesn't work with named exports.
195
195
196
-
## Swift Quickstart
196
+
## Swift quickstart
197
197
198
198
> info ""
199
199
> For use with the `analytics-ios` SDK, use [Typewriter v7](/docs/protocols/apis-and-extensions/typewriter-v7).
200
200
201
201
To get started using Typewriter with Swift:
202
-
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites) above.
202
+
1. Make sure you have `node` installed using the instructions in the [prerequisites](#prerequisites).
203
203
2. Install `analytics-swift`in your app. Follow the [analytics-swift Quickstart Guide](/docs/connections/sources/catalog/libraries/mobile/swift).
204
-
3. 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).
204
+
3. 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 repository. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference).
205
205
206
206
<br>**Note:** Run `npx typewriter` to regenerate your Typewriter client. You need to do this each time you update your Tracking Plan.
207
207
@@ -216,15 +216,15 @@ To get started using Typewriter with Swift:
216
216
))
217
217
```
218
218
219
-
## Kotlin Quickstart
219
+
## Kotlin quickstart
220
220
221
221
> info ""
222
222
> For use with the `analytics-android` SDK, use [Typewriter v7](/docs/protocols/apis-and-extensions/typewriter-v7).
223
223
224
224
To get started using Typewriter with Kotlin:
225
-
1. Make sure you have `node` installed. Use the instructions in the [prerequisites](#prerequisites) above.
225
+
1. Make sure you have `node` installed. Use the instructions in the [prerequisites](#prerequisites).
226
226
2. Install `analytics-kotlin`in your app. Follow the [analytics-kotlin QuickStart Guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/#getting-started).
227
-
3. Run `npx typewriter init`. This command enables you to use the Typewriter quickstart wizard that generates a [`typewriter.yml`](#configuration-reference) configuration, along with your first Typewriter client. The command creates a `typewriter.yml` file in your repo. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference).
227
+
3. Run `npx typewriter init`. This command enables you to use the Typewriter quickstart wizard that generates a [`typewriter.yml`](#configuration-reference) configuration, along with your first Typewriter client. The command creates a `typewriter.yml` file in your repository. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference).
228
228
229
229
Typewriter creates the class file with the package name `typewriter`. Segment recommends you to enter the right package name during `npx typewriter init` by choosing to review the Advanced Options forKotlin. You can also enter the right package name directlyin`typewriter.yml`:
230
230
@@ -234,19 +234,21 @@ To get started using Typewriter with Kotlin:
234
234
sdk: kotlin
235
235
languageOptions:
236
236
package: com.segment.typewriter
237
-
```
237
+
```
238
238
239
239
> info ""
240
240
> Run `npx typewriter` to regenerate your Typewriter client. You need to do this each time you update your Tracking Plan.
241
241
242
242
You can now use your Typewriter client in your Android Kotlin or Java application as extensions to any `Analytics` object:
243
243
244
244
Kotlin:
245
+
245
246
```kotlin
246
247
// Import your auto-generated Typewriter client:
247
248
import com.segment.generated.*
248
249
analytics.orderCompleted(OrderCompleted(orderID = "110", total = 39.98))
1. Follow the [Getting Started guide for React Native](/docs/connections/sources/catalog/libraries/mobile/react-native/).
@@ -273,7 +275,7 @@ To get started with React Native:
273
275
274
276
3. Run `npx typewriter init` to use the Typewriter quickstart wizard that generates a `typewriter.yml` configuration along with your first Typewriter client.
275
277
276
-
This command 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 / Segment client in `./analytics` (or whichever path you configured). You can use this interchangeably as a normal React Native Segment client. It contains additional methods for your tracking plan:
278
+
This command creates a `typewriter.yml` file in your repository. For more information on the format of this file, see the [Typewriter Configuration Reference](#configuration-reference). The command also adds a new Typewriter/Segment client in `./analytics` (or whichever path you configured). You can use this interchangeably as a normal React Native Segment client. It contains additional methods for your tracking plan:
277
279
278
280
```ts
279
281
import {
@@ -318,10 +320,11 @@ To get started with React Native:
318
320
// Remember this is just an extended client with the typewriter methods so all the normal segment methods still work!
319
321
segmentClient.track('Untyped event');
320
322
```
323
+
321
324
> info ""
322
325
> Run `npx typewriter` to regenerate your Typewriter client. You need to do this each time you update your Tracking Plan.
323
326
324
-
## Adding Events
327
+
## Adding events
325
328
326
329
To update or add a new event to a Typewriter client, first apply your changes to your Tracking Plan. Then run the following:
327
330
@@ -330,20 +333,20 @@ To update or add a new event to a Typewriter client, first apply your changes to
330
333
$ npx typewriter
331
334
```
332
335
333
-
## API Token Configuration
336
+
## API token configuration
334
337
335
338
Typewriter requires a Segment API token to fetch Tracking Plans from the [Segment Public API](https://docs.segmentapis.com/){:target="_blank”}.
336
339
337
340
338
-
You must be a workspace owner to create Segment API tokens.
341
+
You must have the [Workspace Owner role](/docs/segment-app/iam/roles/) to create Segment API tokens.
339
342
340
343
To create an API token:
341
344
1. Click on the **Tokens** tab on the [Access Management](https://app.segment.com/goto-my-workspace/settings/access-management){:target="_blank”} page and click **Create Token**.
342
345
2. Choose Segment's Public API.
343
346
3. Add a description for the token and assign access. If you choose *Workspace Member*, you only need to select **Tracking Plan Read-Only** for the Resource Role, as Typewriter only needs the *Tracking Plan Read-Only* role.
344
347
4. Click **Create**.
345
348
346
-
Typewriter looks for an API token in three ways, in the following order:
349
+
Typewriter looks for an API token in the following order:
347
350
1. If a token is piped through, it will use that token. For example, `echo $TW_TOKEN | typewriter build`.
348
351
2. Typewriter executes a token script from the `typewriter.yml`. See [Token Script](#token-script) for more information.
349
352
3. Typewriter reads the contents of the `~/.typewriter` file.
@@ -401,7 +404,7 @@ If this isn't possible you can also check in the full generated client. Segment,
401
404
402
405
## Configuration Reference
403
406
404
-
Typewriter stores its configuration in a `typewriter.yml` file in the root of your repo. A sample configuration might look like this:
407
+
Typewriter stores its configuration in a `typewriter.yml` file in the root of your repository. A sample configuration might look like this:
Typewriter only supports `track` calls. However, you can continue to use the underlying (untyped) analytics instance to perform `identify`, `group`, `page`, `screen`, and `alias` calls.
572
+
Typewriter only supports Track calls. However, you can continue to use the underlying (untyped) analytics instance to perform Identify, Group, Page, Screen, and Alias calls.
570
573
571
574
Not all languages support run-time validation. Currently, `analytics.js` and `analytics-node` support it using [AJV](https://github.com/epoberezkin/ajv){:target="_blank"} (both for JavaScript and TypeScript projects) while`analytics-swift` and `analytics-kotlin` don't support run-time validation. Typewriter also does not support event validation using the Common JSON Schema.
572
575
@@ -576,4 +579,4 @@ If you're interested in contributing, [open an issue on GitHub](https://github.c
576
579
577
580
## Feedback
578
581
579
-
Segment welcomes feedback you may have on your experience with Typewriter. To contact Segment, [open an issue on GitHub](https://github.com/segmentio/typewriter/issues/new){:target="_blank”}.
582
+
Segment welcomes feedback you may have on your experience with Typewriter. To contact us, [open an issue on GitHub](https://github.com/segmentio/typewriter/issues/new){:target="_blank”}.
0 commit comments