JavaScript API Methods
You can use our JavaScript API to control RightMessage and send data to our platform. To execute a command, you can use window.RM.push(['command', 'parameter']);
We recommend using RM.push(['command', 'parameter'])
instead, which is a shorter version of the above.
trigger
This command allows you to manually trigger a widget to appear.
// Shows the widget with the ID 'wdg_1234abcd'
RM.push(['trigger', 'wdg_1234abcd']);
hide
This command allows you to hide a widget.
// Hides the widget with the ID 'wdg_1234abcd'
RM.push(['hide', 'wdg_1234abcd']);
reset
This command resets the current visitor's data, recalculates their segments, and re-runs any active campaigns.
RM.push(['reset']);
personalize
This command re-runs any active campaigns for the current visitor. This is useful when you've updated a visitor's information and want to re-personalize the page for them.
RM.push(['personalize']);
lookup
This command allows you to look up a contact ID from one of your integrations.
// Looks up a contact with the email '[email protected]'
RM.push(['lookup', { email: '[email protected]' }]);
identify
This command identifies a visitor and associates them with a subscriber ID. This is useful for when a visitor logs in or signs up.
// Identifies the visitor with the subscriber ID 'sub_1234abcd'
RM.push(['identify', 'sub_1234abcd']);
prepopulate
This command pre-populates any forms on the page with the visitor's information.
RM.push(['prepopulate']);
clearAnswers
This command clears all of the answers a visitor has given to your questions.
RM.push(['clearAnswers']);
addSegment
This command adds a visitor to a specific segment.
// Adds the visitor to the segment with the ID 'seg_1234abcd'
RM.push(['addSegment', 'seg_1234abcd']);
removeSegment
This command removes a visitor from a specific segment.
// Removes the visitor from the segment with the ID 'seg_1234abcd'
RM.push(['removeSegment', 'seg_1234abcd']);
JavaScript events
We trigger events on the document when various things happen. You can listen to these events to trigger whatever functionality you need. Current events:
Visitor answers a question in a RightMessage widget
// rm:widget:answer
//
// Properties:
// - widgetId e.g. "wdg_1234abcd"
// - widgetName e.g. "Blog sticky bar"
// - dimensionId e.g. "dim_1234abcd"
// - dimensionName e.g. "Job role"
// - questionText e.g. "You said you work for a retail firm - what's your role there?"
// - segmentId e.g. "seg_1234abcd"
// - segmentName e.g. "Sales director"
//
// Example implementation:
document.addEventListener("rm:widget:answer", function(event) {
console.log("Visitor's " + event.detail.dimensionName + " is " + event.detail.segmentName);
});
Visitor accepts an offer in a RightMessage widget
// rm:widget:acceptOffer
//
// Properties:
// - widgetId e.g. "wdg_1234abcd"
// - widgetName e.g. "Blog sticky bar"
// - offerId e.g. "ofr_1234abcd"
// - offerName e.g. "Newsletter opt-in"
// - emailAddress e.g. "[email protected]"
//
// Example implementation:
document.addEventListener("rm:widget:acceptOffer", function(event) {
console.log(event.detail.emailAddress + " just opted in for " + event.detail.offerName);
});