Install on Django
View .mdWhat the package will be
Section titled “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 onrequest.kismet. - A
KISMET_TELEMETRYsettings 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()andquote_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
Section titled “Running the contract on Django today”Everything the middleware has to do is specified in the contract, 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:
- Classify the path against your route profile; skip assets and your API.
- Resolve:
?kid_sid=on the URL, then the_kid_sidcookie, then suppressed for bots (the vocabulary isbot-patterns.jsonin the core) and for visitors without consent, else mint eight characters fromA-Za-z0-9withsecrets. - Record the server-plane event with the body in contract section 8, from a background thread or task with a two-second bound.
- Set
_kid_sid(90 days) and_kid_vid(about 400) on the dotted serving domain,SameSite=Lax,Secureon HTTPS, neverHttpOnly. - Seed the page with one inline script that sets
window.Kismet._kidSidand then appends the tracker tag; mark the responseprivate, no-store. - 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:
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.