This article explains how to send server-side Track Events from Salesforce to Pendo using the TrackEvent Apex class in the Pendo Toolkit. These events help you monitor user behavior, measure adoption, and track actions that aren't captured automatically by the Pendo Web SDK.
This feature is available for Salesforce admins and developers and supports sending events from:
- Apex (synchronous or asynchronous)
- Lightning Web Components (LWC)
- Aura Components
- Salesforce Flows (through Apex Action)
- Batch Jobs or Triggers
If you're tracking events from a web or mobile app, use the Track Events API.
Prerequisites
To use this feature, make sure:
- The Pendo Toolkit for Salesforce is installed and configured. For instructions, see Set up the Pendo Toolkit for Salesforce.
- You have the Pendo Toolkit Administrator permission set assigned in Salesforce.
- You have Salesforce permissions: Customize Application and the ability to edit and activate Flows, Apex, or LWCs.
- You have access to the Track Event shared secret (API key) from your Pendo subscription.
Step 1: Configure the Pendo Track Event API in Salesforce
- In Pendo, go to Settings > Subscription Settings
- Select the Applications tab, then choose your app.
- Next to Track Event shared secret, select Show, and copy the key.
- In Salesforce, open the App Launcher and search for the Pendo app.
- In the Pendo app, open the Pendo Track Event Configuration tab.
- Paste your API key, select your Environment (
io,eu,us1, orjpn), then select Save.
Step 2: Send events using Flow, Apex, or components
After configuration is complete, you can send events with any of the following methods in Salesforce.
We recommend the following best practices for all methods:
- Don’t include personally identifiable information (PII) in event data.
- Ensure the event data you send complies with your data security policies.
- Test your setup in a sandbox before sending production events.
Option 1: Use Salesforce Flow
- Open Flow Builder.
- Add an Action element and search for
trackEvent. - Select the Apex Action from TrackEvent.
- Provide values for the input parameters:
-
event (string). Name of the user action (for example,
LoggedIn). - visitorId (string). Unique ID associated with the user.
- accountId (string, optional). Account associated with the user.
- properties (collection, optional). Custom key-value data.
-
context (collection, optional). Session data like
ip,userAgent, orurl.
-
event (string). Name of the user action (for example,
Tip: Use the Pendo Track Event Sample Flow as a starting point. Clone and customize it to match your use case.
Option 2: Send Track Events in Apex
Use the TrackEvent class in synchronous or asynchronous Apex, triggers, or batch jobs:
TrackEvent.EventData event = new TrackEvent.EventData();
event.event = 'Registered';
event.visitorId = 'user-123';
event.accountId = 'acc-001';
event.properties = new Map<String, Object>{
'plan' => 'Pro',
'device' => 'Mobile'
};
event.context = new Map<String, Object>{
'ip' => '76.253.187.23',
'userAgent' => 'Mozilla/5.0'
};
TrackEvent.send(new List<TrackEvent.EventData>{ event });Option 3: Call the API from LWC or Aura
Call the TrackEvent.send() method using JSON serialization in a Lightning Web Component:
import send from '@salesforce/apex/TrackEvent.send';
const eventPayload = JSON.stringify({
event: 'ClickedButton',
visitorId: 'user-123',
accountId: 'acc-001',
properties: { page: 'HomePage' },
context: { ip: '192.168.1.1' }
});
send({ eventDataJson: eventPayload })
.then(result => console.log('Success'))
.catch(error => console.error('Error sending event:', error));