Skip to content

JavaScript Widget SDK (window.PitajIO)

The Pitaj.io client widget exposes a comprehensive global JavaScript API on browser environments: window.PitajIO.

Through this SDK, engineers can toggle viewport states, dispatch pre-filled messages from landing page CTAs, monitor analytics telemetry, and bind authenticated user attributes.


1. SDK Ready Verification

Because the client bundle evaluates asynchronously (defer), invoke SDK methods inside the ready hook:

window.addEventListener('pitaj:ready', () => {
console.log('Pitaj.io SDK initialized and active!');
});
// Or using queued array syntax:
window.PitajIO = window.PitajIO || [];
window.PitajIO.push(['on', 'ready', () => {
console.log('Widget engine mounted!');
}]);

2. API Method Reference

open()

Programmatically reveals the chat interface.

window.PitajIO.open();

close()

Collapses the chat window and restores host page focus.

window.PitajIO.close();

toggle()

Inverts current window visibility state.

window.PitajIO.toggle();

sendMessage(text)

Dispatches a conversational prompt on behalf of the visitor and expands the modal.

// Example: External CTA button dispatches prompt into assistant
document.getElementById('pricing-cta').addEventListener('click', () => {
window.PitajIO.sendMessage('I want to learn more about enterprise volume discounts.');
});

identify(userData)

Binds authenticated visitor metadata to the active session. The agent immediately personalizes responses without prompting for email or contact info:

window.PitajIO.identify({
userId: 'usr_98124',
name: 'Marcus Vance',
email: 'marcus@vancetech.io',
company: 'Vance Technologies Inc.',
plan: 'Enterprise VIP'
});

resetSession()

Purges client conversation storage and resets session credentials (ideal on user account sign-out).

window.PitajIO.resetSession();

3. Lifecycle Analytics Events

Stream engagement events into your product analytics platforms (Google Analytics 4, Segment, Mixpanel):

// Visitor opened chat modal
window.PitajIO.on('widget:opened', () => {
gtag('event', 'chat_opened', { event_category: 'Pitaj_Chat' });
});
// Outbound message dispatched
window.PitajIO.on('message:sent', (data) => {
console.log('Dispatched prompt:', data.text);
});
// Visitor completed lead capture action
window.PitajIO.on('lead:captured', (lead) => {
gtag('event', 'generate_lead', {
currency: 'USD',
value: 100.0,
lead_email: lead.email
});
});