sdk-sample 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export * from './tracked-button';
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ interface TrackedButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ eventId?: string;
4
+ buttonName: string;
5
+ extraParams?: Record<string, any>;
6
+ children: React.ReactNode;
7
+ }
8
+ /**
9
+ * Encapsulated Button Component that automatically tracks clicks.
10
+ * Uses the `useTracker` hook to send events directly.
11
+ */
12
+ export declare const TrackedButton: React.FC<TrackedButtonProps>;
13
+ export {};
@@ -0,0 +1 @@
1
+ export * from './tracked-form';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ interface TrackedFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
3
+ formId: string;
4
+ children: React.ReactNode;
5
+ transformData?: (formData: FormData) => Record<string, any>;
6
+ }
7
+ /**
8
+ * Encapsulated Form Component that automatically tracks submission.
9
+ */
10
+ export declare const TrackedForm: React.FC<TrackedFormProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from './tracked-page';
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface TrackedPageProps {
3
+ pageTitle?: string;
4
+ children: React.ReactNode;
5
+ }
6
+ /**
7
+ * Component Wrapper that automatically tracks page view on mount.
8
+ */
9
+ export declare const TrackedPage: React.FC<TrackedPageProps>;
10
+ export {};
@@ -0,0 +1,11 @@
1
+ export { Tracker } from './sdk/tracker';
2
+ export { EventManager } from './sdk/event-manager';
3
+ export { QueueManager } from './sdk/queue-manager';
4
+ export { StrategyManager } from './sdk/strategy-manager';
5
+ export { SchemaManager } from './sdk/schema-manager';
6
+ export type { SchemaConfig, EventDefinition } from './sdk/schema-manager';
7
+ export { TrackerProvider, useTracker, usePageView, usePageStay, useExposure } from './sdk/react-hooks';
8
+ export { TrackedButton } from './components/trackedButton';
9
+ export { TrackedPage } from './components/trackedPage';
10
+ export { TrackedForm } from './components/trackedForm';
11
+ export * from './types';
@@ -0,0 +1,11 @@
1
+ import { BaseEvent } from '../types';
2
+ export declare class EventManager {
3
+ private getBaseInfo;
4
+ /**
5
+ * Factory method to create an event with base info.
6
+ * @param eventName Name of the event
7
+ * @param params Event parameters
8
+ * @returns Enriched event object
9
+ */
10
+ createEvent(eventName: string, params: Record<string, unknown>): BaseEvent;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { BaseEvent } from '../types';
2
+ import { StrategyManager } from './strategy-manager';
3
+ export declare class QueueManager {
4
+ private queue;
5
+ private strategyManager;
6
+ private batchSize;
7
+ private timer;
8
+ private interval;
9
+ constructor(strategyManager: StrategyManager, batchSize?: number, interval?: number);
10
+ /**
11
+ * Add an event to the queue.
12
+ * @param event Event to track
13
+ * @param immediate Whether to send immediately
14
+ */
15
+ addEvent(event: BaseEvent, immediate?: boolean): void;
16
+ /**
17
+ * Flush the current queue via XHR.
18
+ */
19
+ flush(): void;
20
+ flushOnUnload(): void;
21
+ }
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { Tracker } from './tracker';
3
+ interface TrackerProviderProps {
4
+ config: {
5
+ endpoint: string;
6
+ autoTrack?: boolean;
7
+ debug?: boolean;
8
+ };
9
+ children: React.ReactNode;
10
+ }
11
+ export declare const TrackerProvider: React.FC<TrackerProviderProps>;
12
+ /**
13
+ * Hook to access the Tracker instance.
14
+ * @returns Tracker instance
15
+ * @throws Error if used outside TrackerProvider
16
+ */
17
+ export declare const useTracker: () => Tracker;
18
+ /**
19
+ * Hook to automatically track page view on mount.
20
+ * @param pageTitle Optional page title override
21
+ */
22
+ export declare const usePageView: (pageTitle?: string) => void;
23
+ /**
24
+ * Hook to track how long the user stays on the page/component.
25
+ * Tracks 'pageStay' event on unmount with duration and scroll depth.
26
+ */
27
+ export declare const usePageStay: () => void;
28
+ /**
29
+ * Hook to track element exposure (visibility).
30
+ * Tracks 'exposure' event when element becomes hidden after being visible.
31
+ * @param elementId Unique ID for the element
32
+ * @param componentName Human-readable name
33
+ * @returns Ref to attach to the element
34
+ */
35
+ export declare const useExposure: (elementId: string, componentName: string) => React.RefObject<HTMLDivElement>;
36
+ export {};
@@ -0,0 +1,33 @@
1
+ export type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'object';
2
+ export interface ParamSchema {
3
+ type: ParamType;
4
+ required?: boolean;
5
+ description?: string;
6
+ }
7
+ export interface EventDefinition {
8
+ priority: 'high' | 'medium' | 'low';
9
+ params: Record<string, ParamSchema>;
10
+ description?: string;
11
+ }
12
+ export interface SchemaConfig {
13
+ version: string;
14
+ events: Record<string, EventDefinition>;
15
+ }
16
+ export declare const DEFAULT_SCHEMA: SchemaConfig;
17
+ export declare class SchemaManager {
18
+ private schema;
19
+ constructor(initialConfig?: SchemaConfig);
20
+ loadConfig(config: SchemaConfig): void;
21
+ /**
22
+ * Validate event parameters against the schema.
23
+ * @param eventName Name of the event
24
+ * @param params Event parameters
25
+ * @returns Validation result
26
+ */
27
+ validate(eventName: string, params?: Record<string, unknown>): {
28
+ valid: boolean;
29
+ errors: string[];
30
+ };
31
+ getEventPriority(eventName: string): 'high' | 'medium' | 'low';
32
+ private getType;
33
+ }
@@ -0,0 +1,14 @@
1
+ import { ReportStrategy } from '../types';
2
+ export declare class StrategyManager {
3
+ private endpoint;
4
+ constructor(endpoint: string);
5
+ /**
6
+ * Send data using the specified strategy.
7
+ * @param data Data to send
8
+ * @param strategy Reporting strategy (xhr, beacon, img)
9
+ */
10
+ send(data: unknown, strategy?: ReportStrategy): void;
11
+ private sendBeacon;
12
+ private sendXHR;
13
+ private sendImg;
14
+ }
@@ -0,0 +1,41 @@
1
+ import { EventMap } from '../types';
2
+ import { SchemaConfig } from './schema-manager';
3
+ interface TrackerConfig {
4
+ endpoint: string;
5
+ autoTrack?: boolean;
6
+ debug?: boolean;
7
+ }
8
+ export declare class Tracker {
9
+ private eventManager;
10
+ private queueManager;
11
+ private strategyManager;
12
+ private schemaManager;
13
+ private isInitialized;
14
+ private debug;
15
+ constructor(config: TrackerConfig);
16
+ /**
17
+ * Safe execution wrapper to handle errors based on debug mode.
18
+ * @param fn Function to execute safely
19
+ */
20
+ private safeRun;
21
+ /**
22
+ * Load dynamic schema (IDL/JSON) for event validation.
23
+ * @param config Schema configuration
24
+ */
25
+ loadSchema(config: SchemaConfig): void;
26
+ /**
27
+ * Track an event.
28
+ * @param eventName Name of the event
29
+ * @param params Event parameters
30
+ * @param forcedImmediate Whether to send immediately (bypassing queue)
31
+ */
32
+ trackEvent<K extends keyof EventMap>(eventName: K, params: EventMap[K], forcedImmediate?: boolean): void;
33
+ trackEvent(eventName: string, params: Record<string, unknown>, forcedImmediate?: boolean): void;
34
+ private initAutoTracking;
35
+ private trackPageView;
36
+ private trackClicks;
37
+ private trackErrors;
38
+ private trackPerformance;
39
+ private setupUnload;
40
+ }
41
+ export {};