# Install on Django

> Kismet Telemetry for Django, a PyPI package on the same contract, is next. Until it ships, wire the contract yourself from the reference adapter.


> **Status**
>
> The Django package (`kismet-telemetry` on PyPI) is next on the roadmap and is not published. This page says what it will be and how to run the contract on Django today.

## What the package will be

The same six steps as every other adapter, in Django's shapes:

- A middleware class for `MIDDLEWARE`, run before your views, that resolves the visitor, records the server-plane event, sets the cookies and leaves the decision on `request.kismet`.
- A `KISMET_TELEMETRY` settings block: collection slug, tracking key from the environment, the route profile, the cookie domain override, endpoint overrides for staging.
- A consent callable (`KISMET_TELEMETRY_CONSENT`) with the same meaning as the Next and Node consent hook and the WordPress filter.
- A template tag that prints the seed first thing in `<head>`.
- `booking_bridge()` and `quote_capture()` for the checkout code.
- The conformance suite, run in CI against the middleware on Django's test client.

## Running the contract on Django today

Everything the middleware has to do is specified in the [contract](https://developers.kismet.travel/telemetry/contract.md), and the core's reference adapter (`src/conformance/reference-adapter.js` inside `@kismet-tech/telemetry`) is the worked example in about 160 lines. Port it step by step:

1. **Classify** the path against your route profile; skip assets and your API.
2. **Resolve**: `?kid_sid=` on the URL, then the `_kid_sid` cookie, then suppressed for bots (the vocabulary is `bot-patterns.json` in the core) and for visitors without consent, else mint eight characters from `A-Za-z0-9` with `secrets`.
3. **Record** the server-plane event with the body in contract section 8, from a background thread or task with a two-second bound.
4. **Set** `_kid_sid` (90 days) and `_kid_vid` (about 400) on the dotted serving domain, `SameSite=Lax`, `Secure` on HTTPS, never `HttpOnly`.
5. **Seed** the page with one inline script that sets `window.Kismet._kidSid` and then appends the tracker tag; mark the response `private, no-store`.
6. **Reconcile** a minted id with the authority after the response (contract section 6), and **join** bookings with one call to the booking bridge (section 9).

Then run the conformance suite against it. The suite is Node, but the driver only has to forward each request to your running Django server, the same way the Node adapter's own test does:

```js
import { runConformance, formatReport } from '@kismet-tech/telemetry/conformance';

const report = await runConformance((env) => ({
  handle: (request) => fetch(`http://127.0.0.1:8000${new URL(request.url).pathname}`, {
    headers: { ...Object.fromEntries(request.headers), 'x-forwarded-host': new URL(request.url).host, 'x-forwarded-proto': 'https' },
    redirect: 'manual',
  }),
  fixtures: { host: 'www.example.co.uk', pagePath: '/about', propertyPath: '/stays/porthleven/harbour-house', propertyId: 'harbour-house', propertyIdField: 'externalListingId', intentPath: '/stays/checkout', consentCookie: 'CookieConsent=statistics:true' },
}));
if (!report.ok) throw new Error(formatReport(report));
```

Point `KISMET_RESOLVE_ANCHOR_URL` and `KISMET_TRACKING_ENDPOINT` in your Django settings at `env.authorityUrl` and `env.relayUrl` for the run.

If you build this before we do, we would like to see it.
