Once your customer installs the Radar loader script on their website, it exposes a global object with the namespace you defined. This JavaScript SDK provides a set of methods that your customers can use to send custom data, manage their users’ identity, and control the tracker’s behavior. Throughout this guide, we’ll use YourAppName as the example namespace that you would provide to your customers.

Core Methods

track

The track method is the primary way for your customers to send custom event data to Radar.
YourAppName.track(eventName, properties);
eventName
string
required
The name of the event to track. You should advise your customers to use a consistent [Object] [Verb] naming convention, such as Document Signed or Video Played.
properties
object
A JSON object of key-value pairs to send as metadata with the event.
Example Implementation:
// Your customer would implement this after a successful action
YourAppName.track("Trial Started", {
  plan: "Pro",
  source: "Website CTA"
});

identify

The identify method allows your customers to associate traits with a user on their website. These traits are stored by Radar and attached to all future events from that user.
YourAppName.identify(traits);
traits
object
required
A JSON object of key-value pairs representing the user’s traits. If an email property is included, Radar will use it for enrichment.
Example Implementation:
// Your customer could call this after a user signs in
YourAppName.identify({
  email: "hello@snitcher.com",
  name: "Alex",
  plan: "Enterprise"
});

page

While Radar tracks pageviews automatically in most cases, the page method can be used to manually trigger a pageview event. This is useful in Single-Page Applications (SPAs) where routing changes don’t always trigger a full page load.
YourAppName.page();

Session Management

getSession

Returns the current session object for the end user.
const session = YourAppName.getSession();
console.log(session.id); // "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"

resetSession

Ends the current user’s session and immediately starts a new one.
YourAppName.resetSession();

giveCookieConsent

This method signals to Radar that an end user has provided consent to use persistent storage (cookies and localStorage). See the Consent Management guide for a full walkthrough.
// Your customer calls this when their user accepts the cookie policy
YourAppName.giveCookieConsent();

Advanced Methods

flush

Forces the tracker to immediately send any queued events to the Radar API. This can be useful for your customers in specific situations where they need to ensure data is sent before a certain action.
YourAppName.flush();

on

Allows you to build functionality that listens for events emitted by the tracker on your customer’s site. Your customers can use this to integrate the tracker’s lifecycle with their own application code.
YourAppName.on(eventName, callback);
eventName
string
required
The name of the internal tracker event to listen for. Common events include: initialized, session_start, identify, page_view.
callback
function
required
A function to execute when the event occurs. The callback will receive the event payload as an argument.
Example Implementation:
// Your customer could use this to update their UI when a user is identified
YourAppName.on('identify', (traits) => {
  console.log('User identified:', traits);
});