TrackingTypeScript

TypeScript

Add a declaration so window.lynq is typed. Put it in any .d.ts file your project includes, for example types/lynq.d.ts:

types/lynq.d.ts
type LynqProps = Record<string, string | number | boolean | null | undefined>;
 
interface Lynq {
  /** Record a custom event; properties are flat and stored as text. */
  track(name: string, properties?: LynqProps): void;
  /** Attach the session to one of your users; ignored under Global Privacy Control. */
  identify(userId: string): void;
  /** Report a handled error: an Error, a string or anything thrown. Ten per page load. */
  error(error: unknown): void;
  /** Put the session in an experiment: variants assigns, variant records yours, neither reads. */
  experiment(opts: {
    name: string;
    variants?: string[] | Record<string, number>;
    variant?: string;
  }): string | undefined;
  /** Stop measuring this browser (sets one localStorage flag). */
  optOut(): void;
  /** Measure this browser again. */
  optIn(): void;
}
 
declare global {
  interface Window {
    /** Present once the script has loaded. */
    lynq?: Lynq;
    /** Calls queued before the script loads are replayed on start. */
    lynqQueue?: { name: string; properties?: LynqProps }[];
  }
}
 
export {};

lynq is optional on window on purpose: the script is deferred, and a blocker may stop it. Write window.lynq?.track(...) and the call is a no-op until it exists.

Types for the other direction, an agent asking Lynq, are the tool schemas the MCP server publishes; see For agents.