@sinaptik/retein-client-sdk
v0.1.2
Published
Retein SDK for client-side tracking and analytics
Readme
Retein SDK
TypeScript/JavaScript SDK for Retein email marketing automation platform.
Installation
yarn add @sinaptik/retein-client-sdk
# or
npm install @sinaptik/retein-client-sdkUsage
import ReteinSDK from "@sinaptik/retein-client-sdk";
// Initialize with default settings (automatic page view tracking enabled)
reteinClient = await ReteinClientSDK.create("your-api-key");
// Track an event
retein.track("page_viewed", { page: "/home" });
// Identify a user
retein.identify("user123");
// Update user properties
retein.updateUser({
email: "[email protected]",
name: "John Doe",
plan: "premium",
lastLogin: new Date(),
});Automatic page view tracking
By default, the SDK automatically tracks page views:
- On initial page load
- On navigation using the History API (pushState, replaceState)
- On page navigation using the browser back/forward buttons
- When client-side routing changes the URL without using History API
Each page view event includes:
{
url: "https://example.com/page", // full URL
path: "/page", // pathname
title: "Page Title", // document title
referrer: "https://google.com", // referrer if available
search: "?query=value", // URL search parameters if any
hash: "#section", // URL hash if any
}To control automatic page view tracking:
// Disable page view tracking
retein.disablePageViewTracking();
// Re-enable page view tracking
retein.enablePageViewTracking();API Reference
track(eventName: string, properties?: Record<string, any>)
Track an event for the current user with optional properties.
identify(distinctId: string)
Identify a user with a unique identifier.
updateUser(properties: Record<string, any>)
Update properties for the current user.
disablePageViewTracking()
Disable automatic page view tracking.
enablePageViewTracking()
Enable automatic page view tracking.
reset()
Reset the SDK instance to its initial state. This includes clearing session and identity information and reinitializing page view tracking if it is enabled.
// Reset the SDK instance
retein.reset();