Skip to main content

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) β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ Splunk: full timing payload │────▢│ β”‚
β”‚ β”‚ β”‚ GTM: enriched + timing data │────▢│ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Getting Started​

Ready to integrate powerful analytics into your application? Choose your path:

πŸš€ Quick Start Guide​

Get up and running in minutes with our streamlined setup process.

πŸ“– Complete Usage Guide​

Comprehensive documentation covering all features, best practices, and real-world examples.

πŸ”§ API Reference​

Detailed technical documentation for all classes, methods, and interfaces.

πŸ’‘ Examples & Patterns​

Ready-to-use code examples for common integration scenarios.

Installation​

# Using npm
npm install @elliemae/pui-analytics-so

# Using pnpm (recommended)
pnpm add @elliemae/pui-analytics-so

Quick Example​

import { Analytics, updateBAEventParameters } from '@elliemae/pui-analytics-so';

// Configure global parameters (applied to all events)
updateBAEventParameters({
envName: 'production',
appId: 'my-awesome-app',
userId: 'user-123',
instanceId: 'instance-456',
});

// Initialize analytics with optional sampling
const analytics = new Analytics({
logger: console, // or PUI Diagnostics Logger
timingEventSamplingRatios: {
'user-interaction': 0.1, // Sample 10% of user-interaction timing events
'api-call': 1.0, // Sample 100% of api-call timing events
},
});

// Track business events
await analytics.sendBAEvent({
event: 'user-login',
method: 'oauth',
timestamp: new Date().toISOString(),
});

// Measure performance
const timing = await analytics.startTiming('api-call', {
appId: 'my-app',
appUrl: window.location.href,
});

// ... perform operation ...

await analytics.endTiming(timing, {
appId: 'my-app',
appUrl: window.location.href,
});

Start with our Usage Guide or jump straight to the Quick Start section.