import { AnalyticsInstance } from 'analytics';
import { AnalyticsOptions } from '@solid-analytics/solid/runtime';
import { AnalyticsRuntime } from '@solid-analytics/solid/runtime';
import { Component } from 'solid-js';
import { JSX } from 'solid-js';
/**
* SolidStart Analytics Provider
*
* Provides analytics context with automatic server-side tracking support
*
* @example
* ```tsx
* import { AnalyticsProvider } from '@solid-analytics/solidstart'
* import Analytics from 'analytics'
* import segmentPlugin from '@analytics/segment'
*
* const client = Analytics({
* app: 'my-app',
* plugins: [segmentPlugin({ writeKey: 'key' })]
* })
*
* export default function App() {
* return (
*
*
*
* )
* }
* ```
*/
export declare const AnalyticsProvider: Component;
export declare interface AnalyticsProviderProps {
/**
* Analytics client instance (must support SSR if using server-side tracking)
*/
client?: AnalyticsInstance;
/**
* Configuration options
*/
options?: SolidStartAnalyticsOptions;
/**
* Children
*/
children: JSX.Element;
}
export { AnalyticsRuntime }
/**
* Create a server-side analytics instance with automatic context enrichment
*
* @example
* ```tsx
* "use server"
* import { createServerAnalytics } from '@solid-analytics/solidstart/server'
*
* const analytics = createServerAnalytics(analyticsClient)
*
* export async function trackEvent(name: string, data: any) {
* await analytics.track(name, data)
* }
* ```
*/
export declare function createServerAnalytics(client: AnalyticsInstance, defaultOptions?: Omit): {
track: (eventName: string, properties?: Record) => Promise;
identify: (userId: string, traits?: Record) => Promise;
page: (pageName?: string, properties?: Record) => Promise;
batch: (events: Parameters[0]) => Promise;
};
export declare interface RequestContext {
ip?: string;
userAgent?: string;
referer?: string;
country?: string;
region?: string;
city?: string;
sessionId?: string;
userId?: string;
[key: string]: any;
}
/**
* Server-side identify function
*
* @example
* ```tsx
* "use server"
* import { serverIdentify } from '@solid-analytics/solidstart/server'
*
* export async function handleLogin(userId: string) {
* await serverIdentify(userId, { email: 'user@example.com' })
* }
* ```
*/
export declare function serverIdentify(userId: string, traits?: Record, options?: ServerTrackOptions): Promise;
/**
* Server-side page function
*
* @example
* ```tsx
* "use server"
* import { serverPage } from '@solid-analytics/solidstart/server'
*
* export async function trackPageView() {
* await serverPage('Home', { section: 'landing' })
* }
* ```
*/
export declare function serverPage(pageName?: string, properties?: Record, options?: ServerTrackOptions): Promise;
/**
* Server-side track function
*
* @example
* ```tsx
* "use server"
* import { serverTrack } from '@solid-analytics/solidstart/server'
*
* export async function handlePurchase() {
* await serverTrack('purchase_completed', { amount: 99.99 })
* }
* ```
*/
export declare function serverTrack(eventName: string, properties?: Record, options?: ServerTrackOptions): Promise;
/**
* Batch server tracking for multiple events
*
* @example
* ```tsx
* "use server"
* import { serverTrackBatch } from '@solid-analytics/solidstart/server'
*
* export async function trackUserFlow() {
* await serverTrackBatch([
* { type: 'track', event: 'page_view' },
* { type: 'track', event: 'button_click', properties: { button: 'cta' } },
* ])
* }
* ```
*/
export declare function serverTrackBatch(events: Array<{
type: "track" | "identify" | "page";
event?: string;
userId?: string;
traits?: Record;
properties?: Record;
}>, options?: ServerTrackOptions): Promise;
export declare interface ServerTrackOptions {
/**
* Analytics client instance (must be isomorphic)
*/
client?: AnalyticsInstance;
/**
* Enrich event with request context (IP, user agent, etc.)
* @default true
*/
enrichContext?: boolean;
/**
* Extract session information from cookies
* @default true
*/
includeSession?: boolean;
/**
* Debug logging
* @default false
*/
debug?: boolean;
}
export declare interface SolidStartAnalyticsOptions extends AnalyticsOptions {
/**
* Server-side tracking mode
* - 'server-function': Use server functions (default for SolidStart)
* - 'queue': Queue events during SSR, replay on client
* - 'track': Track immediately on server
* - 'both': Track on both server and client
* - false: Client-only
*
* @default 'server-function'
*/
ssr?: "server-function" | "queue" | "track" | "both" | false;
/**
* Server tracking options (only applies when ssr is 'server-function')
*/
serverOptions?: Omit;
}
/**
* Hook to access analytics context
*
* @example
* ```tsx
* import { useAnalytics } from '@solid-analytics/solidstart'
*
* function MyComponent() {
* const analytics = useAnalytics()
*
* const handleClick = () => {
* analytics.track('button_clicked', { button: 'cta' })
* }
*
* return
* }
* ```
*/
export declare function useAnalytics(): AnalyticsRuntime;
export { }