Live Chat Script

The Rapidpace SDK provides flexible profile ID management to track users across their journey, from anonymous visitors to authenticated users. This guide covers the three main approaches for handling profile IDs.

Installation

CDN Integration

Add the Rapidpace SDK to your website using our CDN:

var urmChatSetting = {
 channelId: "your-channel-id",
 appId: "your-app-id",
 apiKey: "your-api-key",
 targetElementId: "rapidpaceSDKChat",
};


(function () {
 var w = window;
 var uc = w && w.urmChat;
 var d = document;
 if (typeof uc === "function") {
   uc.initChat(urmChatSetting);
 } else {
   var l = function () {
     var s = d.createElement("script");
     s.type = "text/javascript";
     s.async = true;
     s.src =
       "https://cdn.urm.app/js/live-chat/RapidpaceLiveChat.js?date=" +
       Date.now();
     var x = d.getElementsByTagName("script")[0];
     x.parentNode.insertBefore(s, x);
     s.onload = function () {
       window && window.urmChat && window.urmChat.initChat(urmChatSetting);
     };
   };
   if (document.readyState === "complete") {
     l();
   } else if (w.attachEvent) {
     w.attachEvent("onload", l);
   } else {
     w.addEventListener("load", l, false);
   }
 }
})();

Quick Start:

The SDK is automatically initialized when the script loads

Access it through window.urmChat after initialization

Profile ID Management Strategies

1. Initialize with Known Profile ID

Use this approach when you already know the user's profile ID at initialization time (e.g., user is already logged in).

var urmChatSetting = {
 channelId: "your-channel-id",
 appId: "your-app-id",
 apiKey: "your-api-key",
 targetElementId: "urmSDKChat",
 profileId: "user-123" // Set known profile ID here
};
// ... rest of CDN code

When to use:

  • User is already authenticated when the page loads
  • You have a persistent user identifier available immediately
  • Returning users with stored session data

2. Set Profile ID After Initialization

Use this approach when the user authenticates after the SDK has been initialized (e.g., anonymous visitor who later logs in).

// Initialize without profile ID (using the CDN code above)


// Later, when user logs in
window.urmChat.setProfileId('user-123');

What happens:

  • Automatically merges any existing anonymous data with the authenticated profile
  • Preserves all events and attributes from the anonymous session
  • Updates cookies and internal state
  • Triggers chat reconnection if using Rapidpace Chat

3. Merge Profiles

Use this approach when you want to consolidate user data under a new profile ID.

// When you want to merge current profile with a new authenticated profile
window.urmChat.mergeProfile(['authenticated-user-id']);

Use cases:

  • User logs in and you want to consolidate their data
  • Account linking scenarios
  • Switching to a different user identifier

API Reference

Configuration Object

var urmChatSetting = ({
    apiKey: "YOUR_API_KEY",
    appId: "YOUR_APP_ID",
    channelId: "YOUR_CHANNEL_ID",
    targetElementId: "chat-root", // optional: defaults to document.body
    zIndex: 1400 // optional override; default is 999999999
  });

setProfileId(profileId)

Sets or updates the profile ID after initialization.

Parameters:

  • profileId (string, required): The new profile identifier

Effects:

  • Updates internal profile ID
  • Saves to cookies
  • Automatically merges with existing profile data
  • Reconnects chat sessions if applicable
window.urmChat.setProfileId('user@example.com');

mergeProfile(profileIds)

Merges current profile data with a new profile ID.

Parameters:

  • profileIds (Array<string>, required): Array containing the new profile ID to merge with

Returns: Promise that resolves when merge is complete

Example:

// Merge current profile with authenticated user ID
await window.urmChat.mergeProfile(['authenticated-user-123']);
getData()

Returns the current SDK data including profile ID.

Returns: Object containing SDK state and configuration

const data = window.urmChat.getData();
console.log(data.appData.profileId); // Current profile ID
console.log(data.appData.appId);  // App ID
console.log(data.appData.apiKey);    // API key

Update the z-index after load

urmChat.setChatZIndex(1600);

Description:

  • You can call urmChat.setChatZIndex(number) at any time.
  • Non-numeric values are ignored; the previous value is kept
  • The chat box uses zIndex + 1, and the help popup uses zIndex + 2, ensuring they always surface above the launcher button.

User Data Purge

The purge function completely removes all user-related data (cookies, local storage, and session identifiers) and resets the chat session. This ensures that a user's data does not persist after they log out, preventing the next user on the same device from accessing the previous session.

Usage (CDN / Script Tag)

If you are using the Rapidpace Chat via our CDN script, the function is exposed globally on the window.urmChat object.

Syntax:

window.urmChat.purge();

What happens when purge() is called?

  1. Cookies Cleared: All tracking cookies are removed.
  2. Session Reset: The current user profile ID is replaced with a new, anonymous visitor ID.
  3. Chat Disconnect: The active chat connection is closed, and the chat widget state is reset.
Close Modal