# Generate tracking code from tracking plans with Snowtype
> Generate type-safe tracking code and implementation instructions with Snowtype. Use generated APIs to track event specifications and verify events with Snowplow Inspector and Console volume counts.
> Source: https://docs.snowplow.io/tutorials/data-products-base-tracking/generate-tracking-code/
> Documentation index: https://docs.snowplow.io/llms.txt

On your terminal now run `npx @snowplow/snowtype@latest generate --instructions`. If all is as expected, after a few seconds, you will have the following files generated:

![VS Code file explorer showing the src/tracking directory containing .snowtype-lock.json, instructions.md, and snowplow.ts generated by Snowtype](/assets/images/fs-93f506090adab7da1c8deb07e7f41fb8.png)

The `src/tracking/instructions.md` file includes detailed instructions and information about the Event Specifications to be implemented while `src/tracking/snowplow.ts` contains all the required code to be used to track the Event Specifications.

> **Info:** In some editors like [Visual Studio Code](https://code.visualstudio.com/), the APIs that are available in a project are shown to the developer as they type. For Snowtype exposed APIs to track Event Specifications or event Data Structures start with `track` and then the name of the Data Structure or Event Specification. For Event Specification APIs, there is also the suffix of `Spec` or `spec` depending on the language. E.g. for our custom tracking plan, we have available the `trackAddTodoSpec`, `trackCompleteTodoSpec` and `trackRemoveTodoSpec` methods.

## Tracking interactions

To track interactions such as adding a new todo, you can add the following piece of code at `src/pagesTodo/components/Header.tsx`

```diff
import { useState } from "react";
import { v4 } from "uuid";
import { Todo } from "../../../types";
+import { createTodo, trackAddTodoSpec } from "../../../tracking/snowplow";

// Rest of the code...

  function addItem(e: React.KeyboardEvent<HTMLInputElement>) {
    if (e.key === "Enter" && value) {
      addTodo((preItems) => {
        return [
          {
            id: v4(),
            value,
            completed: false,
          },
          ...preItems,
        ];
      });
+     trackAddTodoSpec({
+       action: "add",
+       context: [createTodo({ title: value })],
+     });
      setValue("");
    }
  }
```

Finally, you can go to the application, add a new todo and observe on the Snowplow Inspector extension as the addition Event Specification is being sent. The event contexts should include the `todo`, `event_specification` and any other extra context you might add.

![Snowplow Inspector showing a todo\_action self-describing event with the Entities panel open, displaying the todo entity (title: Test), event\_specification entity (name: \&quot;Add todo\&quot;, data\_product\_name: \&quot;Todo - Goals\&quot;), and web\_page entity](/assets/images/inspector-spec-db0b4a3b905faf7badb73b525180fe05.png)

After a while the Event Specification volume counts for each event will be available at the tracking plans screen.

![Todo - Goals tracking plan showing event specifications Add todo, Complete todo, and Remove todo — all using todo\_action 2-0-0 with a volume of 5 events each as of 14 Sept 2024](/assets/images/custom-dp-volumes-0a0736408362506989e7342543aff991.png)

You can checkout the completed code at the ['implemented' branch](https://github.com/snowplow-incubator/data-products-basic-tracking-recipe/tree/implemented).
