import type { FormEventType, NavigationType, VitalRating, VitalType } from "@entrolytics/shared";
/**
* Client-side tracking functions for Astro components
*
* @example
* ```astro
* ---
* import { trackEvent } from '@entrolytics/astro/client';
* ---
*
*
* ```
*/
export interface EventData {
[key: string]: string | number | boolean | EventData | string[] | number[] | EventData[];
}
export type WebVitalMetric = VitalType;
export type WebVitalRating = VitalRating;
export type { NavigationType };
export interface WebVitalData {
metric: WebVitalMetric;
value: number;
rating: WebVitalRating;
delta?: number;
id?: string;
navigationType?: NavigationType;
attribution?: Record;
}
export type { FormEventType };
export interface FormEventData {
eventType: FormEventType;
formId: string;
formName?: string;
urlPath?: string;
fieldName?: string;
fieldType?: string;
fieldIndex?: number;
timeOnField?: number;
timeSinceStart?: number;
errorMessage?: string;
success?: boolean;
}
declare global {
interface Window {
entrolytics?: {
track: (eventName?: string | object, eventData?: Record) => void;
identify: (data: Record) => void;
};
__entrolytics_config?: {
websiteId: string;
host: string;
};
}
}
/**
* Track a custom event
*
* Can be used inline in onclick handlers or called from client-side scripts
*/
export declare function trackEvent(eventName: string, eventData?: EventData): void;
/**
* Track revenue event
*
* @example
* ```ts
* trackRevenue('purchase', 99.99, 'USD', { productId: 'abc123' });
* ```
*/
export declare function trackRevenue(eventName: string, revenue: number, currency?: string, data?: EventData): void;
/**
* Track outbound link click
*/
export declare function trackOutboundLink(url: string, data?: EventData): void;
/**
* Identify with custom data
*/
export declare function identify(data: EventData): void;
/**
* Identify a user by ID for logged-in tracking
*/
export declare function identifyUser(userId: string, traits?: EventData): void;
/**
* Track a page view manually
* Useful when using View Transitions or client-side routing
*/
export declare function trackPageView(url?: string, referrer?: string): void;
/**
* Track a Web Vital metric
*
* @example
* ```ts
* import { onLCP, onINP, onCLS } from 'web-vitals';
* import { trackVital } from '@entrolytics/astro/client';
*
* onLCP((metric) => trackVital({
* metric: 'LCP',
* value: metric.value,
* rating: metric.rating
* }));
* ```
*/
export declare function trackVital(data: WebVitalData): Promise;
/**
* Initialize automatic Web Vitals tracking
* Call this in your client-side script to auto-track all Core Web Vitals
*
* @example
* ```astro
*
* ```
*/
export declare function initWebVitals(): Promise;
/**
* Track a form event
*
* @example
* ```ts
* import { trackFormEvent } from '@entrolytics/astro/client';
*
* trackFormEvent({
* eventType: 'submit',
* formId: 'contact-form',
* success: true
* });
* ```
*/
export declare function trackFormEvent(data: FormEventData): Promise;
/**
* Create a form tracker for a specific form
*
* @example
* ```ts
* const tracker = createFormTracker('signup-form', 'Signup Form');
* tracker.trackStart();
* tracker.trackFieldFocus('email', 'email', 0);
* tracker.trackSubmit(true);
* ```
*/
export declare function createFormTracker(formId: string, formName?: string): {
trackStart: () => void;
trackFieldFocus: (fieldName: string, fieldType?: string, fieldIndex?: number) => void;
trackFieldBlur: (fieldName: string, fieldType?: string, fieldIndex?: number) => void;
trackFieldError: (fieldName: string, errorMessage: string, fieldType?: string, fieldIndex?: number) => void;
trackSubmit: (success: boolean) => void;
trackAbandon: () => void;
};
//# sourceMappingURL=client.d.ts.map