# Create a PostHog project and copy its token and host into .env

The step `posthog.project_token`, for [`posthog`](https://doc.saymyframe.com/modules/posthog.md).

The app records its events in the PostHog project whose project token is in `POSTHOG_PROJECT_TOKEN` of `.env`, on the host in `POSTHOG_HOST`. While the token is empty, the app starts without PostHog and records nothing in it, and a debug build prints why.

A project token only lets an app send events to its project, and it goes into the app, where anyone can read it, so it is no secret. A personal API key of PostHog, which starts with `phx_`, never goes into `.env`: the app refuses one, and a build with it has the key inside.

Every event has the property `app_flavor`, the [flavor](https://doc.saymyframe.com/guides/flavors.md) of the build, such as `dev` or `prod`, and a debug build records its events too. So filter the insights and the dashboards of PostHog on `app_flavor` equal to `prod` to count only the users of the release.

**1. Create the project.** In [PostHog](https://posthog.com), create a project, and note whether it is on PostHog's US Cloud, on its EU Cloud, or on a PostHog of your own.

**2. Put the token and the host into .env.** Copy the project token, which starts with `phc_`, into `.env` at the root of the app. Leave `POSTHOG_HOST` empty for the US Cloud, or give it `https://eu.i.posthog.com` for the EU Cloud, or the address of your own PostHog:

```bash title=".env"
POSTHOG_PROJECT_TOKEN=phc_...
POSTHOG_HOST=https://eu.i.posthog.com
```

`.env` stays out of git. On another machine, copy `.env.example` to `.env` and fill it in again. If a build with a personal API key left your machine, roll that key in PostHog.

**3. Start the app again.** The `flutter` tool reads `.env` when a command starts, so stop `flutter run` and start it again with the values:

```bash
flutter run --dart-define-from-file=.env
```

Run and Debug of VS Code, and the run configuration of the app in Android Studio, pass the argument for you. A build for a store gets the values of `.env` that its command gives it, such as those of the environment `prod` of your [CI](https://doc.saymyframe.com/guides/ci.md#values-for-each-environment).

**Check.** A debug build no longer prints a line that starts with `initPostHogAnalytics() failed, so the app works without it`, such as one that says that `POSTHOG_PROJECT_TOKEN` has no value in this build. In an app generated with `--analytics-collection=off`, PostHog records nothing until the code of the app turns collection on with `setAnalyticsCollectionEnabled(true)`, and a debug build says so at each start; see [Crash reporting and analytics](https://doc.saymyframe.com/guides/crash-reporting-and-analytics.md#the-collection-switch).
