PUI Analytics Scripting Object
Welcome to the PUI Analytics Scripting Object - an analytics solution designed for tracking business events and performance metrics from Microapps.
What is PUI Analytics SO?β
The PUI Analytics Scripting Object (@elliemae/pui-analytics-so) is a TypeScript library that provides a unified interface for collecting, processing, and forwarding analytics data to multiple destinations including Google Tag Manager (GTM) and LogRocket. Built with performance and reliability in mind, it seamlessly integrates into micro-frontend architectures and supports sophisticated event sampling strategies.
Key Featuresβ
π― Comprehensive Event Trackingβ
- Business analytics events with rich contextual data
- Automatic enrichment with environment, app, and user information
β‘ Performance Monitoringβ
- High-precision timing measurements using the Performance API
- Automatic performance observation for measure entries
- Start/end timing methods for custom measurements
π Smart Sampling & Filteringβ
- Configurable per-event sampling ratios to control timing data volume
- Head sampling (deterministic, not random) for consistent data quality
- Automatic filtering of third-party GTM/GA4 performance measures
- Sampling applies uniformly to all three destinations (Splunk, GTM, LogRocket)
- BA events (
sendBAEvent) are not sampled β always forwarded to GTM and LogRocket
π Multi-Platform Integrationβ
- Google Tag Manager: Automatic event forwarding to GTM data layer
- LogRocket: Seamless integration for session replay correlation
- PUI Diagnostics: Compatible with PUI Logger or console
- Micro-frontend support: Works across iframe boundaries with parent window detection
π‘οΈ Enterprise-Readyβ
- TypeScript support with comprehensive type definitions
- Robust error handling with try-catch patterns
- Memory-efficient with automatic performance mark cleanup
- Configurable sampling ratios for high-traffic scenarios
Use Casesβ
Business Analytics Events (sendBAEvent)β
Track user interactions, page views, feature usage, and errors. Every call reaches GTM (full enriched context) and LogRocket (caller-supplied fields only). No sampling β subject only to LogRocket's sliding-window throttle.
Manual Performance Timing (startTiming / endTiming)β
Bracket a unit of work (API calls, component renders, long-running operations) to measure its wall-clock duration. The resulting measure is automatically captured by the PerformanceObserver pipeline.
Automatic Performance Observationβ
A page-wide PerformanceObserver captures all performance.measure() entries β including those from endTiming and any other code on the page. Third-party measures from GTM/GA4 are automatically filtered out. Sampled entries (default 25%) fan out to Splunk and GTM.
Sampling Ratio Managementβ
Runtime CRUD for per-event sampling ratios via setTimingEventSamplingRatio, getTimingEventSamplingRatio, deleteTimingEventSamplingRatio, and getAllTimingEventSamplingRatios. Sampling applies uniformly to both timing destinations (Splunk and GTM).
Session Replay Integrationβ
Correlate events with LogRocket sessions for comprehensive debugging and user journey analysis. LogRocket receives only BA events (caller-supplied fields) β timing events are not sent to LogRocket β to conserve the 2,000 total-property session budget.
Shared LogRocket Throttle (lrTrackGuarded)β
The throttled logRocket.track() wrapper used internally is exported so consumers (e.g. pui-app-sdk) can send custom events to LogRocket with the same sliding-window throttle and property-count guards β no need to duplicate throttle logic across packages.
Architecture Overviewβ
ββββββββββββββββββββ ββββββββββββββββββββββββββββββββ ββββββββββββββββββββ
β Your App β β PUI Analytics SO β β Destinations β
β β β β β β
β ββββββββββββββββ β β β β ββββββββββββββββ β
β β sendBAEvent()βββΌβββββΆβ GTM: full enriched payload ββββββΆβ β GTM β β
β β (BA events) β β β LR: caller fields only ββββββΆβ β Data Layer β β
β ββββββββββββββββ β β (no sampling, LR throttled) β β ββββββββββββββββ β
β β β β β β
β ββββββββββββββββ β β ββββββββββββββββββββββββββ β β ββββββββββββββββ β
β βstartTiming() β β β β PerformanceObserver β β β β LogRocket β β
β β endTiming() βββΌβββββΆβ β (all page measures) β β β β (BA only) β β
β ββββββββββββββββ β β ββββββββββββ¬ββββββββββββββ β β ββββββββββββββββ β
β β β β β β β
β ββββββββββββββββ β β ββββββββββββΌββββββββββββββ β β ββββββββββββββββ β
β β Other code's β β β β Filter GTM/GA4 names β β β β Splunk β β
β β .measure() βββΌβββββΆβ β Head Sampling (25%) β β β β (Logger) β β