S
API Reference/SDK Methods

🛠️ SDK Methods

Complete reference for the Sypnia JavaScript SDK.

🌐 Global Object

Once the SDK is loaded, you can access it via the global window.Sypnia object:

// Check if SDK is loaded
if (window.Sypnia) {
  Sypnia.track('my_event');
}

Sypnia.track()

Track a custom event with optional properties.

Sypnia.track(eventName: string, properties?: object): void
PropertyTypeDescription
eventName*stringName of the event (e.g., "signup", "purchase")
propertiesobjectOptional key-value pairs of event metadata

Examples

// Simple event
Sypnia.track('button_clicked');

// Event with properties
Sypnia.track('purchase', {
  product_id: 'prod_123',
  product_name: 'Pro Plan',
  value: 29.99,
  currency: 'USD'
});

// Feature usage tracking
Sypnia.track('feature_used', {
  feature: 'export',
  format: 'csv'
});

Sypnia.identify()

Associate the current visitor with a user ID and traits.

Sypnia.identify(userId: string, traits?: object): void
PropertyTypeDescription
userId*stringUnique identifier for the user in your system
traitsobjectOptional user attributes (email, name, plan, etc.)

Examples

// Basic identification
Sypnia.identify('user_123');

// With user traits
Sypnia.identify('user_123', {
  email: 'john@example.com',
  name: 'John Doe',
  plan: 'pro',
  company: 'Acme Inc',
  created_at: '2025-01-15'
});

Sypnia.page()

Manually trigger a pageview event. Useful for SPAs.

Sypnia.page(): void

Examples

// Trigger pageview after navigation
Sypnia.page();

// React Router integration
useEffect(() => {
  Sypnia.page();
}, [location.pathname]);

// Vue Router integration
router.afterEach(() => {
  Sypnia.page();
});

Sypnia.feedback()

Collect user feedback or NPS scores.

Sypnia.feedback(score: number | null, message?: string): void
PropertyTypeDescription
scorenumber | nullNPS score (1-10) or null for comment-only feedback
messagestringOptional feedback message or comment

Examples

// NPS score with comment
Sypnia.feedback(9, 'Love this product!');

// Just a score
Sypnia.feedback(7);

// Just a comment
Sypnia.feedback(null, 'The checkout process was confusing');

📋 Automatic Properties

These properties are automatically added to every event:

PropertyTypeDescription
session_idstringUnique session identifier
visitor_idstringPersistent visitor identifier
timestampstringISO 8601 timestamp
urlstringCurrent page URL
pathstringURL path
referrerstringReferrer URL
titlestringPage title
browserstringBrowser name (Chrome, Firefox, etc.)
osstringOperating system
device_typestring"desktop" or "mobile"
screen_widthnumberScreen width in pixels
screen_heightnumberScreen height in pixels