@sitepulse/web 1.0.0

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,20 @@
1
+ /**
2
+ * SitePulse Campaign Trigger & Audience Evaluation Engine (§8.3)
3
+ *
4
+ * Evaluates triggers (delay, scroll_percent, exit_intent, click, event)
5
+ * and matches audience rules against locally known visitor state.
6
+ *
7
+ * SILENT FAILURE GUARANTEE:
8
+ * All evaluations are enclosed in defensive try/catch blocks.
9
+ * A broken selector, malformed regex, or missing browser API will
10
+ * fail gracefully and silently without throwing into the host page.
11
+ */
12
+ import { Trigger, Audience } from "@sitepulse/types";
13
+ export interface VisitorAudienceState {
14
+ isNewVisitor: boolean;
15
+ deviceType: "desktop" | "mobile" | "tablet";
16
+ pathname: string;
17
+ sessionCount: number;
18
+ }
19
+ export declare function evaluateAudience(audience: Audience | undefined, state: VisitorAudienceState): boolean;
20
+ export declare function attachTrigger(trigger: Trigger | undefined, onTriggered: () => void): () => void;
@@ -0,0 +1,61 @@
1
+ import { CampaignActionHandlers } from "./renderer";
2
+ import type { Campaign } from "@sitepulse/types";
3
+ export * from "./renderer";
4
+ export * from "./evaluator";
5
+ export interface SitePulseConfig {
6
+ siteId: string;
7
+ endpointUrl?: string;
8
+ campaignsEndpointUrl?: string;
9
+ flushIntervalMs?: number;
10
+ autoTrack?: boolean;
11
+ autoFetchCampaigns?: boolean;
12
+ }
13
+ export interface IngestPayloadEvent {
14
+ eventName: string;
15
+ anonymousId: string;
16
+ sessionId: string;
17
+ userId?: string;
18
+ properties: Record<string, unknown>;
19
+ page: {
20
+ url: string;
21
+ referrer?: string;
22
+ title?: string;
23
+ };
24
+ deviceType?: "desktop" | "mobile" | "tablet";
25
+ browser?: string;
26
+ os?: string;
27
+ timestamp: string;
28
+ }
29
+ declare class SitePulseClient {
30
+ private config;
31
+ private queue;
32
+ private flushTimer;
33
+ private initialized;
34
+ private lastUrl;
35
+ private registeredCampaignTeardowns;
36
+ init(config: SitePulseConfig): void;
37
+ track(eventName: string, properties?: Record<string, unknown>): void;
38
+ page(properties?: Record<string, unknown>): void;
39
+ flush(isUnloading?: boolean): void;
40
+ /**
41
+ * Fetches active campaigns for this site from the endpoint, caches in sessionStorage,
42
+ * and automatically registers each active campaign. (§8.3)
43
+ */
44
+ fetchAndRegisterActiveCampaigns(): Promise<void>;
45
+ /**
46
+ * Directly renders a Campaign into the DOM using the fixed block renderer.
47
+ * (§8.3 & §3.2: Zero-innerHTML guaranteed)
48
+ */
49
+ renderCampaign(campaign: Campaign, handlers?: CampaignActionHandlers): {
50
+ destroy: () => void;
51
+ } | null;
52
+ /**
53
+ * Registers a Campaign: Evaluates audience rules and trigger signals,
54
+ * then mounts DOM when matched. Returns a teardown function.
55
+ */
56
+ registerCampaign(campaign: Campaign): () => void;
57
+ private autoCapturePageViews;
58
+ private checkRouteChange;
59
+ }
60
+ export declare const SitePulse: SitePulseClient;
61
+ export default SitePulse;