@optic7409/resolvo-analytics
Version:
Simplified analytics client library for Next.js with automatic SSR handling, one-line integration, and comprehensive tracking
108 lines (107 loc) • 2.43 kB
TypeScript
export interface AnalyticsConfig {
apiKey: string;
websiteToken: string;
apiUrl?: string;
debug?: boolean;
userId?: string;
sessionId?: string;
enableAutoTracking?: boolean;
ssr?: boolean;
autoInitialize?: boolean;
environment?: 'development' | 'production' | 'test';
framework?: 'nextjs' | 'react' | 'vue' | 'angular' | 'unknown';
routerType?: 'app' | 'pages';
}
export interface ResolvoConfig {
apiKey: string;
websiteToken?: string;
apiUrl?: string;
debug?: boolean;
ssr?: boolean;
autoInitialize?: boolean;
environment?: 'development' | 'production' | 'test';
}
export interface PageViewEvent {
type: 'page_view';
url: string;
title: string;
referrer?: string;
timestamp: number;
userId?: string;
sessionId: string;
}
export interface CustomEvent {
type: 'custom';
name: string;
properties?: Record<string, any>;
timestamp: number;
userId?: string;
sessionId: string;
}
export interface ClickEvent {
type: 'click';
element: string;
text?: string;
url?: string;
position?: {
x: number;
y: number;
};
timestamp: number;
userId?: string;
sessionId: string;
}
export interface FormEvent {
type: 'form_submit' | 'form_abandon';
formId?: string;
formName?: string;
fields?: string[];
timestamp: number;
userId?: string;
sessionId: string;
}
export interface ScrollEvent {
type: 'scroll';
depth: number;
maxDepth: number;
timestamp: number;
userId?: string;
sessionId: string;
}
export type AnalyticsEvent = PageViewEvent | CustomEvent | ClickEvent | FormEvent | ScrollEvent;
export interface UserProperties {
userId?: string;
email?: string;
name?: string;
company?: string;
plan?: string;
[key: string]: any;
}
export interface SessionData {
sessionId: string;
startTime: number;
lastActivity: number;
pageViews: number;
events: number;
referrer?: string;
userAgent: string;
screen: {
width: number;
height: number;
};
location?: {
country?: string;
city?: string;
timezone?: string;
};
}
export interface AnalyticsResponse {
success: boolean;
message?: string;
data?: any;
}
export interface QueuedEvent {
event: AnalyticsEvent;
retries: number;
timestamp: number;
}