Integrations
The Salesforce Interactions SDK provides a set of built-in CustomEvents that act as integration hooks. These hooks allow developers to bind custom JavaScript listeners to specific internal lifecycle and data events within the Web SDK.
The data passed by these custom events is found within the detail property of the standard JavaScript event object passed to your listener's callback function.
Here's a full list of CustomEvents within the SDK.
Here's a breakdown of the built-in custom events available for integration.
The OnBeforeEventSend event is dispatched by the SDK immediately before an event payload passed via SalesforceInteractions.sendEvent is processed by consuming modules.
OnEventSend is dispatched after an event has been successfully processed, and a request is made to the Event API (or consuming modules). This event contains the actionEvent payload processed in the event pipeline.
OnInIt is dispatched when the Web SDK is successfully initialized. You can use this event for debugging Single-Page Applications (SPAs) where the SDK usually reinitializes without a page load event.
The OnInitSitemap event is dispatched whenever the Web SDK Sitemap is initialized via the SalesforceInteractions.initSitemap() function. This event provides confirmation that the Sitemap configuration has loaded, and contains this detail.
OnPageMatchStatusUpdated is dispatched whenever the sitemap evaluates and updates the match status of any page type defined in your sitemap configuration. Use this custom event to debug the sitemap's logic, as it shows the chronological sequence and outcome of the matching process of all page types.
The data provided in this event's detail is a matchStatus array that accumulates the status of every page type checked so far.
The PageMatchStatus object has this structure.
A page type with a status of running includes the startTime of the evaluation. Conversely, when a page type evaluation concludes with a status of matched, rejected, or selected, the output includes the endTime.
Critically, the very first page type to successfully match the current URL is given the status selected. After a page type is selected, the sitemap stops evaluating any other remaining page types.
This event is dispatched when a critical operation within the SDK fails, providing error information and context. Use this custom event for error logging and monitoring runtime errors.
The Error object has this structure.
OnSetAnonymousId is dispatched every time the Web SDK assigns a new tracking identity (anonymousId) to the customer's device or browser, and contains this detail.
OnResetAnonymousId is dispatched when SalesforceInteractions.resetAnonymousId() is explicitly called by your code. Use this custom event to confirm the SDK has executed the command to generate a new anonymous ID.
OnClearPersistedIdentities is dispatched when SalesforceInteractions.clearPersistedIdentities() is explicitly called by your code. This event confirms that known user identities (such as, loyaltyId or email used for matching) have been cleared from the SDK's internal storage.
This custom event is dispatched when a user had previously granted consent, but their consent status is later updated from Opt In to Opt Out. You can use this custom event to trigger custom logic on your site when tracking is explicitly disabled after having been active.
The OnConsentRevoke custom event contains this detail.
OnShutDown is dispatched when the Web SDK receives the signal to shut down its operations (for example, due to an Opt Out status update or explicit command).
You use the standard browser document.addEventListener() method to attach a function to the event's string name (prefixed with salesforce:), as shown in this example.